wrote tests for parser and checks

This commit is contained in:
Schrottkatze 2023-11-18 18:34:03 +01:00
commit 91adcd40f5
5 changed files with 52 additions and 119 deletions

View file

@ -1,6 +1,6 @@
use super::{
error::{FileId, SyntaxError},
PipelineElement, PipelineElementKind,
parse_syntax, PipelineElement, PipelineElementKind,
};
pub fn check(
@ -11,17 +11,15 @@ pub fn check(
let mut errs = Vec::new();
if let Err(e_span) = check_missing_streamer(&syntax) {
errs.push(SyntaxError::MissingStreamer(vec![(file_id, e_span)]));
errs.push(SyntaxError::MissingStreamer(vec![e_span]));
}
if let Err(mut err_locs) = check_missing_filters(&syntax) {
errs.push(SyntaxError::MissingFilter(
err_locs.into_iter().map(|loc| (file_id, loc)).collect(),
))
if let Err(err_locs) = check_missing_filters(&syntax) {
errs.push(SyntaxError::MissingFilter(err_locs))
}
if let Err(e_span) = check_missing_sink(&syntax) {
errs.push(SyntaxError::MissingSink(vec![(file_id, e_span)]));
errs.push(SyntaxError::MissingSink(vec![e_span]));
}
if errs.is_empty() {
@ -43,6 +41,14 @@ fn check_missing_streamer(syntax: &Vec<PipelineElement>) -> Result<(), logos::Sp
}
}
#[test]
fn test_check_missing_streamer() {
let test_data = "| invert | save \"./image_processed.jpg\"";
let syntax = parse_syntax(test_data).unwrap();
assert_eq!(check_missing_streamer(&syntax), Err(0..1))
}
fn check_missing_filters(syntax: &Vec<PipelineElement>) -> Result<(), Vec<logos::Span>> {
let mut missing_filter_locs = Vec::new();
@ -69,6 +75,14 @@ fn check_missing_filters(syntax: &Vec<PipelineElement>) -> Result<(), Vec<logos:
}
}
#[test]
fn test_check_missing_filters() {
let test_data = "meow | | test | awa | | nya";
let syntax = parse_syntax(test_data).unwrap();
assert_eq!(check_missing_filters(&syntax), Err(vec![5..8, 20..25]))
}
fn check_missing_sink(syntax: &Vec<PipelineElement>) -> Result<(), logos::Span> {
if let Some(&PipelineElement {
kind: PipelineElementKind::Pipe,
@ -80,3 +94,11 @@ fn check_missing_sink(syntax: &Vec<PipelineElement>) -> Result<(), logos::Span>
Ok(())
}
}
#[test]
fn test_check_missing_sink() {
let test_data = "meow | invert | ";
let syntax = parse_syntax(test_data).unwrap();
assert_eq!(check_missing_sink(&syntax), Err(14..15))
}