コード例 #1
0
        public void ShouldExecuteInstSizeInRectangle()
        {
            PepsiMachine machine = new PepsiMachine();

            string[] methods =
            {
                "x [^x]",
                "x: newX [x := newX]",
                "y [^y]",
                "y: newY [y := newY]"
            };

            IClass cls = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                methods);

            machine.SetGlobalObject("aRectangle", cls.CreateInstance());

            Compiler compiler = new Compiler("^aRectangle instSize");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

            object result = block.Execute(machine, null);

            Assert.AreEqual(2, result);
        }
コード例 #2
0
        public void ShouldExecuteInstAtPut()
        {
            PepsiMachine machine = new PepsiMachine();

            string[] methods =
            {
                "x [^x]",
                "x: newX [x := newX]",
                "y [^y]",
                "y: newY [y := newY]"
            };

            IClass cls = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                methods);

            IObject iobj = cls.CreateInstance();

            machine.SetGlobalObject("aRectangle", iobj);

            Compiler compiler = new Compiler("aRectangle instAt: 0 put: 200");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

            block.Execute(machine, null);

            Assert.AreEqual(200, iobj.GetValueAt(0));
            Assert.IsNull(iobj.GetValueAt(1));
        }
コード例 #3
0
        public void ShouldSetGlobalVariable()
        {
            PepsiMachine machine = new PepsiMachine();

            machine.SetGlobalObject("One", 1);

            Assert.AreEqual(1, machine.GetGlobalObject("One"));
        }
コード例 #4
0
        public void ShouldExecuteBasicNew()
        {
            PepsiMachine machine = new PepsiMachine();
            IClass       cls     = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                null);

            machine.SetGlobalObject("Rectangle", cls.CreateInstance());

            Compiler compiler = new Compiler("^Rectangle class basicNew");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

            object obj = block.Execute(machine, null);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IObject));
            Assert.AreEqual(cls, ((IObject)obj).Behavior);
        }