Fix handling of extra tokens in ts_tree_cursor_current_field_id
This commit is contained in:
parent
7ad087ce27
commit
30e73505e1
2 changed files with 39 additions and 1 deletions
|
|
@ -190,7 +190,7 @@ fn test_tree_edit() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_tree_walk() {
|
||||
fn test_tree_cursor() {
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(get_language("rust")).unwrap();
|
||||
|
||||
|
|
@ -225,6 +225,43 @@ fn test_tree_walk() {
|
|||
assert_eq!(cursor.node().is_named(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tree_cursor_fields() {
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(get_language("javascript")).unwrap();
|
||||
|
||||
let tree = parser
|
||||
.parse("function /*1*/ bar /*2*/ () {}", None)
|
||||
.unwrap();
|
||||
|
||||
let mut cursor = tree.walk();
|
||||
assert_eq!(cursor.node().kind(), "program");
|
||||
|
||||
cursor.goto_first_child();
|
||||
assert_eq!(cursor.node().kind(), "function_declaration");
|
||||
assert_eq!(cursor.field_name(), None);
|
||||
|
||||
cursor.goto_first_child();
|
||||
assert_eq!(cursor.node().kind(), "function");
|
||||
assert_eq!(cursor.field_name(), None);
|
||||
|
||||
cursor.goto_next_sibling();
|
||||
assert_eq!(cursor.node().kind(), "comment");
|
||||
assert_eq!(cursor.field_name(), None);
|
||||
|
||||
cursor.goto_next_sibling();
|
||||
assert_eq!(cursor.node().kind(), "identifier");
|
||||
assert_eq!(cursor.field_name(), Some("name"));
|
||||
|
||||
cursor.goto_next_sibling();
|
||||
assert_eq!(cursor.node().kind(), "comment");
|
||||
assert_eq!(cursor.field_name(), None);
|
||||
|
||||
cursor.goto_next_sibling();
|
||||
assert_eq!(cursor.node().kind(), "formal_parameters");
|
||||
assert_eq!(cursor.field_name(), Some("parameters"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tree_node_equality() {
|
||||
let mut parser = Parser::new();
|
||||
|
|
|
|||
|
|
@ -273,6 +273,7 @@ TSFieldId ts_tree_cursor_current_field_id(const TSTreeCursor *_self) {
|
|||
|
||||
while (field_map < field_map_end) {
|
||||
if (
|
||||
!ts_subtree_extra(*entry->subtree) &&
|
||||
!field_map->inherited &&
|
||||
field_map->child_index == entry->structural_child_index
|
||||
) return field_map->field_id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue