public void CompileAndExecuteTwoSimpleCommand() { Block block = this.compiler.CompileBlock("a := 1. b := 2"); Machine machine = new Machine(); block.Execute(machine, null); Assert.AreEqual(1, machine.GetGlobalObject("a")); Assert.AreEqual(2, machine.GetGlobalObject("b")); }
public void ExecuteBlockWithTwoCommands() { Loader loader = new Loader(new StringReader("One := 1.\nTwo := 2\n!\n"), new VmCompiler()); Machine machine = new Machine(); loader.LoadAndExecute(machine); Assert.AreEqual(1, machine.GetGlobalObject("One")); Assert.AreEqual(2, machine.GetGlobalObject("Two")); }
public void ExecuteBlock() { Loader loader = new Loader(new StringReader("One := 1\n!\n"), new SimpleCompiler()); Machine machine = new Machine(); loader.LoadAndExecute(machine); Assert.AreEqual(1, machine.GetGlobalObject("One")); }
public void DefineClassAndGetItsOutputString() { Loader loader = new Loader(@"DefineRectangleWithNewAndInitialize.st", new VmCompiler()); Machine machine = new Machine(); loader.LoadAndExecute(machine); BaseClass rectangle = (BaseClass)machine.GetGlobalObject("Rectangle"); string output = rectangle.ToOutputString(); Assert.IsNotNull(output); Assert.IsTrue(output.Contains("nil subclass:")); Assert.IsTrue(output.Contains("category: ''!")); Assert.IsTrue(output.Contains("!Rectangle class methods!")); Assert.IsTrue(output.Contains("!Rectangle methods!")); Assert.IsTrue(output.Contains("! !")); Assert.IsTrue(output.Contains("^x")); Assert.IsTrue(output.Contains("^y")); Assert.IsTrue(output.Contains("x := 10")); Assert.IsTrue(output.Contains("y := 20")); }
public void ExecuteSetObjectsFile() { Loader loader = new Loader(@"SetObjects.st", new VmCompiler()); Machine machine = new Machine(); loader.LoadAndExecute(machine); Assert.AreEqual(1, machine.GetGlobalObject("One")); Assert.AreEqual(2, machine.GetGlobalObject("Two")); }
public void ExecuteSetDotNetObjectFile() { Loader loader = new Loader(@"SetDotNetObject.st", new VmCompiler()); Machine machine = new Machine(); loader.LoadAndExecute(machine); object obj = machine.GetGlobalObject("FileInfo"); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(System.IO.FileInfo)); }
public void ExecuteTrueIfTrueIfFalse() { Machine machine = new Machine(); Block block = this.compiler.CompileBlock("true ifTrue: [GlobalName := 'bar'] ifFalse: [GlobalName := 'foo']"); Assert.IsNotNull(block); block.Execute(machine, null); Assert.AreEqual("bar", machine.GetGlobalObject("GlobalName")); }
public void ExecuteBlock() { Machine machine = new Machine(); object nil = machine.UndefinedObjectClass; Assert.IsNotNull(nil); Assert.IsInstanceOfType(nil, typeof(IClass)); Block block = this.compiler.CompileBlock("nil ifNil: [GlobalName := 'foo']"); Assert.IsNotNull(block); block.Execute(machine, null); Assert.IsNotNull(machine.GetGlobalObject("GlobalName")); }
public void ExecuteTrueIfFalse() { Machine machine = new Machine(); Parser compiler = new Parser("true ifFalse: [GlobalName := 'foo']"); Block block = compiler.CompileBlock(); Assert.IsNotNull(block); block.Execute(machine, null); Assert.IsNull(machine.GetGlobalObject("GlobalName")); }
public void DuplicateClassInOtherMachine() { Loader loader = new Loader(@"DefineRectangleWithNewAndInitialize.st", new SimpleCompiler()); Machine machine = new Machine(); loader.LoadAndExecute(machine); BaseClass rectangle = (BaseClass)machine.GetGlobalObject("Rectangle"); string output = rectangle.ToOutputString(); Loader loader2 = new Loader(new StringReader(output), new VmCompiler()); Machine machine2 = new Machine(); loader2.LoadAndExecute(machine2); BaseClass rectangle2 = (BaseClass)machine2.GetGlobalObject("Rectangle"); Assert.IsNotNull(rectangle2); Assert.IsNotNull(rectangle2.GetClassMethod("new")); Assert.IsNotNull(rectangle2.GetInstanceMethod("x")); Assert.IsNotNull(rectangle2.GetInstanceMethod("y")); Assert.IsNotNull(rectangle2.GetInstanceMethod("x:")); Assert.IsNotNull(rectangle2.GetInstanceMethod("y:")); Assert.IsNotNull(rectangle2.GetInstanceMethod("initialize")); Parser parser = new Parser("Rectangle new"); Block block = parser.CompileBlock(); object result = block.Execute(machine2, null); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IObject)); IObject iobj = (IObject)result; Assert.AreEqual(10, iobj[0]); Assert.AreEqual(20, iobj[1]); }
public void CompileAndRun() { Machine machine = new Machine(); Block block; block = new Block(); block.CompileArgument("newX"); block.CompileGet("newX"); block.CompileSet("GlobalX"); block.Execute(machine, new object[] { 10 }); Assert.AreEqual(10, machine.GetGlobalObject("GlobalX")); }
public void CompileAndRunWithGlobal() { Block block; block = new Block(); block.CompileGetConstant(10); block.CompileSet("Global"); Machine machine = new Machine(); block.Execute(machine, null); Assert.AreEqual(10, machine.GetGlobalObject("Global")); }
public void SetGlobalVariable() { Machine machine = new Machine(); machine.SetGlobalObject("One", 1); Assert.AreEqual(1, machine.GetGlobalObject("One")); }
public void LoadLibrary2UsingLoadFile() { Machine machine = new Machine(); machine.LoadFile("Library2.st"); Assert.IsNotNull(machine.GetGlobalObject("Object")); Assert.IsNotNull(machine.GetGlobalObject("Behavior")); Assert.IsNotNull(machine.GetGlobalObject("ClassDescription")); Assert.IsNotNull(machine.GetGlobalObject("Class")); Assert.IsNotNull(machine.GetGlobalObject("Metaclass")); Assert.IsNotNull(machine.GetGlobalObject("UndefinedObject")); }
public void InitializeMachine() { Machine machine = new Machine(); Assert.IsNotNull(machine.UndefinedObjectClass); Assert.IsNull(machine.ClassClass); Assert.IsNotNull(machine.Environment); var result = machine.GetGlobalObject("UndefinedObject"); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(IBehavior)); Assert.IsInstanceOfType(result, typeof(BaseClass)); var klass = (BaseClass)result; Assert.AreEqual("UndefinedObject", klass.Name); Assert.AreSame(klass, machine.UndefinedObjectClass); result = machine.GetGlobalObject("Machine"); Assert.IsNotNull(result); Assert.AreSame(machine, result); result = machine.GetGlobalObject("Smalltalk"); Assert.IsNotNull(result); Assert.AreSame(machine.Environment, result); Assert.AreSame(machine.Environment, machine.CurrentEnvironment); }
public void GetNullIfGlobalVariableDoesNotExists() { Machine machine = new Machine(); Assert.IsNull(machine.GetGlobalObject("InexistenteGlobal")); }