示例#1
0
        public void TestVariableItem()
        {
            Interpreter interp = new Interpreter();

            VariableItem varItem = new VariableItem();

            varItem.VariableValue = new IntItem(100);

            // Simulate creation of finding a variable
            var word = new PushStackItemWord("x", varItem);

            word.Execute(interp);

            Assert.AreEqual(1, interp.stack.Count);
            dynamic item = interp.stack.Peek();
            dynamic val  = item.VariableValue;

            Assert.AreEqual(100, val.IntValue);

            // Change variable value and check that the original changed, too
            item.VariableValue = new IntItem(21);
            dynamic val2 = varItem.VariableValue;

            Assert.AreEqual(21, val2.IntValue);
        }
示例#2
0
        protected bool TryHandleALiteral(string text, out Word result)
        {
            bool found = false;

            result = null;

            if (text == "A")
            {
                result = new PushStackItemWord(text, new IntItem(1));
                found  = true;
            }

            return(found);
        }