Пример #1
0
        public void ExecuteBlockTest()
        {
            IKernel kernel = TestModule.GetTestKernel ();
            Assign assign = kernel.Get<Assign> ();
            assign.Ident = "x";

            Block block = new Block();
            Print print = kernel.Get<Print> ();
            print.Expr = new StringLiteral { Value = "Yo planet!" };
            block.Add(print);

            assign.Expr = block;

            Block statements = new Block ();
            statements.Add ( assign );
            Variable variable = kernel.Get<Variable> ();
            variable.Ident = "x";
            statements.Add ( variable );

            Executor target = new Executor ( statements );

            StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy;
            Assert.AreEqual ( "Yo planet!", output.Text );
        }
Пример #2
0
        public void SimpleIfTest()
        {
            IKernel kernel = TestModule.GetTestKernel ();
            Block statements = new Block ();

            Assign assign = kernel.Get<Assign> ();
            assign.Ident = "x";
            assign.Expr = new NumberLiteral
            {
                Value = 5
            };
            statements.Add ( assign );

            If iif = kernel.Get<If> ();
            Variable variable = kernel.Get<Variable> ();
            ( variable as Variable ).Ident = "x";

            iif.Test = new ArithExpr
            {
                Left = variable,
                Op = ArithOp.Equality,
                Right = new NumberLiteral
                {
                    Value = 5
                }
            };

            iif.Body = new Block ();

            Print print = kernel.Get<Print> ();
            Variable call = kernel.Get<Variable> ();
            ( call as Variable ).Ident = "x";
            print.Expr = call;

            iif.Body.Add( print );
            statements.Add ( iif );

            Executor target = new Executor ( statements );

            StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy;
            Assert.AreEqual ( "5", output.Text );
        }
Пример #3
0
        public void PrintExpressionTest()
        {
            IKernel kernel = TestModule.GetTestKernel ();
            Print print = kernel.Get<Print> ();
            print.Expr = new ArithExpr
            {
                Left = new StringLiteral
                {
                    Value = "Yo "
                },
                Right = new StringLiteral
                {
                    Value = "planet!"
                },
                Op = ArithOp.Add
            };

            Block statements = new Block ();
            statements.Add ( print );

            Executor target = new Executor ( statements );

            StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy;
            Assert.AreEqual ( "Yo planet!", output.Text );
        }
Пример #4
0
        public void SimplePrintTest()
        {
            IKernel kernel = TestModule.GetTestKernel ();
            Print print = kernel.Get<Print> ();
            print.Expr = new StringLiteral {
                Value = "Yo planet!"
            };

            Block statements = new Block ();
            statements.Add ( print );

            Executor target = new Executor ( statements );

            StandardOutDummy output = kernel.Get<IStandardOut> () as StandardOutDummy;
            Assert.AreEqual( "Yo planet!", output.Text );
        }