Fixed all tests

This commit is contained in:
greg 2017-01-05 02:36:28 -08:00
parent e1ce54aece
commit db92292569
2 changed files with 14 additions and 14 deletions

View File

@ -489,32 +489,32 @@ mod tests {
"fn a() 1 + 2 end", "fn a() 1 + 2 end",
&[FuncDefNode(Function {prototype: Prototype { ref name, ref parameters }, ref body})], &[FuncDefNode(Function {prototype: Prototype { ref name, ref parameters }, ref body})],
match &body[..] { &[ExprNode(BinExp(_, box Number(1.0), box Number(2.0)))] => true, _ => false } match &body[..] { &[ExprNode(BinExp(_, box Number(1.0), box Number(2.0)))] => true, _ => false }
&& name == "a" && match &parameters[..] { &[] => true, _ => false } && **name == "a" && match &parameters[..] { &[] => true, _ => false }
); );
parsetest!( parsetest!(
"fn a(x,y) 1 + 2 end", "fn a(x,y) 1 + 2 end",
&[FuncDefNode(Function {prototype: Prototype { ref name, ref parameters }, ref body})], &[FuncDefNode(Function {prototype: Prototype { ref name, ref parameters }, ref body})],
match &body[..] { &[ExprNode(BinExp(_, box Number(1.0), box Number(2.0)))] => true, _ => false } match &body[..] { &[ExprNode(BinExp(_, box Number(1.0), box Number(2.0)))] => true, _ => false }
&& name == "a" && *parameters == ["x","y"] && **name == "a" && *parameters[0] == "x" && *parameters[1] == "y" && parameters.len() == 2
); );
} }
#[test] #[test]
fn expression_parse_test() { fn expression_parse_test() {
parsetest!("a", &[ExprNode(Variable(ref s))], s == "a"); parsetest!("a", &[ExprNode(Variable(ref s))], **s == "a");
parsetest!("a + b", parsetest!("a + b",
&[ExprNode(BinExp(ref plus, box Variable(ref a), box Variable(ref b)))], &[ExprNode(BinExp(ref plus, box Variable(ref a), box Variable(ref b)))],
plus == "+" && a == "a" && b == "b"); **plus == "+" && **a == "a" && **b == "b");
parsetest!("a + b * c", parsetest!("a + b * c",
&[ExprNode(BinExp(ref plus, box Variable(ref a), box BinExp(ref mul, box Variable(ref b), box Variable(ref c))))], &[ExprNode(BinExp(ref plus, box Variable(ref a), box BinExp(ref mul, box Variable(ref b), box Variable(ref c))))],
plus == "+" && mul == "*" && a == "a" && b == "b" && c == "c"); **plus == "+" && **mul == "*" && **a == "a" && **b == "b" && **c == "c");
parsetest!("a * b + c", parsetest!("a * b + c",
&[ExprNode(BinExp(ref plus, box BinExp(ref mul, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))], &[ExprNode(BinExp(ref plus, box BinExp(ref mul, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))],
plus == "+" && mul == "*" && a == "a" && b == "b" && c == "c"); **plus == "+" && **mul == "*" && **a == "a" && **b == "b" && **c == "c");
parsetest!("(a + b) * c", parsetest!("(a + b) * c",
&[ExprNode(BinExp(ref mul, box BinExp(ref plus, box Variable(ref a), box Variable(ref b)), box Variable(ref c)))], &[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"); **plus == "+" && **mul == "*" && **a == "a" && **b == "b" && **c == "c");
} }
#[test] #[test]

View File

@ -162,19 +162,19 @@ mod tests {
fn basic_tokeniziation_tests() { fn basic_tokeniziation_tests() {
token_test!("let a = 3\n", token_test!("let a = 3\n",
[Keyword(Kw::Let), Identifier(ref a), Operator(Op(ref b)), NumLiteral(3.0), Newline], [Keyword(Kw::Let), Identifier(ref a), Operator(Op(ref b)), NumLiteral(3.0), Newline],
a == "a" && b == "="); **a == "a" && **b == "=");
token_test!("2+1", token_test!("2+1",
[NumLiteral(2.0), Operator(Op(ref a)), NumLiteral(1.0)], [NumLiteral(2.0), Operator(Op(ref a)), NumLiteral(1.0)],
a == "+"); **a == "+");
token_test!("2 + 1", token_test!("2 + 1",
[NumLiteral(2.0), Operator(Op(ref a)), NumLiteral(1.0)], [NumLiteral(2.0), Operator(Op(ref a)), NumLiteral(1.0)],
a == "+"); **a == "+");
token_test!("2.3*49.2", token_test!("2.3*49.2",
[NumLiteral(2.3), Operator(Op(ref a)), NumLiteral(49.2)], [NumLiteral(2.3), Operator(Op(ref a)), NumLiteral(49.2)],
a == "*"); **a == "*");
assert!(tokenize("2.4.5").is_err()); assert!(tokenize("2.4.5").is_err());
} }
@ -182,15 +182,15 @@ mod tests {
#[test] #[test]
fn string_test() { fn string_test() {
token_test!("null + \"a string\"", token_test!("null + \"a string\"",
[Keyword(Kw::Null), Operator(Op(ref a)), StrgLiteral(ref b)], [Keyword(Kw::Null), Operator(Op(ref a)), StrLiteral(ref b)],
a == "+" && b == "a string"); **a == "+" && **b == "a string");
} }
#[test] #[test]
fn operator_test() { fn operator_test() {
token_test!("a *> b", token_test!("a *> b",
[Identifier(ref a), Operator(Op(ref b)), Identifier(ref c)], [Identifier(ref a), Operator(Op(ref b)), Identifier(ref c)],
a == "a" && b == "*>" && c == "b"); **a == "a" && **b == "*>" && **c == "b");
} }