From f626ca1427abce397311f11d57a69289711991b3 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 31 Dec 2016 04:00:30 -0800 Subject: [PATCH] Add test for conditional parsing --- conditional.schala | 2 +- src/parser.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/conditional.schala b/conditional.schala index 88ffbdf..ccd7cfa 100644 --- a/conditional.schala +++ b/conditional.schala @@ -1,2 +1,2 @@ -if true then 20 else 40 end +if 34 then 20 else 40 end diff --git a/src/parser.rs b/src/parser.rs index b2fd9b3..3ed5d20 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -452,4 +452,21 @@ mod tests { &[ExprNode(BinExp(ref mul, box BinExp(ref plus, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))], plus == "+" && mul == "*" && a == "a" && b == "b" && c == "c"); } + + #[test] + fn conditional_parse_test() { + use tokenizer; + use super::ASTNode::*; + use super::Expression::*; + + let t1 = "if null then 20 else 40 end"; + let tokens = tokenizer::tokenize(t1).unwrap(); + match parse(&tokens, &[]).unwrap()[..] { + [ExprNode(Conditional(box Null, box ref a, Some(box ref b)))] => { + // TODO make this test better + + } + _ => panic!("Bad conditional test"), + } + } }