Remove document parameter from ts_node_type, ts_node_string
Co-Authored-By: Rick Winfrey <rewinfrey@github.com>
This commit is contained in:
parent
8d805feab1
commit
92255bbfdd
10 changed files with 87 additions and 88 deletions
|
|
@ -75,8 +75,8 @@ TSPoint ts_node_start_point(TSNode);
|
|||
uint32_t ts_node_end_byte(TSNode);
|
||||
TSPoint ts_node_end_point(TSNode);
|
||||
TSSymbol ts_node_symbol(TSNode);
|
||||
const char *ts_node_type(TSNode, const TSDocument *);
|
||||
char *ts_node_string(TSNode, const TSDocument *);
|
||||
const char *ts_node_type(TSNode);
|
||||
char *ts_node_string(TSNode);
|
||||
bool ts_node_eq(TSNode, TSNode);
|
||||
bool ts_node_is_named(TSNode);
|
||||
bool ts_node_is_missing(TSNode);
|
||||
|
|
|
|||
|
|
@ -342,12 +342,12 @@ TSSymbol ts_node_symbol(TSNode self) {
|
|||
return self.alias_symbol ? self.alias_symbol : tree->symbol;
|
||||
}
|
||||
|
||||
const char *ts_node_type(TSNode self, const TSDocument *document) {
|
||||
return ts_language_symbol_name(document->parser.language, ts_node_symbol(self));
|
||||
const char *ts_node_type(TSNode self) {
|
||||
return ts_language_symbol_name(self.document->parser.language, ts_node_symbol(self));
|
||||
}
|
||||
|
||||
char *ts_node_string(TSNode self, const TSDocument *document) {
|
||||
return ts_tree_string(ts_node__tree(self), document->parser.language, false);
|
||||
char *ts_node_string(TSNode self) {
|
||||
return ts_tree_string(ts_node__tree(self), self.document->parser.language, false);
|
||||
}
|
||||
|
||||
bool ts_node_eq(TSNode self, TSNode other) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ static void append_to_scope_sequence(ScopeSequence *sequence,
|
|||
sequence, current_scopes, text, ts_node_start_byte(node) - sequence->size()
|
||||
);
|
||||
|
||||
current_scopes->push_back(ts_node_type(node, document));
|
||||
current_scopes->push_back(ts_node_type(node));
|
||||
|
||||
for (size_t i = 0, n = ts_node_child_count(node); i < n; i++) {
|
||||
TSNode child = ts_node_child(node, i);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ ostream &operator<<(std::ostream &stream, const Tree *tree) {
|
|||
|
||||
ostream &operator<<(ostream &stream, const TSNode &node) {
|
||||
if (node.subtree) {
|
||||
char *string = ts_node_string(node, node.document);
|
||||
char *string = ts_node_string(node);
|
||||
stream << "{" << string << ", " << to_string(ts_node_start_byte(node)) << "}";
|
||||
ts_free(string);
|
||||
return stream;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ for (auto &language_name : test_languages) {
|
|||
edit_sequence();
|
||||
|
||||
TSNode root_node = ts_document_root_node(document);
|
||||
const char *node_string = ts_node_string(root_node, document);
|
||||
const char *node_string = ts_node_string(root_node);
|
||||
string result(node_string);
|
||||
ts_free((void *)node_string);
|
||||
AssertThat(result, Equals(entry.tree_string));
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ for (auto &language_name : test_languages) {
|
|||
TSNode root_node = ts_document_root_node(document);
|
||||
AssertThat(ts_node_end_byte(root_node), Equals(entry.input.size()));
|
||||
assert_consistent_tree_sizes(root_node);
|
||||
const char *node_string = ts_node_string(root_node, document);
|
||||
const char *node_string = ts_node_string(root_node);
|
||||
string result(node_string);
|
||||
ts_free((void *)node_string);
|
||||
ts_document_free(document);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ describe("Document", [&]() {
|
|||
});
|
||||
|
||||
auto assert_node_string_equals = [&](TSNode node, const string &expected) {
|
||||
char *str = ts_node_string(node, document);
|
||||
char *str = ts_node_string(node);
|
||||
string actual(str);
|
||||
ts_free(str);
|
||||
AssertThat(actual, Equals(expected));
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ describe("Language", []() {
|
|||
ts_document_parse(document);
|
||||
|
||||
TSNode root_node = ts_document_root_node(document);
|
||||
char *string = ts_node_string(root_node, document);
|
||||
char *string = ts_node_string(root_node);
|
||||
AssertThat(string, Equals("(a (c))"));
|
||||
|
||||
TSNode aliased_node = ts_node_child(root_node, 0);
|
||||
AssertThat(ts_node_type(aliased_node, document), Equals("c"));
|
||||
AssertThat(ts_node_type(aliased_node), Equals("c"));
|
||||
|
||||
TSSymbol aliased_symbol = ts_node_symbol(aliased_node);
|
||||
AssertThat(ts_language_symbol_count(language), IsGreaterThan(aliased_symbol));
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ describe("Node", [&]() {
|
|||
document = ts_document_new();
|
||||
ts_document_set_language(document, load_real_language("json"));
|
||||
ts_document_set_input_string(document, json_string.c_str());
|
||||
// ts_document_print_debugging_graphs(document, true);
|
||||
ts_document_parse(document);
|
||||
root_node = ts_node_child(ts_document_root_node(document), 0);
|
||||
});
|
||||
|
|
@ -84,7 +83,7 @@ describe("Node", [&]() {
|
|||
});
|
||||
|
||||
it("parses the example as expected (precondition)", [&]() {
|
||||
char *node_string = ts_node_string(root_node, document);
|
||||
char *node_string = ts_node_string(root_node);
|
||||
AssertThat(node_string, Equals(
|
||||
"(array "
|
||||
"(number) "
|
||||
|
|
@ -95,7 +94,7 @@ describe("Node", [&]() {
|
|||
|
||||
describe("named_child_count(), named_child(i)", [&]() {
|
||||
it("returns the named child node at the given index", [&]() {
|
||||
AssertThat(ts_node_type(root_node, document), Equals("array"));
|
||||
AssertThat(ts_node_type(root_node), Equals("array"));
|
||||
|
||||
AssertThat(ts_node_named_child_count(root_node), Equals<size_t>(3));
|
||||
AssertThat(ts_node_start_byte(root_node), Equals(array_index));
|
||||
|
|
@ -107,9 +106,9 @@ describe("Node", [&]() {
|
|||
TSNode false_node = ts_node_named_child(root_node, 1);
|
||||
TSNode object_node = ts_node_named_child(root_node, 2);
|
||||
|
||||
AssertThat(ts_node_type(number_node, document), Equals("number"));
|
||||
AssertThat(ts_node_type(false_node, document), Equals("false"));
|
||||
AssertThat(ts_node_type(object_node, document), Equals("object"));
|
||||
AssertThat(ts_node_type(number_node), Equals("number"));
|
||||
AssertThat(ts_node_type(false_node), Equals("false"));
|
||||
AssertThat(ts_node_type(object_node), Equals("object"));
|
||||
|
||||
AssertThat(ts_node_start_byte(number_node), Equals(number_index));
|
||||
AssertThat(ts_node_end_byte(number_node), Equals(number_end_index));
|
||||
|
|
@ -129,7 +128,7 @@ describe("Node", [&]() {
|
|||
|
||||
TSNode pair_node = ts_node_named_child(object_node, 0);
|
||||
|
||||
AssertThat(ts_node_type(pair_node, document), Equals("pair"));
|
||||
AssertThat(ts_node_type(pair_node), Equals("pair"));
|
||||
AssertThat(ts_node_start_byte(pair_node), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(pair_node), Equals(null_end_index));
|
||||
AssertThat(ts_node_start_point(pair_node), Equals<TSPoint>({ 6, 4 }));
|
||||
|
|
@ -139,8 +138,8 @@ describe("Node", [&]() {
|
|||
TSNode string_node = ts_node_named_child(pair_node, 0);
|
||||
TSNode null_node = ts_node_named_child(pair_node, 1);
|
||||
|
||||
AssertThat(ts_node_type(string_node, document), Equals("string"));
|
||||
AssertThat(ts_node_type(null_node, document), Equals("null"));
|
||||
AssertThat(ts_node_type(string_node), Equals("string"));
|
||||
AssertThat(ts_node_type(null_node), Equals("null"));
|
||||
|
||||
AssertThat(ts_node_start_byte(string_node), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(string_node), Equals(string_end_index));
|
||||
|
|
@ -169,16 +168,16 @@ describe("Node", [&]() {
|
|||
ts_document_parse(document);
|
||||
root_node = ts_document_root_node(document);
|
||||
|
||||
char *node_string = ts_node_string(root_node, document);
|
||||
char *node_string = ts_node_string(root_node);
|
||||
AssertThat(node_string, Equals("(a (b) (comment) (B) (comment) (b))"));
|
||||
ts_free(node_string);
|
||||
|
||||
AssertThat(ts_node_named_child_count(root_node), Equals(5u));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 0), document), Equals("b"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 1), document), Equals("comment"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 2), document), Equals("B"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 3), document), Equals("comment"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 4), document), Equals("b"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 0)), Equals("b"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 1)), Equals("comment"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 2)), Equals("B"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 3)), Equals("comment"));
|
||||
AssertThat(ts_node_type(ts_node_named_child(root_node, 4)), Equals("b"));
|
||||
|
||||
AssertThat(ts_node_symbol(ts_node_named_child(root_node, 0)), !Equals(ts_node_symbol(ts_node_named_child(root_node, 2))));
|
||||
});
|
||||
|
|
@ -189,29 +188,29 @@ describe("Node", [&]() {
|
|||
TSNode child;
|
||||
|
||||
child = ts_node_first_child_for_byte(root_node, array_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("["));
|
||||
AssertThat(ts_node_type(child), Equals("["));
|
||||
child = ts_node_first_child_for_byte(root_node, number_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("number"));
|
||||
AssertThat(ts_node_type(child), Equals("number"));
|
||||
child = ts_node_first_child_for_byte(root_node, number_end_index);
|
||||
AssertThat(ts_node_type(child, document), Equals(","));
|
||||
AssertThat(ts_node_type(child), Equals(","));
|
||||
child = ts_node_first_child_for_byte(root_node, number_end_index + 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_child_for_byte(root_node, false_index - 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_child_for_byte(root_node, false_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_child_for_byte(root_node, false_index + 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_child_for_byte(root_node, false_end_index);
|
||||
AssertThat(ts_node_type(child, document), Equals(","));
|
||||
AssertThat(ts_node_type(child), Equals(","));
|
||||
child = ts_node_first_child_for_byte(root_node, false_end_index);
|
||||
AssertThat(ts_node_type(child, document), Equals(","));
|
||||
AssertThat(ts_node_type(child), Equals(","));
|
||||
child = ts_node_first_child_for_byte(root_node, object_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("object"));
|
||||
AssertThat(ts_node_type(child), Equals("object"));
|
||||
child = ts_node_first_child_for_byte(root_node, object_index + 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("object"));
|
||||
AssertThat(ts_node_type(child), Equals("object"));
|
||||
child = ts_node_first_child_for_byte(root_node, object_end_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("]"));
|
||||
AssertThat(ts_node_type(child), Equals("]"));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -220,25 +219,25 @@ describe("Node", [&]() {
|
|||
TSNode child;
|
||||
|
||||
child = ts_node_first_named_child_for_byte(root_node, array_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("number"));
|
||||
AssertThat(ts_node_type(child), Equals("number"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, number_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("number"));
|
||||
AssertThat(ts_node_type(child), Equals("number"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, number_end_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, number_end_index + 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, false_index - 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, false_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, false_index + 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child), Equals("false"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, false_end_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("object"));
|
||||
AssertThat(ts_node_type(child), Equals("object"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, object_index);
|
||||
AssertThat(ts_node_type(child, document), Equals("object"));
|
||||
AssertThat(ts_node_type(child), Equals("object"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, object_index + 1);
|
||||
AssertThat(ts_node_type(child, document), Equals("object"));
|
||||
AssertThat(ts_node_type(child), Equals("object"));
|
||||
child = ts_node_first_named_child_for_byte(root_node, object_end_index);
|
||||
AssertThat(child.subtree, Equals<void *>(nullptr));
|
||||
});
|
||||
|
|
@ -255,14 +254,14 @@ describe("Node", [&]() {
|
|||
TSNode child6 = ts_node_child(root_node, 5);
|
||||
TSNode child7 = ts_node_child(root_node, 6);
|
||||
|
||||
AssertThat(ts_node_type(root_node, document), Equals("array"));
|
||||
AssertThat(ts_node_type(child1, document), Equals("["));
|
||||
AssertThat(ts_node_type(child2, document), Equals("number"));
|
||||
AssertThat(ts_node_type(child3, document), Equals(","));
|
||||
AssertThat(ts_node_type(child4, document), Equals("false"));
|
||||
AssertThat(ts_node_type(child5, document), Equals(","));
|
||||
AssertThat(ts_node_type(child6, document), Equals("object"));
|
||||
AssertThat(ts_node_type(child7, document), Equals("]"));
|
||||
AssertThat(ts_node_type(root_node), Equals("array"));
|
||||
AssertThat(ts_node_type(child1), Equals("["));
|
||||
AssertThat(ts_node_type(child2), Equals("number"));
|
||||
AssertThat(ts_node_type(child3), Equals(","));
|
||||
AssertThat(ts_node_type(child4), Equals("false"));
|
||||
AssertThat(ts_node_type(child5), Equals(","));
|
||||
AssertThat(ts_node_type(child6), Equals("object"));
|
||||
AssertThat(ts_node_type(child7), Equals("]"));
|
||||
|
||||
AssertThat(ts_node_is_named(root_node), IsTrue());
|
||||
AssertThat(ts_node_is_named(child1), IsFalse());
|
||||
|
|
@ -303,13 +302,13 @@ describe("Node", [&]() {
|
|||
TSNode grandchild3 = ts_node_child(pair, 1);
|
||||
TSNode grandchild4 = ts_node_child(pair, 2);
|
||||
|
||||
AssertThat(ts_node_type(left_brace, document), Equals("{"));
|
||||
AssertThat(ts_node_type(pair, document), Equals("pair"));
|
||||
AssertThat(ts_node_type(right_brace, document), Equals("}"));
|
||||
AssertThat(ts_node_type(left_brace), Equals("{"));
|
||||
AssertThat(ts_node_type(pair), Equals("pair"));
|
||||
AssertThat(ts_node_type(right_brace), Equals("}"));
|
||||
|
||||
AssertThat(ts_node_type(grandchild2, document), Equals("string"));
|
||||
AssertThat(ts_node_type(grandchild3, document), Equals(":"));
|
||||
AssertThat(ts_node_type(grandchild4, document), Equals("null"));
|
||||
AssertThat(ts_node_type(grandchild2), Equals("string"));
|
||||
AssertThat(ts_node_type(grandchild3), Equals(":"));
|
||||
AssertThat(ts_node_type(grandchild4), Equals("null"));
|
||||
|
||||
AssertThat(ts_node_parent(grandchild2), Equals(pair));
|
||||
AssertThat(ts_node_parent(grandchild3), Equals(pair));
|
||||
|
|
@ -411,14 +410,14 @@ describe("Node", [&]() {
|
|||
describe("when there is a leaf node that spans the given range exactly", [&]() {
|
||||
it("returns that leaf node", [&]() {
|
||||
TSNode leaf = ts_node_named_descendant_for_byte_range(root_node, string_index, string_end_index - 1);
|
||||
AssertThat(ts_node_type(leaf, document), Equals("string"));
|
||||
AssertThat(ts_node_type(leaf), Equals("string"));
|
||||
AssertThat(ts_node_start_byte(leaf), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(leaf), Equals(string_end_index));
|
||||
AssertThat(ts_node_start_point(leaf), Equals<TSPoint>({ 6, 4 }));
|
||||
AssertThat(ts_node_end_point(leaf), Equals<TSPoint>({ 6, 7 }));
|
||||
|
||||
leaf = ts_node_named_descendant_for_byte_range(root_node, number_index, number_end_index - 1);
|
||||
AssertThat(ts_node_type(leaf, document), Equals("number"));
|
||||
AssertThat(ts_node_type(leaf), Equals("number"));
|
||||
AssertThat(ts_node_start_byte(leaf), Equals(number_index));
|
||||
AssertThat(ts_node_end_byte(leaf), Equals(number_end_index));
|
||||
AssertThat(ts_node_start_point(leaf), Equals<TSPoint>({ 3, 2 }));
|
||||
|
|
@ -429,14 +428,14 @@ describe("Node", [&]() {
|
|||
describe("when there is a leaf node that extends beyond the given range", [&]() {
|
||||
it("returns that leaf node", [&]() {
|
||||
TSNode leaf = ts_node_named_descendant_for_byte_range(root_node, string_index, string_index + 1);
|
||||
AssertThat(ts_node_type(leaf, document), Equals("string"));
|
||||
AssertThat(ts_node_type(leaf), Equals("string"));
|
||||
AssertThat(ts_node_start_byte(leaf), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(leaf), Equals(string_end_index));
|
||||
AssertThat(ts_node_start_point(leaf), Equals<TSPoint>({ 6, 4 }));
|
||||
AssertThat(ts_node_end_point(leaf), Equals<TSPoint>({ 6, 7 }));
|
||||
|
||||
leaf = ts_node_named_descendant_for_byte_range(root_node, string_index + 1, string_index + 2);
|
||||
AssertThat(ts_node_type(leaf, document), Equals("string"));
|
||||
AssertThat(ts_node_type(leaf), Equals("string"));
|
||||
AssertThat(ts_node_start_byte(leaf), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(leaf), Equals(string_end_index));
|
||||
AssertThat(ts_node_start_point(leaf), Equals<TSPoint>({ 6, 4 }));
|
||||
|
|
@ -447,7 +446,7 @@ describe("Node", [&]() {
|
|||
describe("when there is no leaf node that spans the given range", [&]() {
|
||||
it("returns the smallest node that does span the range", [&]() {
|
||||
TSNode pair_node = ts_node_named_descendant_for_byte_range(root_node, string_index, string_index + 3);
|
||||
AssertThat(ts_node_type(pair_node, document), Equals("pair"));
|
||||
AssertThat(ts_node_type(pair_node), Equals("pair"));
|
||||
AssertThat(ts_node_start_byte(pair_node), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(pair_node), Equals(null_end_index));
|
||||
AssertThat(ts_node_start_point(pair_node), Equals<TSPoint>({ 6, 4 }));
|
||||
|
|
@ -456,7 +455,7 @@ describe("Node", [&]() {
|
|||
|
||||
it("does not return invisible nodes (repeats)", [&]() {
|
||||
TSNode node = ts_node_named_descendant_for_byte_range(root_node, number_end_index, number_end_index + 1);
|
||||
AssertThat(ts_node_type(node, document), Equals("array"));
|
||||
AssertThat(ts_node_type(node), Equals("array"));
|
||||
AssertThat(ts_node_start_byte(node), Equals(array_index));
|
||||
AssertThat(ts_node_end_byte(node), Equals(array_end_index));
|
||||
AssertThat(ts_node_start_point(node), Equals<TSPoint>({ 2, 0 }));
|
||||
|
|
@ -468,14 +467,14 @@ describe("Node", [&]() {
|
|||
describe("descendant_for_byte_range(start, end)", [&]() {
|
||||
it("returns the smallest node that spans the given byte offsets", [&]() {
|
||||
TSNode node1 = ts_node_descendant_for_byte_range(root_node, colon_index, colon_index);
|
||||
AssertThat(ts_node_type(node1, document), Equals(":"));
|
||||
AssertThat(ts_node_type(node1), Equals(":"));
|
||||
AssertThat(ts_node_start_byte(node1), Equals(colon_index));
|
||||
AssertThat(ts_node_end_byte(node1), Equals(colon_index + 1));
|
||||
AssertThat(ts_node_start_point(node1), Equals<TSPoint>({ 6, 7 }));
|
||||
AssertThat(ts_node_end_point(node1), Equals<TSPoint>({ 6, 8 }));
|
||||
|
||||
TSNode node2 = ts_node_descendant_for_byte_range(root_node, string_index + 2, string_index + 4);
|
||||
AssertThat(ts_node_type(node2, document), Equals("pair"));
|
||||
AssertThat(ts_node_type(node2), Equals("pair"));
|
||||
AssertThat(ts_node_start_byte(node2), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(node2), Equals(null_end_index));
|
||||
AssertThat(ts_node_start_point(node2), Equals<TSPoint>({ 6, 4 }));
|
||||
|
|
@ -490,10 +489,10 @@ describe("Node", [&]() {
|
|||
|
||||
uint32_t comma_position = input_string.find(",");
|
||||
TSNode node1 = ts_node_descendant_for_byte_range(root_node, comma_position, comma_position);
|
||||
AssertThat(ts_node_type(node1, document), Equals(","));
|
||||
AssertThat(ts_node_type(node1), Equals(","));
|
||||
|
||||
TSNode node2 = ts_node_descendant_for_byte_range(root_node, 6, 10);
|
||||
AssertThat(ts_node_type(node2, document), Equals("string"));
|
||||
AssertThat(ts_node_type(node2), Equals("string"));
|
||||
AssertThat(ts_node_start_byte(node2), Equals<size_t>(1));
|
||||
AssertThat(ts_node_end_byte(node2), Equals<size_t>(11));
|
||||
});
|
||||
|
|
@ -502,14 +501,14 @@ describe("Node", [&]() {
|
|||
describe("descendant_for_point_range(start, end)", [&]() {
|
||||
it("returns the smallest concrete node that spans the given range", [&]() {
|
||||
TSNode node1 = ts_node_descendant_for_point_range(root_node, {6, 7}, {6, 7});
|
||||
AssertThat(ts_node_type(node1, document), Equals(":"));
|
||||
AssertThat(ts_node_type(node1), Equals(":"));
|
||||
AssertThat(ts_node_start_byte(node1), Equals(colon_index));
|
||||
AssertThat(ts_node_end_byte(node1), Equals(colon_index + 1));
|
||||
AssertThat(ts_node_start_point(node1), Equals<TSPoint>({ 6, 7 }));
|
||||
AssertThat(ts_node_end_point(node1), Equals<TSPoint>({ 6, 8 }));
|
||||
|
||||
TSNode node2 = ts_node_descendant_for_point_range(root_node, {6, 6}, {6, 8});
|
||||
AssertThat(ts_node_type(node2, document), Equals("pair"));
|
||||
AssertThat(ts_node_type(node2), Equals("pair"));
|
||||
AssertThat(ts_node_start_byte(node2), Equals(string_index));
|
||||
AssertThat(ts_node_end_byte(node2), Equals(null_end_index));
|
||||
AssertThat(ts_node_start_point(node2), Equals<TSPoint>({ 6, 4 }));
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ describe("Parser", [&]() {
|
|||
|
||||
auto assert_root_node = [&](const string &expected) {
|
||||
TSNode node = ts_document_root_node(document);
|
||||
char *node_string = ts_node_string(node, document);
|
||||
char *node_string = ts_node_string(node);
|
||||
string actual(node_string);
|
||||
ts_free(node_string);
|
||||
AssertThat(actual, Equals(expected));
|
||||
|
|
@ -93,7 +93,7 @@ describe("Parser", [&]() {
|
|||
"(value (array (number) (ERROR (UNEXPECTED '@')) (true)))");
|
||||
|
||||
TSNode error = ts_node_named_child(ts_node_child(root, 0), 1);
|
||||
AssertThat(ts_node_type(error, document), Equals("ERROR"));
|
||||
AssertThat(ts_node_type(error), Equals("ERROR"));
|
||||
AssertThat(get_node_text(error), Equals("@@@@@,"));
|
||||
AssertThat(ts_node_child_count(error), Equals<size_t>(2));
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ describe("Parser", [&]() {
|
|||
AssertThat(get_node_text(comma), Equals(","));
|
||||
|
||||
TSNode node_after_error = ts_node_next_named_sibling(error);
|
||||
AssertThat(ts_node_type(node_after_error, document), Equals("true"));
|
||||
AssertThat(ts_node_type(node_after_error), Equals("true"));
|
||||
AssertThat(get_node_text(node_after_error), Equals("true"));
|
||||
});
|
||||
});
|
||||
|
|
@ -118,20 +118,20 @@ describe("Parser", [&]() {
|
|||
"(value (array (number) (ERROR (UNEXPECTED 'a')) (true)))");
|
||||
|
||||
TSNode error = ts_node_named_child(ts_node_child(root, 0), 1);
|
||||
AssertThat(ts_node_type(error, document), Equals("ERROR"));
|
||||
AssertThat(ts_node_type(error), Equals("ERROR"));
|
||||
AssertThat(get_node_text(error), Equals("faaaaalse,"));
|
||||
AssertThat(ts_node_child_count(error), Equals<size_t>(2));
|
||||
|
||||
TSNode garbage = ts_node_child(error, 0);
|
||||
AssertThat(ts_node_type(garbage, document), Equals("ERROR"));
|
||||
AssertThat(ts_node_type(garbage), Equals("ERROR"));
|
||||
AssertThat(get_node_text(garbage), Equals("faaaaalse"));
|
||||
|
||||
TSNode comma = ts_node_child(error, 1);
|
||||
AssertThat(ts_node_type(comma, document), Equals(","));
|
||||
AssertThat(ts_node_type(comma), Equals(","));
|
||||
AssertThat(get_node_text(comma), Equals(","));
|
||||
|
||||
TSNode last = ts_node_next_named_sibling(error);
|
||||
AssertThat(ts_node_type(last, document), Equals("true"));
|
||||
AssertThat(ts_node_type(last), Equals("true"));
|
||||
AssertThat(ts_node_start_byte(last), Equals(strlen(" [123, faaaaalse, ")));
|
||||
});
|
||||
});
|
||||
|
|
@ -145,12 +145,12 @@ describe("Parser", [&]() {
|
|||
"(value (array (number) (true) (ERROR (false)) (true)))");
|
||||
|
||||
TSNode error = ts_node_named_child(ts_node_child(root, 0), 2);
|
||||
AssertThat(ts_node_type(error, document), Equals("ERROR"));
|
||||
AssertThat(ts_node_type(error), Equals("ERROR"));
|
||||
AssertThat(get_node_text(error), Equals("false"));
|
||||
AssertThat(ts_node_child_count(error), Equals<size_t>(1));
|
||||
|
||||
TSNode last = ts_node_next_named_sibling(error);
|
||||
AssertThat(ts_node_type(last, document), Equals("true"));
|
||||
AssertThat(ts_node_type(last), Equals("true"));
|
||||
AssertThat(get_node_text(last), Equals("true"));
|
||||
});
|
||||
});
|
||||
|
|
@ -186,7 +186,7 @@ describe("Parser", [&]() {
|
|||
);
|
||||
|
||||
TSNode error = ts_node_named_child(root, 1);
|
||||
AssertThat(ts_node_type(error, document), Equals("ERROR"));
|
||||
AssertThat(ts_node_type(error), Equals("ERROR"));
|
||||
AssertThat(ts_node_start_point(error), Equals<TSPoint>({2, 0}));
|
||||
AssertThat(ts_node_end_point(error), Equals<TSPoint>({2, 2}));
|
||||
});
|
||||
|
|
@ -303,7 +303,7 @@ describe("Parser", [&]() {
|
|||
"(program (expression_statement (binary_expression (identifier) (number))))");
|
||||
|
||||
TSNode node = ts_node_named_descendant_for_byte_range(root, 1, 1);
|
||||
AssertThat(ts_node_type(node, document), Equals("identifier"));
|
||||
AssertThat(ts_node_type(node), Equals("identifier"));
|
||||
AssertThat(ts_node_end_byte(node), Equals(strlen("abXYZc")));
|
||||
});
|
||||
});
|
||||
|
|
@ -322,7 +322,7 @@ describe("Parser", [&]() {
|
|||
"(program (expression_statement (binary_expression (identifier) (number))))");
|
||||
|
||||
TSNode node = ts_node_named_descendant_for_byte_range(root, 1, 1);
|
||||
AssertThat(ts_node_type(node, document), Equals("identifier"));
|
||||
AssertThat(ts_node_type(node), Equals("identifier"));
|
||||
AssertThat(ts_node_end_byte(node), Equals(strlen("abcXYZ")));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue