public void PrintExpressionTest() { IKernel kernel = TestModule.GetTestKernel (); IExecutorFactory factory = kernel.Get<IExecutorFactory> (); Print print = new Print ( factory.GetPrintExecutor() ); print.Expr = new ArithExpr { Left = new StringLiteral { Value = "Yo " }, Right = new StringLiteral { Value = "planet!" }, Op = ArithOp.Add }; Block statements = new Block (); statements.Add ( print ); new Executor ( statements ); StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy; Assert.AreEqual ( "Yo planet!", output.Text ); }
public void TestAccessArray() { IKernel kernel = TestModule.GetTestKernel (); var factory = kernel.Get<IExecutorFactory>(); Block statements = new Block (); statements.Scope = new Scope (); ArrayExpr array = new ArrayExpr(factory.GetArrayExecutor()); array.Scope = statements.Scope; array.Elements.Add(new StringLiteral { Value = "yay" }); array.Elements.Add(new StringLiteral { Value = "boo" }); Assign assign = new Assign(factory.GetAssignExecutor()) { Ident = new Variable ( factory.GetVariableExecutor ()) { Scope = statements.Scope, Ident = "x" }, Expr = array, Scope = statements.Scope }; Print print = new Print(factory.GetPrintExecutor()); print.Expr = new Variable( factory.GetVariableExecutor()) { Scope = statements.Scope, Ident = "x", Indexer = new NumberLiteral() { Value = 1 } }; statements.Add ( assign ); statements.Add ( print ); statements.Execute(); StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy; Assert.AreEqual ( "boo", output.Text ); }
public bool TryParse(Tokens tokens, IScope scope, out IStatement statement) { if ( tokens.PeekToken () == PrintTag ) { // Print statement tokens.RemoveNextToken ( PrintTag ); Print print = new Print( _executorFactory.GetPrintExecutor ()); print.Expr = _expressionParser.ParseExpression ( scope, tokens ); statement = print; return true; } statement = null; return false; }
public void ExecuteBlockTest() { IKernel kernel = TestModule.GetTestKernel (); IExecutorFactory factory = kernel.Get<IExecutorFactory> (); Block statements = new Block (); statements.Scope = new Scope(); Assign assign = new Assign ( factory.GetAssignExecutor () ); assign.Ident = new Variable ( factory.GetVariableExecutor () ) { Ident = "x" }; assign.Scope = statements.Scope; Block block = new Block(); block.Scope = statements.Scope; Print print = new Print ( factory.GetPrintExecutor () ); print.Scope = block.Scope; print.Expr = new StringLiteral { Value = "Yo planet!" }; block.Add(print); assign.Expr = block; Assert.IsTrue ( assign.Scope != null ); statements.Add ( assign ); Variable variable = new Variable ( factory.GetVariableExecutor () ); variable.Ident = "x"; variable.Scope = statements.Scope; statements.Add ( variable ); new Executor ( statements ); StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy; Assert.AreEqual ( "Yo planet!", output.Text ); }
public void Execute( Print info ) { _debug.PrintDebugInfo ( "Printing" ); _output.Output ( info.Expr.Evaluate ().StringValue ); }
public void SimpleIfTest() { IKernel kernel = TestModule.GetTestKernel (); IExecutorFactory factory = kernel.Get<IExecutorFactory> (); Block statements = new Block (); statements.Scope = new Scope (); Assign assign = new Assign ( factory.GetAssignExecutor () ); assign.Scope = statements.Scope; assign.Ident = new Variable ( factory.GetVariableExecutor () ) { Ident = "x" }; assign.Expr = new NumberLiteral { Value = 5 }; statements.Add ( assign ); If iif = new If ( factory.GetIfExecutor() ); Variable variable = new Variable ( factory.GetVariableExecutor () ); ( variable as Variable ).Ident = "x"; iif.Scope = statements.Scope; iif.Test = new ArithExpr { Scope = iif.Scope, Left = variable, Op = ArithOp.Equality, Right = new NumberLiteral { Value = 5 } }; iif.Body = new Block (); iif.Body.Scope = statements.Scope; Print print = new Print ( factory.GetPrintExecutor () ); Variable call = new Variable ( factory.GetVariableExecutor () ); ( call as Variable ).Ident = "x"; print.Expr = call; print.Scope = iif.Body.Scope; call.Scope = iif.Body.Scope; iif.Body.Add( print ); statements.Add ( iif ); new Executor ( statements ); StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy; Assert.AreEqual ( "5", output.Text ); }