Fix missing auxiliary tokens in lex error state
This commit is contained in:
parent
926b4ef242
commit
c43ec90dad
5 changed files with 81 additions and 26 deletions
|
|
@ -5,44 +5,61 @@ extern ts_parse_config ts_parse_config_arithmetic;
|
|||
START_TEST
|
||||
|
||||
describe("arithmetic", []() {
|
||||
ts_document *document;
|
||||
ts_document *doc;
|
||||
|
||||
before_each([&]() {
|
||||
document = ts_document_make();
|
||||
ts_document_set_parser(document, ts_parse_config_arithmetic);
|
||||
doc = ts_document_make();
|
||||
ts_document_set_parser(doc, ts_parse_config_arithmetic);
|
||||
});
|
||||
|
||||
after_each([&]() {
|
||||
ts_document_free(doc);
|
||||
});
|
||||
|
||||
it("parses variables", [&]() {
|
||||
ts_document_set_text(document, "x");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
ts_document_set_text(doc, "x");
|
||||
AssertThat(string(ts_document_string(doc)), Equals(
|
||||
"(expression (term (factor (variable))))"));
|
||||
});
|
||||
|
||||
it("parses numbers", [&]() {
|
||||
ts_document_set_text(document, "5");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
ts_document_set_text(doc, "5");
|
||||
AssertThat(string(ts_document_string(doc)), Equals(
|
||||
"(expression (term (factor (number))))"));
|
||||
});
|
||||
|
||||
it("parses products of variables", [&]() {
|
||||
ts_document_set_text(document, "x + y");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
ts_document_set_text(doc, "x + y");
|
||||
AssertThat(string(ts_document_string(doc)), Equals(
|
||||
"(expression (term (factor (variable))) (plus) (term (factor (variable))))"));
|
||||
|
||||
ts_document_set_text(document, "x * y");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
ts_document_set_text(doc, "x * y");
|
||||
AssertThat(string(ts_document_string(doc)), Equals(
|
||||
"(expression (term (factor (variable)) (times) (factor (variable))))"));
|
||||
});
|
||||
|
||||
it("parses complex trees", [&]() {
|
||||
ts_document_set_text(document, "x * y + z * a");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
ts_document_set_text(doc, "x * y + z * a");
|
||||
AssertThat(string(ts_document_string(doc)), Equals(
|
||||
"(expression (term (factor (variable)) (times) (factor (variable))) (plus) (term (factor (variable)) (times) (factor (variable))))"));
|
||||
|
||||
ts_document_set_text(document, "x * (y + z)");
|
||||
AssertThat(string(ts_document_string(document)), Equals(
|
||||
ts_document_set_text(doc, "x * (y + z)");
|
||||
AssertThat(string(ts_document_string(doc)), Equals(
|
||||
"(expression (term (factor (variable)) (times) (factor (expression (term (factor (variable))) (plus) (term (factor (variable)))))))"));
|
||||
});
|
||||
|
||||
describe("error recovery", [&]() {
|
||||
it("recovers from errors at the top level", [&]() {
|
||||
ts_document_set_text(doc, "x * * y");
|
||||
AssertThat(string(ts_document_string(doc)), Equals("(ERROR)"));
|
||||
});
|
||||
|
||||
it("recovers from errors in parenthesized expressions", [&]() {
|
||||
ts_document_set_text(doc, "x + (y * + z) * 5");
|
||||
AssertThat(string(ts_document_string(doc)), Equals(
|
||||
"(expression (term (factor (variable))) (plus) (term (factor (ERROR)) (times) (factor (number))))"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
END_TEST
|
||||
Loading…
Add table
Add a link
Reference in a new issue