Skip to content

Commit e7f0cc4

Browse files
committed
add python test case for tag testing
1 parent dba7a13 commit e7f0cc4

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

cli/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ mod pathological_test;
77
mod query_test;
88
mod tags_test;
99
mod test_highlight_test;
10+
mod test_tags_test;
1011
mod tree_test;

cli/src/tests/test_tags_test.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use super::helpers::fixtures::{get_language, get_tags_config};
2+
use crate::query_testing::{parse_position_comments, Assertion};
3+
use crate::test_tags::get_tag_positions;
4+
use tree_sitter::{Parser, Point};
5+
use tree_sitter_tags::TagsContext;
6+
7+
#[test]
8+
fn test_tags_test_with_basic_test() {
9+
let language = get_language("python");
10+
let config = get_tags_config("python");
11+
let source = [
12+
"# hi",
13+
"def abc(d):",
14+
" # <- definition.function",
15+
" e = fgh(d)",
16+
" # ^ reference.call",
17+
" return d(e)",
18+
" # ^ reference.call",
19+
"",
20+
]
21+
.join("\n");
22+
23+
let assertions =
24+
parse_position_comments(&mut Parser::new(), language, source.as_bytes()).unwrap();
25+
26+
assert_eq!(
27+
assertions,
28+
&[
29+
Assertion {
30+
position: Point::new(1, 4),
31+
expected_capture_name: "definition.function".to_string(),
32+
},
33+
Assertion {
34+
position: Point::new(3, 9),
35+
expected_capture_name: "reference.call".to_string(),
36+
},
37+
Assertion {
38+
position: Point::new(5, 11),
39+
expected_capture_name: "reference.call".to_string(),
40+
},
41+
]
42+
);
43+
44+
let mut tags_context = TagsContext::new();
45+
let tag_positions = get_tag_positions(&mut tags_context, &config, source.as_bytes()).unwrap();
46+
assert_eq!(
47+
tag_positions,
48+
&[
49+
(
50+
Point::new(1, 4),
51+
Point::new(1, 7),
52+
"definition.function".to_string()
53+
),
54+
(
55+
Point::new(3, 8),
56+
Point::new(3, 11),
57+
"reference.call".to_string()
58+
),
59+
(
60+
Point::new(5, 11),
61+
Point::new(5, 12),
62+
"reference.call".to_string()
63+
),
64+
]
65+
)
66+
}

0 commit comments

Comments
 (0)