Skip to content

Commit

Permalink
test: improve coverage with minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib committed Feb 2, 2023
1 parent fa9fda6 commit 863bb35
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions boreal-parser/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,6 @@ mod tests {
#[test]
fn test_public_types() {
test_public_type(Input::new(r"a"));
test_public_type(Input::new(r"a").pos());
}
}
5 changes: 5 additions & 0 deletions boreal/src/compiler/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@ mod tests {
index: BoundedValueIndex::Module(0),
operations: Vec::new(),
});
test_type_traits_non_clonable(ModuleExpression::Function {
fun: |_, _| None,
arguments: Vec::new(),
operations: Vec::new(),
});
test_type_traits_non_clonable(IteratorType::Array(ValueType::Integer));
test_type_traits_non_clonable(TypeError::UnknownSubfield("a".to_owned()));
test_type_traits_non_clonable(ValueOrType::Type(&ValueType::Integer));
Expand Down
18 changes: 6 additions & 12 deletions boreal/src/compiler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@ use super::expression::{compile_expression, Type};
use super::module::compile_module;
use super::rule::RuleCompiler;
use super::{
AddRuleError, AddRuleErrorKind, AvailableModule, CompilationError, Compiler, CompilerParams,
ImportedModule, ModuleLocation, Namespace,
AddRuleError, AddRuleErrorKind, AddRuleStatus, AvailableModule, CompilationError, Compiler,
CompilerParams, ImportedModule, ModuleLocation, Namespace,
};
use crate::test_helpers::{test_type_traits, test_type_traits_non_clonable};
use boreal_parser::parse;

#[track_caller]
fn compile_expr(expression_str: &str, expected_type: Type) {
let rule_str = format!("rule a {{ strings: $a = /a/ condition: {expression_str} }}");
let file = parse(&rule_str).unwrap_or_else(|err| {
panic!(
"failed parsing: {}",
AddRuleError {
path: None,
kind: AddRuleErrorKind::Parse(err)
}
.to_short_description("mem", &rule_str)
)
});
let file = parse(&rule_str).unwrap();

let rule = file
.components
Expand Down Expand Up @@ -294,4 +285,7 @@ fn test_types_traits() {
}),
});
test_type_traits(CompilerParams::default());
test_type_traits_non_clonable(AddRuleStatus {
warnings: Vec::new(),
});
}
15 changes: 8 additions & 7 deletions boreal/src/evaluator/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ pub enum EvalError {
Timeout,
}

impl std::error::Error for EvalError {}
#[cfg(test)]
mod tests {
use crate::test_helpers::test_type_traits_non_clonable;

impl std::fmt::Display for EvalError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Undecidable => write!(f, "undecidable"),
Self::Timeout => write!(f, "timeout"),
}
use super::*;

#[test]
fn test_types_traits() {
test_type_traits_non_clonable(EvalError::Undecidable);
}
}
3 changes: 3 additions & 0 deletions boreal/src/evaluator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ mod tests {
#[test]
fn test_types_traits() {
test_type_traits(Value::Integer(0));
test_type_traits(Params {
string_max_nb_matches: 0,
});
test_type_traits_non_clonable(ScanData {
mem: b"",
module_values: Vec::new(),
Expand Down

0 comments on commit 863bb35

Please sign in to comment.