Skip to content

Commit

Permalink
Increase test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ISibboI committed Oct 17, 2024
1 parent 05430ca commit bb428e5
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bin/evalexpr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(not(tarpaulin_include))]
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = std::env::args().skip(1).collect::<Vec<String>>().join(" ");

Expand Down
29 changes: 29 additions & 0 deletions src/feature_serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,32 @@ impl<NumericTypes: EvalexprNumericTypes> de::Visitor<'_> for NodeVisitor<Numeric
}
}
}

#[cfg(test)]
mod tests {
use std::{
fmt::{Debug, Formatter, Write},
marker::PhantomData,
};

use serde::de::Visitor;

use crate::DefaultNumericTypes;

use super::NodeVisitor;

#[test]
fn node_visitor() {
struct Debugger;

impl Debug for Debugger {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
NodeVisitor::<DefaultNumericTypes>(PhantomData).expecting(f)
}
}

let mut output = String::new();
write!(output, "{:?}", Debugger).unwrap();
assert!(!output.is_empty());
}
}
44 changes: 44 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,3 +2500,47 @@ fn test_clear() {
assert!(context.get_value("five").is_none());
assert!(eval_with_context("abc(5)", &context).is_err());
}

#[test]
fn test_iter_empty_contexts() {
assert_eq!(
EmptyContext::<DefaultNumericTypes>::default()
.iter_variables()
.next(),
None
);
assert_eq!(
EmptyContext::<DefaultNumericTypes>::default()
.iter_variable_names()
.next(),
None
);
assert_eq!(
EmptyContextWithBuiltinFunctions::<DefaultNumericTypes>::default()
.iter_variables()
.next(),
None
);
assert_eq!(
EmptyContextWithBuiltinFunctions::<DefaultNumericTypes>::default()
.iter_variable_names()
.next(),
None
);
}

#[test]
fn test_empty_context_builtin_functions() {
assert!(EmptyContext::<DefaultNumericTypes>::default().are_builtin_functions_disabled());
assert!(
!EmptyContextWithBuiltinFunctions::<DefaultNumericTypes>::default()
.are_builtin_functions_disabled()
);
}

#[test]
fn test_compare_different_numeric_types() {
assert_eq!(eval("1 < 2.0"), Ok(true.into()));
assert_eq!(eval("1 >= 2"), Ok(false.into()));
assert_eq!(eval("1 >= 2.0"), Ok(false.into()));
}

0 comments on commit bb428e5

Please sign in to comment.