Skip to content

Commit

Permalink
Increase test coverage (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
ISibboI authored Oct 25, 2024
2 parents 5f87929 + d592e9d commit 2dee218
Show file tree
Hide file tree
Showing 4 changed files with 106 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());
}
}
2 changes: 2 additions & 0 deletions src/token/display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(tarpaulin_include))]

use std::fmt;

use crate::{
Expand Down
74 changes: 74 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,3 +2500,77 @@ 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()));
}

#[test]
fn test_escape_sequences() {
assert_eq!(
eval("\"\\x\""),
Err(EvalexprError::IllegalEscapeSequence("\\x".to_string()))
);
assert_eq!(
eval("\"\\"),
Err(EvalexprError::IllegalEscapeSequence("\\".to_string()))
);
}

#[test]
fn test_unmatched_partial_tokens() {
assert_eq!(
eval("|"),
Err(EvalexprError::UnmatchedPartialToken {
first: PartialToken::VerticalBar,
second: None
})
);
}

#[test]
fn test_node_mutable_access() {
let mut node = build_operator_tree::<DefaultNumericTypes>("5").unwrap();
assert_eq!(node.children_mut().len(), 1);
assert_eq!(*node.operator_mut(), Operator::RootNode);
}

0 comments on commit 2dee218

Please sign in to comment.