Allow overlap in specs.

This commit is contained in:
Patrick Thomson 2020-11-23 11:58:07 -05:00
parent 0b4661e401
commit 6764b803a0
2 changed files with 16 additions and 16 deletions

View file

@ -2,7 +2,6 @@ use crate::error;
use crate::error::Result;
use lazy_static::lazy_static;
use regex::Regex;
use std::collections::hash_map::HashMap;
use std::fs;
use tree_sitter::{Language, Parser, Point};
@ -14,6 +13,7 @@ lazy_static! {
pub struct CaptureInfo {
pub name: String,
pub position: Point,
pub terminus: Point,
}
#[derive(Debug, PartialEq, Eq)]
@ -134,22 +134,20 @@ pub fn assert_expected_captures(
) -> Result<()> {
let contents = fs::read_to_string(path)?;
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_capture_name))
.collect();
for info in &infos {
if !per_position_index.contains_key(&info.position) {
continue;
}
let found = per_position_index.get(&info.position).unwrap();
if **found != info.name && info.name != "name" {
Err(error::Error::new(format!(
"Assertion failed: at {}, found {}, expected {}",
info.position, found, info.name
)))?
let found = pairs.iter().find(|p| {
p.position.row == info.position.row
&& p.position >= info.position
&& p.position < info.terminus
});
if let Some(found) = found {
if found.expected_capture_name != info.name && info.name != "name" {
Err(error::Error::new(format!(
"Assertion failed: at {}, found {}, expected {}",
info.position, found.expected_capture_name, info.name
)))?
}
}
}
Ok(())