add python test case for tag testing
This commit is contained in:
parent
dba7a13808
commit
e7f0cc4e24
2 changed files with 67 additions and 0 deletions
|
|
@ -7,4 +7,5 @@ mod pathological_test;
|
|||
mod query_test;
|
||||
mod tags_test;
|
||||
mod test_highlight_test;
|
||||
mod test_tags_test;
|
||||
mod tree_test;
|
||||
|
|
|
|||
66
cli/src/tests/test_tags_test.rs
Normal file
66
cli/src/tests/test_tags_test.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
use super::helpers::fixtures::{get_language, get_tags_config};
|
||||
use crate::query_testing::{parse_position_comments, Assertion};
|
||||
use crate::test_tags::get_tag_positions;
|
||||
use tree_sitter::{Parser, Point};
|
||||
use tree_sitter_tags::TagsContext;
|
||||
|
||||
#[test]
|
||||
fn test_tags_test_with_basic_test() {
|
||||
let language = get_language("python");
|
||||
let config = get_tags_config("python");
|
||||
let source = [
|
||||
"# hi",
|
||||
"def abc(d):",
|
||||
" # <- definition.function",
|
||||
" e = fgh(d)",
|
||||
" # ^ reference.call",
|
||||
" return d(e)",
|
||||
" # ^ reference.call",
|
||||
"",
|
||||
]
|
||||
.join("\n");
|
||||
|
||||
let assertions =
|
||||
parse_position_comments(&mut Parser::new(), language, source.as_bytes()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
assertions,
|
||||
&[
|
||||
Assertion {
|
||||
position: Point::new(1, 4),
|
||||
expected_capture_name: "definition.function".to_string(),
|
||||
},
|
||||
Assertion {
|
||||
position: Point::new(3, 9),
|
||||
expected_capture_name: "reference.call".to_string(),
|
||||
},
|
||||
Assertion {
|
||||
position: Point::new(5, 11),
|
||||
expected_capture_name: "reference.call".to_string(),
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
let mut tags_context = TagsContext::new();
|
||||
let tag_positions = get_tag_positions(&mut tags_context, &config, source.as_bytes()).unwrap();
|
||||
assert_eq!(
|
||||
tag_positions,
|
||||
&[
|
||||
(
|
||||
Point::new(1, 4),
|
||||
Point::new(1, 7),
|
||||
"definition.function".to_string()
|
||||
),
|
||||
(
|
||||
Point::new(3, 8),
|
||||
Point::new(3, 11),
|
||||
"reference.call".to_string()
|
||||
),
|
||||
(
|
||||
Point::new(5, 11),
|
||||
Point::new(5, 12),
|
||||
"reference.call".to_string()
|
||||
),
|
||||
]
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue