Start work on tagging unit test

Co-Authored-By: Patrick Thomson <patrickt@users.noreply.github.com>
This commit is contained in:
Max Brunsfeld 2020-03-05 13:04:49 -08:00
parent 38a9f33d9e
commit a3f0087b11
3 changed files with 81 additions and 8 deletions

View file

@ -4,5 +4,6 @@ mod highlight_test;
mod node_test;
mod parser_test;
mod query_test;
mod tags_test;
mod test_highlight_test;
mod tree_test;

View file

@ -0,0 +1,56 @@
use super::helpers::fixtures::get_language;
use tree_sitter_tags::{TagKind, TagsConfiguration, TagsContext};
#[test]
fn test_tags_javascript() {
let language = get_language("python");
let tags_config = TagsConfiguration::new(
language,
r#"
((function_definition
name: (identifier) @name
body: (block
. (string) @doc)) @function
(set! replace @doc "(^['\s]*)|(['\s]*$)"))
(function_definition
name: (identifier) @name) @function
(class_definition
name: (identifier) @name) @class
(call
function: (identifier) @name) @call
"#,
"",
)
.unwrap();
let mut tag_context = TagsContext::new();
let tags = tag_context.generate_tags(
&tags_config,
br#"
class Customer:
"""
Data about a customer
"""
def age(self):
"""
Get the customer's age
"""
compute_age(self.id);
}
"#,
);
assert_eq!(
tags.iter().map(|t| (t.name, t.kind)).collect::<Vec<_>>(),
&[
("Customer", TagKind::Class),
("age", TagKind::Function),
("compute_age", TagKind::Call),
]
);
assert_eq!(tags[0].docs, Some("Data about a customer"));
assert_eq!(tags[1].docs, Some("Get the customer's age"));
}