From f364ce2304371cbe89f40fa14e471919dac23015 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Mon, 26 Oct 2020 13:22:12 -0400 Subject: [PATCH] Remove old assertion stuff --- cli/src/query/assert.rs | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/cli/src/query/assert.rs b/cli/src/query/assert.rs index 5f042f3b..352f8de5 100644 --- a/cli/src/query/assert.rs +++ b/cli/src/query/assert.rs @@ -1,40 +1,16 @@ 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::{Language, Parser, Point}; -// TODO: It would be cooler to do this with a comments query rather than with a regex -// directly. -lazy_static! { - static ref METADATA_REGEX: Regex = Regex::new(r#"(\w+): ([^\s,]+), (\d+), (\d+)"#).unwrap(); -} - #[derive(Debug, Eq, PartialEq)] pub struct CaptureInfo { pub name: String, pub position: Point, } -#[derive(Debug, Eq, PartialEq)] -struct Assertion { - position: Point, - expected: String, -} - -impl From<&(Point, String)> for Assertion { - fn from(item: &(Point, String)) -> Assertion { - let (pos, info) = item; - Assertion { - position: *pos, - expected: info.to_string(), - } - } -} - pub fn assert_expected_captures( infos: Vec, path: String, @@ -45,20 +21,17 @@ pub fn assert_expected_captures( let pairs = parse_highlight_test(parser, language, contents.as_bytes())?; println!("{:?}", pairs); - let assertions: Vec = pairs.iter().map(Assertion::from).collect(); - - let per_position_index: HashMap = - assertions.iter().map(|a| (a.position, a)).collect(); + let per_position_index: HashMap = pairs.iter().map(|(a, b)| (*a, b)).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.expected != info.name && info.name != "name" { + if **found != info.name && info.name != "name" { Err(error::Error::new(format!( "Assertion failed: at {}, found {}, expected {}", - info.position, info.name, found.expected + info.position, info.name, found )))? } }