|
| 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