mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2025-10-30 00:57:58 +01:00
refactoring and implementing clippy suggestions
This commit is contained in:
parent
3952091018
commit
2db2ef2ea1
5 changed files with 45 additions and 51 deletions
|
|
@ -1,22 +1,20 @@
|
|||
use super::{
|
||||
error::{FileId, SyntaxError},
|
||||
parse_syntax, PipelineElement, PipelineElementKind,
|
||||
};
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
pub fn check(
|
||||
syntax: &Vec<PipelineElement>,
|
||||
) -> Result<(), Vec<SyntaxError>> {
|
||||
use super::{error::SyntaxError, PipelineElement, PipelineElementKind};
|
||||
|
||||
pub fn check(syntax: &[PipelineElement]) -> Result<(), Vec<SyntaxError>> {
|
||||
let mut errs = Vec::new();
|
||||
|
||||
if let Err(e_span) = check_missing_streamer(&syntax) {
|
||||
if let Err(e_span) = check_missing_streamer(syntax) {
|
||||
errs.push(SyntaxError::MissingStreamer(vec![e_span]));
|
||||
}
|
||||
|
||||
if let Err(err_locs) = check_missing_filters(&syntax) {
|
||||
if let Err(err_locs) = check_missing_filters(syntax) {
|
||||
errs.push(SyntaxError::MissingFilter(err_locs))
|
||||
}
|
||||
|
||||
if let Err(e_span) = check_missing_sink(&syntax) {
|
||||
if let Err(e_span) = check_missing_sink(syntax) {
|
||||
errs.push(SyntaxError::MissingSink(vec![e_span]));
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +25,7 @@ pub fn check(
|
|||
}
|
||||
}
|
||||
|
||||
fn check_missing_streamer(syntax: &Vec<PipelineElement>) -> Result<(), logos::Span> {
|
||||
fn check_missing_streamer(syntax: &[PipelineElement]) -> Result<(), logos::Span> {
|
||||
if let Some(&PipelineElement {
|
||||
kind: PipelineElementKind::Pipe,
|
||||
ref span,
|
||||
|
|
@ -39,15 +37,7 @@ 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>> {
|
||||
fn check_missing_filters(syntax: &[PipelineElement]) -> Result<(), Vec<logos::Span>> {
|
||||
let mut missing_filter_locs = Vec::new();
|
||||
|
||||
for i in 0..syntax.len() {
|
||||
|
|
@ -73,15 +63,7 @@ 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> {
|
||||
fn check_missing_sink(syntax: &[PipelineElement]) -> Result<(), logos::Span> {
|
||||
if let Some(&PipelineElement {
|
||||
kind: PipelineElementKind::Pipe,
|
||||
ref span,
|
||||
|
|
@ -92,11 +74,3 @@ 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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue