Ejemplo n.º 1
0
        public void AllowsToAssignValueToStringLikeInArray()
        {
            var runtime = new Runtime(new Processors());

            runtime.StartRootScope(new Compilation("testScope"));

            //// set 1 on position 0
            var assignEmptyTable =
                new Assigment(null,
                              new VariableName(null, "testString"),
                              new ValueString(null, new String("some long string")));

            //// set 1 on position 0
            var sut =
                new Assigment(null,
                              new ValueTable(null,
                                             new VariablePointer("testString"),
                                             new ValueNumber(new Number(32))),
                              new ValueNumber(new Number('X')));

            assignEmptyTable.Execute(runtime);
            Assert.Empty(runtime.Errors);

            sut.Execute(runtime);

            var value = runtime.GetVariable("testString").Get(runtime) as String;

            runtime.EndRootScope();

            Assert.Empty(runtime.Errors);
            Assert.Equal("some long string                X", value?.Value);
        }
Ejemplo n.º 2
0
        public void AllowsToAssignValueWhenTableIsEmpty()
        {
            var runtime = new Runtime(new Processors());

            runtime.StartRootScope(new Compilation("testScope"));

            //// set 1 on position 0
            var assignEmptyTable =
                new Assigment(null,
                              new VariableName(null, "testArray"),
                              new DeclareTable(null));

            //// set 1 on position 0
            var sut =
                new Assigment(null,
                              new ValueTable(null,
                                             new VariablePointer("testArray"),
                                             new ValueNumber(new Number(0))),
                              new ValueNumber(new Number(1)));

            assignEmptyTable.Execute(runtime);
            Assert.Empty(runtime.Errors);

            sut.Execute(runtime);

            runtime.EndRootScope();

            Assert.Empty(runtime.Errors);
        }
Ejemplo n.º 3
0
        public void AllowsToReadValue()
        {
            var runtime = new Runtime(new Processors());

            runtime.StartRootScope(new Compilation("testScope"));


            var assignEmptyTable =
                new Assigment(null,
                              new VariableName(null, "testString"),
                              new DeclareTable(null));

            assignEmptyTable.Execute(runtime);
            Assert.Empty(runtime.Errors);

            for (int k = 0; k < 1024 * 10; k++)
            {
                var setArrayElementValue =
                    new Assigment(null,
                                  new ValueTable(null,
                                                 new VariablePointer("testString"),
                                                 new ValueNumber(new Number(k))),
                                  new ValueNumber(new Number(k)));

                setArrayElementValue.Execute(runtime);
            }

            Assert.Empty(runtime.Errors);

            //// read some element in table
            var getNthValue =
                new Assigment(
                    null,
                    new VariableName(null, "tempNthValue"),
                    new ValueTable(null,
                                   new VariablePointer("testString"),
                                   new ValueNumber(new Number(10)))
                    );

            getNthValue.Execute(runtime);
            Assert.Empty(runtime.Errors);

            var value = runtime.GetVariable("tempNthValue").Get(runtime) as Number;

            Assert.Empty(runtime.Errors);

            runtime.EndRootScope();

            Assert.Empty(runtime.Errors);
            Assert.Equal(10, value?.Value);
        }