示例#1
0
        public void ShouldExecuteInstSize()
        {
            PepsiMachine machine = new PepsiMachine();

            machine.CreatePrototype("nil");
            object nil = machine.GetGlobalObject("nil");

            Assert.IsNotNull(nil);
            Assert.IsInstanceOfType(nil, typeof(IObject));

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

            Assert.IsNotNull(block);

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

            Assert.AreEqual(0, result);
        }
        public void ShouldCreatePrototype()
        {
            PepsiMachine machine = new PepsiMachine();
            IObject      proto   = machine.CreatePrototype("TestPrototype");

            Assert.IsNotNull(proto);

            object obj = machine.GetGlobalObject("TestPrototype");

            Assert.AreEqual(proto, obj);

            Assert.IsInstanceOfType(proto.Behavior, typeof(IClass));

            IClass cls = (IClass)proto.Behavior;

            Assert.AreEqual(-1, cls.GetInstanceVariableOffset("x"));
            Assert.IsNull(cls.Lookup("x"));
            Assert.IsNull(cls.Send("lookup:", "x"));
            Assert.IsNotNull(cls.Parent);
            Assert.IsInstanceOfType(cls.Parent, typeof(BaseClass));
            Assert.IsNotNull(cls.Machine);
            Assert.AreEqual(machine, cls.Machine);
        }