Fix inconsistencies in nodes sizes after edits

This commit is contained in:
Max Brunsfeld 2016-09-19 13:35:08 -07:00
parent ae3b912ddc
commit 3014101104
6 changed files with 70 additions and 67 deletions

View file

@ -127,7 +127,6 @@ describe("Parser", [&]() {
TSNode error = ts_node_named_child(root, 1);
AssertThat(ts_node_symbol(error), Equals(ts_builtin_sym_error));
AssertThat(ts_node_type(error, doc), Equals("ERROR"));
AssertThat(get_node_text(error), Equals(", faaaaalse"));
AssertThat(ts_node_child_count(error), Equals<size_t>(2));
TSNode comma = ts_node_child(error, 0);
@ -162,6 +161,15 @@ describe("Parser", [&]() {
});
});
describe("when there is an unexpected string at the end of a token", [&]() {
it("computes the error's size and position correctly", [&]() {
set_text(" [123, \"hi\n, true]");
assert_root_node(
"(array (number) (ERROR (UNEXPECTED '\\n')) (true))");
});
});
describe("when there is an unterminated error", [&]() {
it("maintains a consistent tree", [&]() {
ts_document_set_language(doc, get_test_language("javascript"));
@ -244,7 +252,7 @@ describe("Parser", [&]() {
"(identifier) "
"(math_op (number) (member_access (identifier) (identifier))))))");
AssertThat(input->strings_read, Equals(vector<string>({ " + abc.d)", "" })));
AssertThat(input->strings_read, Equals(vector<string>({ " + abc.d)" })));
});
});
@ -268,7 +276,7 @@ describe("Parser", [&]() {
"(number) "
"(math_op (number) (math_op (number) (identifier)))))))");
AssertThat(input->strings_read, Equals(vector<string>({ "123 || 5 +", "" })));
AssertThat(input->strings_read, Equals(vector<string>({ "123 || 5 +" })));
});
});
@ -517,7 +525,6 @@ describe("Parser", [&]() {
ts_document_free(doc);
doc = nullptr;
AssertThat(record_alloc::outstanding_allocation_indices(), IsEmpty());
}
record_alloc::stop();