public void ShouldEvaluateDefineAndInvokeEmptyBlock() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, "Object initialize [] result := [^Object initialize]"); evaluator.Evaluate(); IObject obj = (IObject)machine.GetGlobalObject("result"); IObject obj2 = (IObject)machine.GetGlobalObject("Object"); Assert.IsNotNull(obj); Assert.IsNotNull(obj2); Assert.AreEqual(obj, obj2); }
public void ShouldLoadList01() { PepsiMachine machine = this.LoadFile("List01.st"); Assert.IsNotNull(machine.GetGlobalObject("List")); Assert.IsNotNull(machine.GetGlobalObject("list1")); IObject list = (IObject)machine.GetGlobalObject("List"); IObject list1 = (IObject)machine.GetGlobalObject("list1"); Assert.AreEqual(2, list.Size); Assert.AreEqual(2, list1.Size); Assert.AreEqual(list.Behavior, list1.Behavior); }
public void ShouldEvaluateBlockWithCommands() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, "[newobject := Object class basicNew. otherobject := Object class basicNew]"); evaluator.Evaluate(); object newObject = machine.GetGlobalObject("newobject"); Assert.IsNotNull(newObject); object otherObject = machine.GetGlobalObject("otherobject"); Assert.IsNotNull(otherObject); }
public void ShouldLoadObject01() { PepsiMachine machine = this.LoadFile("Object01.st"); Assert.IsNotNull(machine.GetGlobalObject("obj1")); Assert.IsNotNull(machine.GetGlobalObject("Object")); IObject obj = (IObject)machine.GetGlobalObject("Object"); IObject obj1 = (IObject)machine.GetGlobalObject("obj1"); Assert.AreEqual(0, obj.Size); Assert.AreEqual(0, obj1.Size); Assert.AreEqual(obj.Behavior, obj1.Behavior); }
public void ShouldEvaluateDefineAndInvoke() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, "Object new [^self class basicNew] newObject := [^Object new]"); evaluator.Evaluate(); IObject obj = (IObject)machine.GetGlobalObject("newObject"); IObject obj2 = (IObject)machine.GetGlobalObject("Object"); Assert.IsNotNull(obj); Assert.IsNotNull(obj2); Assert.AreEqual(obj.Behavior, obj2.Behavior); }
public void ShouldEvaluateAssignment() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, "newObject := [^Object class basicNew]"); evaluator.Evaluate(); object newObject = machine.GetGlobalObject("newObject"); Assert.IsNotNull(newObject); Assert.IsInstanceOfType(newObject, typeof(AjSoda.IObject)); IObject obj = (IObject)machine.GetGlobalObject("Object"); Assert.AreEqual(((AjSoda.IObject)newObject).Behavior, obj.Behavior); }
public void ShouldCreateObjectInstance() { Block block = new Block(); block.CompileGet("Object"); block.CompileSend("class"); block.CompileSend("basicNew"); block.CompileReturnPop(); PepsiMachine machine = new PepsiMachine(); object obj = block.Execute(machine, null); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); IObject obj2 = (IObject)obj; Assert.IsNotNull(obj2.Behavior); IObject obj3 = (IObject)machine.GetGlobalObject("Object"); Assert.AreEqual(obj2.Behavior, obj3.Behavior); Assert.AreEqual(0, obj2.Size); }
public void ShouldCreateDelegatedPrototypeWithVariables() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, "List : Object(head tail)"); evaluator.Evaluate(); IObject listObject = (IObject)machine.GetGlobalObject("List"); IObject objObject = (IObject)machine.GetGlobalObject("Object"); Assert.IsNotNull(listObject); Assert.IsNotNull(objObject); Assert.AreEqual(((IBehavior)listObject.Behavior).Parent, objObject.Behavior); Assert.AreEqual(2, listObject.Size); }
public void ShouldSetGlobalVariable() { PepsiMachine machine = new PepsiMachine(); machine.SetGlobalObject("One", 1); Assert.AreEqual(1, machine.GetGlobalObject("One")); }
public void ShouldGetObjectBehavior() { PepsiMachine machine = new PepsiMachine(); IObject obj = (IObject)machine.GetGlobalObject("Object"); Assert.AreEqual(obj.Behavior, obj.Send("vtable")); }
public void ShouldLoadList02() { PepsiMachine machine = this.LoadFile("List02.st"); Assert.IsNotNull(machine.GetGlobalObject("list1")); Assert.IsNotNull(machine.GetGlobalObject("list2")); IObject list1 = (IObject)machine.GetGlobalObject("list1"); IObject list2 = (IObject)machine.GetGlobalObject("list2"); Assert.AreEqual(2, list1.Size); Assert.AreEqual(2, list1.Size); Assert.AreEqual("Hello", list1.GetValueAt(0)); Assert.AreEqual("World", list2.GetValueAt(0)); Assert.AreEqual(list2, list1.GetValueAt(1)); }
public void ShouldDelegateObject() { PepsiMachine machine = new PepsiMachine(); IObject obj = (IObject)machine.GetGlobalObject("Object"); IObject delegated = (IObject)obj.Send("delegated"); Assert.AreEqual(obj.Behavior, ((IBehavior)delegated.Behavior).Parent); Assert.AreEqual(obj.Behavior.Behavior, delegated.Behavior.Behavior); }
public void ShouldEvaluateDefine() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, "Object new [^self class basicNew]"); evaluator.Evaluate(); IObject obj = (IObject)machine.GetGlobalObject("Object"); Assert.IsNotNull(obj.Behavior.Send("lookup:", "new")); }
public void ShouldCompileAndRunWithGlobal() { Block block; block = new Block(); block.CompileGetConstant(10); block.CompileSet("Global"); PepsiMachine machine = new PepsiMachine(); block.Execute(machine); Assert.AreEqual(10, machine.GetGlobalObject("Global")); }
public void ShouldCompileAndRun() { PepsiMachine machine = new PepsiMachine(); Block block; block = new Block(); block.CompileArgument("newX"); block.CompileGet("newX"); block.CompileSet("GlobalX"); block.Execute(machine, 10); Assert.AreEqual(10, machine.GetGlobalObject("GlobalX")); }
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 ShouldExecuteClass() { PepsiMachine machine = new PepsiMachine(); object obj = machine.GetGlobalObject("Object"); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); Compiler compiler = new Compiler("^Object class basicNew class"); Block block = compiler.CompileBlock(); Assert.IsNotNull(block); object result = block.Execute(machine, null); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IClass)); }
public void ShouldAddMethod() { PepsiMachine machine = new PepsiMachine(); object obj = machine.GetGlobalObject("Object"); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); Compiler compiler = new Compiler("^Object class methodAt: #newMethod put: [self instSize]"); Block block = compiler.CompileBlock(); Assert.IsNotNull(block); block.Execute(machine, null); IObject iobj = (IObject)obj; Assert.IsNotNull(((IClass)iobj.Behavior).Lookup("newMethod")); }
public void ShouldDefineSubclass() { Block block = new Block(); block.CompileGet("Object"); block.CompileSend("class"); block.CompileSend("delegated"); block.CompileSet("NewClass"); PepsiMachine machine = new PepsiMachine(); block.Execute(machine, null); object obj = machine.GetGlobalObject("NewClass"); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); IObject iobj = (IObject)obj; IClass cls = (IClass)iobj.Behavior; Assert.AreEqual(0, cls.InstanceSize); }
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); }
public void ShouldHasGlobals() { PepsiMachine machine = new PepsiMachine(); Assert.IsNotNull(machine.GetGlobalObject("Object")); }
public void ShouldGetNullIfGlobalVariableDoesNotExists() { PepsiMachine machine = new PepsiMachine(); Assert.IsNull(machine.GetGlobalObject("InexistenteGlobal")); }