Fix goto_previous_sibling with padded first children

This commit is contained in:
Daumantas Kavolis 2023-10-25 10:19:03 +03:00
parent 7c0cee70f5
commit e265929f90
No known key found for this signature in database
GPG key ID: 67197B110409498E
2 changed files with 35 additions and 1 deletions

View file

@ -376,6 +376,36 @@ fn test_tree_cursor() {
assert_eq!(copy.node().kind(), "struct_item");
}
#[test]
fn test_tree_cursor_previous_sibling() {
let mut parser = Parser::new();
parser.set_language(get_language("rust")).unwrap();
let text = "
// Hi there
// This is fun!
// Another one!
";
let tree = parser.parse(text, None).unwrap();
let mut cursor = tree.walk();
assert_eq!(cursor.node().kind(), "source_file");
assert!(cursor.goto_last_child());
assert_eq!(cursor.node().kind(), "line_comment");
assert_eq!(cursor.node().utf8_text(text.as_bytes()).unwrap(), "// Another one!");
assert!(cursor.goto_previous_sibling());
assert_eq!(cursor.node().kind(), "line_comment");
assert_eq!(cursor.node().utf8_text(text.as_bytes()).unwrap(), "// This is fun!");
assert!(cursor.goto_previous_sibling());
assert_eq!(cursor.node().kind(), "line_comment");
assert_eq!(cursor.node().utf8_text(text.as_bytes()).unwrap(), "// Hi there");
assert!(!cursor.goto_previous_sibling());
}
#[test]
fn test_tree_cursor_fields() {
let mut parser = Parser::new();