Refactor serde tests into own module

This commit is contained in:
Sebastian Schmidt 2019-08-29 09:21:34 +03:00
parent 8c6228c3d9
commit 596d4d37b1
2 changed files with 15 additions and 12 deletions

View File

@ -2,6 +2,9 @@ extern crate evalexpr;
use evalexpr::{error::*, *}; use evalexpr::{error::*, *};
#[cfg(feature = "serde")]
mod serde;
#[test] #[test]
fn test_unary_examples() { fn test_unary_examples() {
assert_eq!(eval("3"), Ok(Value::Int(3))); assert_eq!(eval("3"), Ok(Value::Int(3)));
@ -589,18 +592,6 @@ fn test_strings() {
assert_eq!(eval("\"a\" < \"b\""), Ok(Value::from(true))); assert_eq!(eval("\"a\" < \"b\""), Ok(Value::from(true)));
} }
#[cfg(feature = "serde")]
#[test]
fn test_serde() {
let strings = ["3", "4+4", "21^(2*2)--3>5||!true"];
for string in &strings {
let manual_tree = build_operator_tree(string).unwrap();
let serde_tree: Node = ron::de::from_str(&format!("\"{}\"", string)).unwrap();
assert_eq!(manual_tree.eval(), serde_tree.eval());
}
}
#[test] #[test]
fn test_tuple_definitions() { fn test_tuple_definitions() {
assert_eq!(eval_empty("()"), Ok(())); assert_eq!(eval_empty("()"), Ok(()));

12
tests/serde.rs Normal file
View File

@ -0,0 +1,12 @@
use evalexpr::{build_operator_tree, Node};
#[test]
fn test_serde() {
let strings = ["3", "4+4", "21^(2*2)--3>5||!true"];
for string in &strings {
let manual_tree = build_operator_tree(string).unwrap();
let serde_tree: Node = ron::de::from_str(&format!("\"{}\"", string)).unwrap();
assert_eq!(manual_tree.eval(), serde_tree.eval());
}
}