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",
&[FuncDefNode(Function {prototype: Prototype { ref name, ref parameters }, ref body})],
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!(
"fn a(x,y) 1 + 2 end",
&[FuncDefNode(Function {prototype: Prototype { ref name, ref parameters }, ref body})],
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]
fn expression_parse_test() {
parsetest!("a", &[ExprNode(Variable(ref s))], s == "a");
parsetest!("a", &[ExprNode(Variable(ref s))], **s == "a");
parsetest!("a + 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",
&[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",
&[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",
&[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]

View File

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