public void FifthChildOfRoot_ReturnsCorrectNodeTypes() { FunctionNode funcNode = astRoot.GetChildren(5) as FunctionNode; Assert.That(funcNode.GetChildren(0), Is.TypeOf <OutputNode>()); Assert.That(funcNode.GetChildren(1), Is.TypeOf <IfNode>()); }
public void FourthChildOfRoot_ReturnsCorrectNodeTypes() { FunctionNode funcNode = astRoot.GetChildren(4) as FunctionNode; Assert.That(funcNode.GetChildren(0), Is.TypeOf <FunctionCallNode>()); Assert.That(funcNode.GetChildren(1), Is.TypeOf <IfNode>()); Assert.That(funcNode.GetChildren(2), Is.TypeOf <IfNode>()); Assert.That(funcNode.GetChildren(3), Is.TypeOf <IfNode>()); }
public void FunctionWithReturnType_ShouldhaveReturnNode() { var ast = TestHelpers.MakeAstRoot("function testFunction -> | int\n return 2;\nendfunction"); FunctionNode funcNode = ast.GetChildren(0) as FunctionNode; Assert.That(funcNode.GetChildren(0), Is.InstanceOf <ReturnNode>()); }
public void RepeatTestNode_ShouldHaveAssignmentChild() { FunctionNode funcNode = this.astRoot.GetChildren(8) as FunctionNode; var repeatNode = funcNode.GetChildren(1) as WhileNode; Assert.That(repeatNode.GetChildren(0), Is.TypeOf <AssignmentNode>()); }
public void RepeatTestNode_ShouldHaveLoopExpression() { FunctionNode funcNode = this.astRoot.GetChildren(8) as FunctionNode; var repeatNode = funcNode.GetChildren(1) as WhileNode; Assert.That(repeatNode.Condition, Is.Not.Null); }
public void RepeatTestFunction_ShouldHaveRepeatNodeAsSecondChild() { FunctionNode funcNode = this.astRoot.GetChildren(8) as FunctionNode; Assert.That(funcNode.Identifier, Is.EqualTo("repeatTest")); Assert.That(funcNode.GetChildren(1), Is.TypeOf <WhileNode>()); }
public void RepeatTestNodeWithoutBody_ShouldHaveNoChildren() { var ast = TestHelpers.MakeAstRoot("function testFunction -> | void\nwhile 2 do\n endwhile\nendfunction"); FunctionNode funcNode = ast.GetChildren(0) as FunctionNode; WhileNode whileNode = funcNode.GetChildren(0) as WhileNode; Assert.That(whileNode.GetChildren(0), Is.Null); }
public void AssignStatementWithVariable_ShouldContainExpressionNode() { var ast = TestHelpers.MakeAstRoot("int varTest = 2;\nint tester = 2;\nfunction testFunction -> | void\ntester = varTest;\nendfunction"); FunctionNode funcNode = ast.GetChildren(2) as FunctionNode; AssignmentNode assignNode = funcNode.GetChildren(0) as AssignmentNode; Assert.That(assignNode.Identifier, Is.EqualTo("tester")); Assert.That(assignNode.Expression, Is.TypeOf <IdentfierNode>()); }
public void AssignStatementHasCorrectId() { var ast = TestHelpers.MakeAstRoot("int tester = 2;\nfunction testFunction -> | void\ntester = 4;\nendfunction"); FunctionNode funcNode = ast.GetChildren(1) as FunctionNode; AssignmentNode assignNode = funcNode.GetChildren(0) as AssignmentNode; //TestContext.WriteLine(((ExpressionNode)assignNode.Expression).Operator); Assert.That(assignNode.Identifier, Is.EqualTo("tester")); Assert.That(assignNode.Expression, Is.TypeOf <IntNode>()); }
public void IfNode_ShouldHaveAlternate() { FunctionNode funcNode = astRoot.GetChildren(4) as FunctionNode; AstNode presumableIfNode = funcNode.GetChildren(4); Assert.That(presumableIfNode, Is.TypeOf <IfNode>()); IfNode ifNode = presumableIfNode as IfNode; Assert.That(ifNode.Alternate, Is.Not.Null); Assert.That(ifNode.GetChildren(), Is.Not.Null); }
public void Visit(FunctionNode node) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(Indent + "FunctionNode: " + node.Identifier); IndentLevel++; var child = node.GetChildren(); while (child != null) { child.Accept(this); child = child.RightSibling; } IndentLevel--; }