| 1 | // (c) 2017 Productize SPRL <[email protected]> |
| 2 | |
| 3 | extern crate symbolic_expressions; |
| 4 | |
| 5 | use symbolic_expressions::SexpError; |
| 6 | use symbolic_expressions::iteratom::*; |
| 7 | use symbolic_expressions::Sexp; |
| 8 | |
| 9 | struct Qq(i64); |
| 10 | |
| 11 | impl FromSexp for Qq { |
| 12 | fn from_sexp(s: &Sexp) -> Result<Self, SexpError> { |
| 13 | let i = s.named_value_i("d")?; |
| 14 | Ok(Qq(i)) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | |
| 19 | fn test_int() -> Result<(), SexpError> { |
| 20 | let s = "(a (b c) (d 42))"; |
| 21 | let s = symbolic_expressions::parser::parse_str(s)?; |
| 22 | let mut i = IterAtom::new(&s, "a")?; |
| 23 | let c = i.s_in_list("b")?; |
| 24 | assert_eq!(&c, "c"); |
| 25 | let e: Qq = i.t("d")?; |
| 26 | assert_eq!(e.0, 42); |
| 27 | Ok(()) |
| 28 | } |
| 29 | |
| 30 | #[test] |
| 31 | fn test_iteratom() { |
| 32 | test_int().unwrap(); |
| 33 | } |