public void SequenceExpression() { var program = "(p;2)"; var ast = ParseText(program); var other = Seq(Var("p"), Num(2)); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void EqExp() { var program = "2 = 1"; var ast = ParseText(program); var other = BinExpr(Num(2), Num(1), "="); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void FunctionCall() { var program = "f(3)"; var ast = ParseText(program); var other = FCall("f", Num(3)); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void Assignment() { var program = "i := 1"; var ast = ParseText(program); var other = Assign(Var("i"), Num(1)); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void RecordAccess() { var program = "p.age"; var ast = ParseText(program); var other = RecordAccess(Var("p"), "age"); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void BreakInstruction() { var program = "break"; var ast = ParseText(program); var other = Break(); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void AddTwoNumbers() { var program = "1 + 2"; var ast = ParseText(program); var other = BinExpr(Num(1), Num(2), "+"); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void BinExprWithFunCall() { var program = "2 + f(2)"; var ast = ParseText(program); var other = BinExpr(Num(2), FCall("f", Num(2)), "+"); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void AddThreeNumbers() { var program = "1 + 2 - 3"; var ast = ParseText(program); var other = BinExpr(BinExpr(Num(1), Num(2), "+"), Num(3), "-"); Assert.IsTrue(AstComparer.EqualNodes(ast, other), "Binary expression must be equal"); }
public void AddTwoVars() { var program = "y + x"; var ast = ParseText(program); var other = BinExpr(Var("y"), Var("x"), "+"); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void BinExprWithNegExpr() { var program = "-2 + 1"; var ast = ParseText(program); var other = BinExpr(Neq(Num(2)), Num(1), "+"); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void If() { //arrays are second-citizens var program = "if 1 then 2 else 3"; var ast = ParseText(program); var other = If(Num(1), Num(2), Num(3)); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void If_DanglingElse() { //arrays are second-citizens var program = "if 1 then if 2 then 3 else 4"; var ast = ParseText(program); var other = If(Num(1), If(Num(2), Num(3), Num(4)), null); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void ArrayInstance() { //arrays are second-citizens var program = "nums[4] of 0"; var ast = ParseText(program); var other = ArrayInst("nums", Num(4), Num(0)); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void While() { var program = "while n do 2"; var ast = ParseText(program); var other = While( Var("n"), Num(2)); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void LetWithOneArrayTypeDeclaration() { var program = "let type myArray = array of int in 2 end"; var ast = ParseText(program); var other = Let( Decls(ArrayDecl("myArray", "int")), Seq(Num(2))); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void LetWithOneVarDeclaration() { var program = "let var i := 5 in 2 end"; var ast = ParseText(program); var other = Let( Decls(VarDecl("i", Num(5))), Seq(Num(2))); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void For() { var program = "for i := 1 to n do 2"; var ast = ParseText(program); var other = For("i", Num(1), Var("n"), Num(2)); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void LetWithOneRecordTypeDeclaration() { var program = "let type person = { name : string , age : int } in 2 end"; var ast = ParseText(program); var other = Let( Decls(RecordType("person", Fp("name", "string"), Fp("age", "int"))), Seq(Num(2))); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void RecordInstance() { var program = "let type person = { name : string , age : int } " + "in person{name = 1, age=2} end"; var ast = ParseText(program); var other = Let( Decls(RecordType("person", Fp("name", "string"), Fp("age", "int"))), Seq(Record("person", FieldIns("name", Num(1)), FieldIns("age", Num(2))))); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }
public void LetWithOneFunctionDeclaration() { var program = "let " + "function fakeSum(a: int, b:int) : int = 1" + "in 2 " + "end"; var ast = ParseText(program); var other = Let( Decls(FDecl("fakeSum", Num(1), "int", Fp("a", "int"), Fp("b", "int"))), Seq(Num(2))); Assert.IsTrue(AstComparer.EqualNodes(ast, other)); }