Ejemplo n.º 1
0
        public void VisitCall_CallsMethodWithCorrectOrderOfParametersPulledFromStack()
        {
            var testVmContext = new TestVmContext();

            testVmContext.ValueStack.Push(1);
            testVmContext.ValueStack.Push(2);
            testVmContext.ValueStack.Push(3);

            var sut = new RuntimeVisitor(testVmContext);

            sut.VisitCall(new CallInstruction(RuntimeVisitorTests.CorrectOrderVMFunction));
        }
Ejemplo n.º 2
0
        public void VisitSubtraction_DoesSubtractionWithNegativeResult_ResultPushedToValueStack()
        {
            var testVmContext = new TestVmContext();

            testVmContext.ValueStack.Push(7);
            testVmContext.ValueStack.Push(10);

            var sut = new RuntimeVisitor(testVmContext);

            sut.VisitSubtraction(new SubtractionInstruction());

            Assert.Equal(-3, testVmContext.ValueStack.Peek());
        }
Ejemplo n.º 3
0
        public void VisitListNewInstruction_CreatesNewListOnTopOfValueStack()
        {
            var testVmContext = new TestVmContext();
            var sut           = new RuntimeVisitor(testVmContext);

            sut.VisitList(new ListNewInstruction());

            Assert.Single(testVmContext.ValueStack);
            var topValue = testVmContext.ValueStack.Pop();

            Assert.IsType <List <object> >(topValue);
            var theList = (List <object>)topValue;

            Assert.Empty(theList);
        }
Ejemplo n.º 4
0
        public void VisitListAddInstruction_AddsObjectToListInValueStack()
        {
            var testVmContext = new TestVmContext();

            testVmContext.ValueStack.Push(new List <object>());
            testVmContext.ValueStack.Push(42);
            var sut = new RuntimeVisitor(testVmContext);

            sut.VisitList(new ListAddInstruction());

            Assert.Single(testVmContext.ValueStack);
            var topValue = testVmContext.ValueStack.Pop();

            Assert.IsType <List <object> >(topValue);
            var theList = (List <object>)topValue;

            Assert.Single(theList);
            Assert.Equal(42, theList[0]);
        }