xrust/testutils/
item_value.rs1#[macro_export]
2macro_rules! item_value_tests (
3 ( $x:ty ) => {
4 use std::rc::Rc;
5 use xrust::value::Value;
6 use xrust::item::{Sequence, SequenceTrait, Item};
7
8 #[test]
9 fn item_value_string_empty_to_bool() {
10 assert_eq!(Item::<$x>::Value(Rc::new(Value::from(""))).to_bool(), false)
11 }
12 #[test]
13 fn item_value_string_nonempty_to_bool() {
14 assert_eq!(Item::<$x>::Value(Rc::new(Value::from("false"))).to_bool(), true)
15 }
16 #[test]
17 fn item_value_int_zero_to_bool() {
18 assert_eq!(Item::<$x>::Value(Rc::new(Value::from(0))).to_bool(), false)
19 }
20 #[test]
21 fn item_value_int_nonzero_to_bool() {
22 assert_eq!(Item::<$x>::Value(Rc::new(Value::from(42))).to_bool(), true)
23 }
24
25 #[test]
26 fn item_value_string_to_int() {
27 match (Item::<$x>::Value(Rc::new(Value::from("1"))).to_int()) {
28 Ok(i) => assert_eq!(i, 1),
29 Err(_) => {
30 panic!("to_int() failed")
31 }
32 }
33 }
34 #[test]
35 fn item_value_string_to_double() {
36 assert_eq!(Item::<$x>::Value(Rc::new(Value::from("2.0"))).to_double(), 2.0)
37 }
38
39 #[test]
40 fn sequence() {
41 let _s = Sequence::<$x>::new();
42 assert!(true)
43 }
44 }
45);