Exemplo n.º 1
0
        public void CanGetListIndex()
        {
            var list = new ListValue();
            list.Add("bar");
            cpu.PushStack(list);

            const int INDEX = 0;
            cpu.PushStack(INDEX);

            var opcode = new OpcodeGetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("bar", cpu.PopStack());
        }
Exemplo n.º 2
0
        public void CanGetCorrectLexiconIndex()
        {
            var list = new Lexicon();
            list.Add(new StringValue("foo"), new StringValue("bar"));
            list.Add(new StringValue("fizz"), new StringValue("bang"));
            cpu.PushStack(list);

            const string INDEX = "fizz";
            cpu.PushStack(INDEX);

            var opcode = new OpcodeGetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(new StringValue("bang"), cpu.PopStack());
        }
Exemplo n.º 3
0
        public void CanGetDoubleIndex()
        {
            var list = new ListValue();
            list.Add(new StringValue("bar"));
            list.Add(new StringValue("foo"));
            list.Add(new StringValue("fizz"));
            cpu.PushStack(list);

            const double INDEX = 2.5;
            cpu.PushStack(INDEX);

            var opcode = new OpcodeGetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(3, list.Count());
            Assert.AreEqual(new StringValue("fizz"), cpu.PopStack());
        }
Exemplo n.º 4
0
        public void CanGetLexiconIndex()
        {
            var list = new Lexicon<object,object>();
            list.Add("foo", "bar");
            cpu.PushStack(list);

            const string INDEX = "foo";
            cpu.PushStack(INDEX);

            var opcode = new OpcodeGetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("bar", cpu.PopStack());
        }