1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#[macro_use] pub mod def; pub mod rules; use def::{Parse, Ruly}; use regex::Regex; use rules::{ Judgement::Plus, Nat::{Succ, Zero}, }; #[test] fn test() { let z = Zero(String::from("Z")); let n1 = Succ( String::from("S"), String::from("("), Box::new(z.clone()), String::from(")"), ); let n2 = Succ( String::from("S"), String::from("("), Box::new(n1.clone()), String::from(")"), ); let n3 = Succ( String::from("S"), String::from("("), Box::new(n2.clone()), String::from(")"), ); let n4 = Succ( String::from("S"), String::from("("), Box::new(n3.clone()), String::from(")"), ); let j1 = Plus( Box::new(n1), String::from("plus"), Box::new(n2), String::from("is"), Box::new(n4), ); let s = "S(Z) plus S(S(Z)) is S(S(S(S(Z))))"; let mut ruly = Ruly::new(); ruly.set_skip_reg(Regex::new(r"[ \n\r\t]*").unwrap()); ruly.set_input(&s); if let Ok(j2) = ruly.run::<rules::Judgement>() { assert_eq!(j1, j2); } else { assert!(false); } }