start pulling in the stuff from test_highlight

This commit is contained in:
Patrick Thomson 2020-10-26 12:58:32 -04:00
parent e370c5053e
commit 3e18e97f7c
3 changed files with 13 additions and 6 deletions

View file

@ -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)?
}
}

View file

@ -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<regex::Captures<'_>> for Assertion {
}
}
pub fn assert_expected_captures(infos: Vec<CaptureInfo>, path: String) -> Result<()> {
pub fn assert_expected_captures(
infos: Vec<CaptureInfo>,
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<Assertion> = METADATA_REGEX
.captures_iter(&contents)

View file

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