propitiate the tests
This commit is contained in:
parent
6adeb7b40d
commit
1aee60a7c0
3 changed files with 22 additions and 9 deletions
|
|
@ -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<Point, &String> =
|
||||
pairs.iter().map(|a| (a.position, &a.expected)).collect();
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue