all tests passing again
This commit is contained in:
@ -1,4 +1,13 @@
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum SqlExpectation {
|
||||
Single(String),
|
||||
Multi(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ExpectBlock {
|
||||
@ -6,7 +15,7 @@ pub struct ExpectBlock {
|
||||
pub result: Option<serde_json::Value>,
|
||||
pub errors: Option<Vec<serde_json::Value>>,
|
||||
#[serde(default)]
|
||||
pub sql: Option<Vec<String>>,
|
||||
pub sql: Option<Vec<SqlExpectation>>,
|
||||
}
|
||||
|
||||
impl ExpectBlock {
|
||||
@ -29,8 +38,7 @@ impl ExpectBlock {
|
||||
));
|
||||
}
|
||||
|
||||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
let ws_re = Regex::new(r"\s+").unwrap();
|
||||
|
||||
let types = HashMap::from([
|
||||
(
|
||||
@ -53,9 +61,18 @@ impl ExpectBlock {
|
||||
// Placeholder regex: {{type:name}} or {{type}}
|
||||
let ph_rx = Regex::new(r"\{\{([a-z]+)(?:[:]([^}]+))?\}\}").unwrap();
|
||||
|
||||
for (i, pattern_str) in patterns.iter().enumerate() {
|
||||
let aline = &actual[i];
|
||||
let mut pp = regex::escape(pattern_str);
|
||||
for (i, pattern_expect) in patterns.iter().enumerate() {
|
||||
let aline_raw = &actual[i];
|
||||
let aline = ws_re.replace_all(aline_raw, " ").trim().to_string();
|
||||
|
||||
let pattern_str_raw = match pattern_expect {
|
||||
SqlExpectation::Single(s) => s.clone(),
|
||||
SqlExpectation::Multi(m) => m.join(" "),
|
||||
};
|
||||
|
||||
let pattern_str = ws_re.replace_all(&pattern_str_raw, " ").trim().to_string();
|
||||
|
||||
let mut pp = regex::escape(&pattern_str);
|
||||
pp = pp.replace(r"\{\{", "{{").replace(r"\}\}", "}}");
|
||||
|
||||
let mut cap_names = HashMap::new(); // cg_X -> var_name
|
||||
@ -96,7 +113,7 @@ impl ExpectBlock {
|
||||
Err(e) => return Err(format!("Bad constructed regex: {} -> {}", final_rx_str, e)),
|
||||
};
|
||||
|
||||
if let Some(captures) = final_rx.captures(aline) {
|
||||
if let Some(captures) = final_rx.captures(&aline) {
|
||||
for (cg_name, var_name) in cap_names {
|
||||
if let Some(m) = captures.name(&cg_name) {
|
||||
let matched_str = m.as_str();
|
||||
|
||||
Reference in New Issue
Block a user