public void ForIfTest(string line, string expected) { var parser = GenerateTree( @"{ for i = 1..5 {" + $"\n if({line})\n" + @"{ a = 3; } } }"); var expectedTree = GenerateTree( @"{ for i = 1..5 {" + $"\n if({expected})\n" + @"{ a = 3; } } }"); var a = new NumberEqualityVisitor(); a.Visit(parser.root); var first = ((parser.root.StList[0] as ForNode) .Stat.StList[0] as IfNode) .Condition as BoolValNode; var second = ((expectedTree.root.StList[0] as ForNode) .Stat.StList[0] as IfNode) .Condition as BoolValNode; Assert.AreEqual(first.Val, second.Val); }
public void OneLineTests(string line, string expected) { var parser = GenerateTree(@"{" + $"\n{line}\n" + @"}"); var expectedTree = GenerateTree(@"{" + $"\n{expected}\n" + @"}"); var a = new NumberEqualityVisitor(); a.Visit(parser.root); var first = (parser.root.StList[0] as AssignNode).Expr as BoolValNode; var second = (expectedTree.root.StList[0] as AssignNode).Expr as BoolValNode; Assert.AreEqual(first.Val, second.Val); }
public void WhileTest(string line, string expected) { var parser = GenerateTree(@"{" + $"\n while({line})\n" + @"{ a = 3; } }"); var expectedTree = GenerateTree(@"{" + $"\n while({expected})\n" + @"{ a = 3; } }"); var a = new NumberEqualityVisitor(); a.Visit(parser.root); var first = (parser.root.StList[0] as WhileNode).Condition as BoolValNode; var second = (expectedTree.root.StList[0] as WhileNode).Condition as BoolValNode; Assert.AreEqual(first.Val, second.Val); }