2021-07-13 10:48:08 +00:00
|
|
|
#![cfg(not(tarpaulin_include))]
|
2019-08-29 06:44:14 +00:00
|
|
|
#![cfg(feature = "serde")]
|
|
|
|
|
2019-08-29 06:21:34 +00:00
|
|
|
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());
|
|
|
|
}
|
2019-08-29 07:02:05 +00:00
|
|
|
}
|
2021-06-22 09:41:51 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_serde_errors() {
|
2021-06-22 09:43:58 +00:00
|
|
|
assert_eq!(
|
|
|
|
ron::de::from_str::<Node>("[\"5==5\"]"),
|
2022-02-20 07:54:24 +00:00
|
|
|
Err(ron::Error {
|
|
|
|
code: ron::de::ErrorCode::ExpectedString,
|
|
|
|
position: ron::de::Position { col: 1, line: 1 }
|
|
|
|
})
|
2021-06-22 09:43:58 +00:00
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
ron::de::from_str::<Node>("\"&\""),
|
2022-02-20 07:54:24 +00:00
|
|
|
Err(ron::Error {
|
|
|
|
code: ron::de::ErrorCode::Message(
|
|
|
|
"Found a partial token '&' that should be followed by another partial token."
|
|
|
|
.to_owned()
|
|
|
|
),
|
|
|
|
position: ron::de::Position { line: 0, col: 0 }
|
|
|
|
})
|
2021-06-22 09:43:58 +00:00
|
|
|
);
|
2021-08-16 11:23:02 +00:00
|
|
|
// Ensure that this does not panic.
|
|
|
|
assert_ne!(
|
|
|
|
ron::de::from_str::<Node>("[\"5==5\"]")
|
|
|
|
.unwrap_err()
|
|
|
|
.to_string(),
|
|
|
|
""
|
|
|
|
);
|
2021-06-22 09:43:58 +00:00
|
|
|
}
|