diff --git a/cli/src/query.rs b/cli/src/query.rs index 704a2c56..de320fba 100644 --- a/cli/src/query.rs +++ b/cli/src/query.rs @@ -93,7 +93,7 @@ pub fn query_files_at_paths( } } if should_test { - assert::assert_expected_captures(results, path)? + assert::assert_expected_captures(results, path, &mut parser, language)? } } diff --git a/cli/src/query/assert.rs b/cli/src/query/assert.rs index 96162c5b..69f0de91 100644 --- a/cli/src/query/assert.rs +++ b/cli/src/query/assert.rs @@ -1,10 +1,11 @@ use crate::error; use crate::error::Result; +use crate::test_highlight::parse_highlight_test; use lazy_static::lazy_static; use regex::Regex; use std::collections::hash_map::HashMap; use std::fs; -use tree_sitter::Point; +use tree_sitter::{Language, Parser, Point}; // TODO: It would be cooler to do this with a comments query rather than with a regex // directly. @@ -48,8 +49,14 @@ impl From> for Assertion { } } -pub fn assert_expected_captures(infos: Vec, path: String) -> Result<()> { +pub fn assert_expected_captures( + infos: Vec, + path: String, + parser: &mut Parser, + language: Language, +) -> Result<()> { let contents = fs::read_to_string(path)?; + let _pairs = parse_highlight_test(parser, language, contents.as_bytes()); let assertions: Vec = METADATA_REGEX .captures_iter(&contents) diff --git a/test/fixtures/queries/python.py b/test/fixtures/queries/python.py index a48ed2de..01ec9ab0 100644 --- a/test/fixtures/queries/python.py +++ b/test/fixtures/queries/python.py @@ -1,7 +1,7 @@ def foo(): pass -# definition: function: 0, 0 +# <- definition.function def bar(): -# definition: function, 3, 0 +# <- definition.function foo() -# reference: call, 5, 4 + # <- reference.call