diff --git a/cli/src/query_testing.rs b/cli/src/query_testing.rs index b6e2c169..9618d1f6 100644 --- a/cli/src/query_testing.rs +++ b/cli/src/query_testing.rs @@ -16,6 +16,7 @@ pub struct CaptureInfo { pub position: Point, } +#[derive(Debug, PartialEq, Eq)] pub struct Assertion { pub position: Point, pub expected: String, @@ -24,7 +25,7 @@ pub struct Assertion { /// Parse the given source code, finding all of the comments that contain /// highlighting assertions. Return a vector of (position, expected highlight name) /// pairs. -pub fn parse_highlight_test( +pub fn parse_position_comments( parser: &mut Parser, language: Language, source: &[u8], @@ -132,7 +133,7 @@ pub fn assert_expected_captures( language: Language, ) -> Result<()> { let contents = fs::read_to_string(path)?; - let pairs = parse_highlight_test(parser, language, contents.as_bytes())?; + let pairs = parse_position_comments(parser, language, contents.as_bytes())?; let per_position_index: HashMap = pairs.iter().map(|a| (a.position, &a.expected)).collect(); diff --git a/cli/src/test_highlight.rs b/cli/src/test_highlight.rs index da67f753..55a709aa 100644 --- a/cli/src/test_highlight.rs +++ b/cli/src/test_highlight.rs @@ -1,6 +1,6 @@ use super::error::Result; use crate::loader::Loader; -use crate::query_testing::{parse_highlight_test, Assertion}; +use crate::query_testing::{parse_position_comments, Assertion}; use ansi_term::Colour; use std::fs; use std::path::Path; @@ -91,7 +91,8 @@ pub fn test_highlight( // Highlight the file, and parse out all of the highlighting assertions. let highlight_names = loader.highlight_names(); let highlights = get_highlight_positions(loader, highlighter, highlight_config, source)?; - let assertions = parse_highlight_test(highlighter.parser(), highlight_config.language, source)?; + let assertions = + parse_position_comments(highlighter.parser(), highlight_config.language, source)?; // Iterate through all of the highlighting assertions, checking each one against the // actual highlights. diff --git a/cli/src/tests/test_highlight_test.rs b/cli/src/tests/test_highlight_test.rs index 6a857dd9..66920823 100644 --- a/cli/src/tests/test_highlight_test.rs +++ b/cli/src/tests/test_highlight_test.rs @@ -1,5 +1,6 @@ use super::helpers::fixtures::{get_highlight_config, get_language, test_loader}; -use crate::test_highlight::{get_highlight_positions, parse_highlight_test}; +use crate::query_testing::{parse_position_comments, Assertion}; +use crate::test_highlight::get_highlight_positions; use tree_sitter::{Parser, Point}; use tree_sitter_highlight::{Highlight, Highlighter}; @@ -25,13 +26,23 @@ fn test_highlight_test_with_basic_test() { ] .join("\n"); - let assertions = parse_highlight_test(&mut Parser::new(), language, source.as_bytes()).unwrap(); + let assertions = + parse_position_comments(&mut Parser::new(), language, source.as_bytes()).unwrap(); assert_eq!( assertions, &[ - (Point::new(0, 5), "function".to_string()), - (Point::new(0, 11), "keyword".to_string()), - (Point::new(3, 9), "variable.parameter".to_string()), + Assertion { + position: Point::new(0, 5), + expected: "function".to_string() + }, + Assertion { + position: Point::new(0, 11), + expected: "keyword".to_string() + }, + Assertion { + position: Point::new(3, 9), + expected: "variable.parameter".to_string() + }, ] );