2017-06-30 21:55:50 -07:00
|
|
|
#include "test_helper.h"
|
|
|
|
|
#include "base64.c"
|
|
|
|
|
#include "helpers/load_language.h"
|
|
|
|
|
#include "helpers/tree_helpers.h"
|
|
|
|
|
#include "helpers/record_alloc.h"
|
|
|
|
|
|
|
|
|
|
START_TEST
|
|
|
|
|
|
|
|
|
|
vector<pair<string, string>> examples({
|
2017-09-14 11:39:08 -07:00
|
|
|
{
|
|
|
|
|
"javascript",
|
|
|
|
|
"Bi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLXGK0i0vLS0tLS0tLS0tLS0tLS0tLS0tLS0tLXGK0i0vLS0tLS0tLS0tLS0tLS0xLS0tLTYtLfpZAA=="
|
|
|
|
|
},
|
Add testcase for parser__advance assertion failure
The python testcase decodes to:
```
00000000 35 63 6f 6e 88 2c 29 33 2c 2c 2c 2c 63 6f 6e 88 |5con.,)3,,,,con.|
00000010 2c 2a 2c 3a 35 63 6f 6e 2c |,*,:5con,|
```
which triggers:
```
Assertion failed: ((uint32_t)0 < (&reduction.slices)->size), function parser__advance, file src/runtime/parser.c, line 1202.
```
2017-09-13 13:02:06 -04:00
|
|
|
{
|
|
|
|
|
"python",
|
|
|
|
|
"NWNvbogsKTMsLCwsY29uiCwqLDo1Y29uLA=="
|
|
|
|
|
},
|
2017-06-30 21:55:50 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("examples found via fuzzing", [&]() {
|
|
|
|
|
before_each([&]() {
|
|
|
|
|
record_alloc::start();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after_each([&]() {
|
|
|
|
|
AssertThat(record_alloc::outstanding_allocation_indices(), IsEmpty());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0, n = examples.size(); i < n; i++) {
|
|
|
|
|
|
|
|
|
|
it(("parses example number " + to_string(i)).c_str(), [&]() {
|
|
|
|
|
TSDocument *document = ts_document_new();
|
|
|
|
|
// ts_document_print_debugging_graphs(document, true);
|
|
|
|
|
|
|
|
|
|
const string &language_name = examples[i].first;
|
|
|
|
|
ts_document_set_language(document, load_real_language(language_name));
|
|
|
|
|
|
|
|
|
|
string input;
|
|
|
|
|
const string &base64_input = examples[i].second;
|
|
|
|
|
input.resize(base64_input.size());
|
|
|
|
|
input.resize(base64_decode(
|
|
|
|
|
reinterpret_cast<const unsigned char *>(base64_input.c_str()),
|
|
|
|
|
reinterpret_cast<unsigned char *>(&input[0]),
|
|
|
|
|
base64_input.size()
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
ts_document_set_input_string_with_length(
|
|
|
|
|
document,
|
|
|
|
|
input.c_str(),
|
|
|
|
|
input.size()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ts_document_parse(document);
|
|
|
|
|
|
|
|
|
|
TSNode node = ts_document_root_node(document);
|
|
|
|
|
assert_consistent_tree_sizes(node);
|
|
|
|
|
|
|
|
|
|
ts_document_free(document);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
END_TEST
|