Esempio n. 1
0
        public void ElseIfStatementInsideFunction()
        {
            TextReader programString = File.OpenText("code78.txt");
            DefaultSprakRunner program = new DefaultSprakRunner(programString);
            program.RunFunction("Foo", new object[] { "Left" });

            program.printOutputToConsole();
            program.getCompileTimeErrorHandler().printErrorsToConsole();

            Assert.AreEqual(1, program.Output.Count);
            Assert.AreEqual("l", program.Output[0]);
        }
Esempio n. 2
0
        public void DontMissStatementAfterElseIfElse()
        {
            TextReader programString = File.OpenText("code79.txt");
            DefaultSprakRunner program = new DefaultSprakRunner(programString);
            program.RunFunction("Foo", new object[] { "Forward" });

            program.printOutputToConsole();
            program.getCompileTimeErrorHandler().printErrorsToConsole();

            Assert.AreEqual(2, program.Output.Count);
            Assert.AreEqual("f", program.Output[0]);
            Assert.AreEqual("buu", program.Output[1]);
        }
Esempio n. 3
0
        public void CallFunctionFromOutside()
        {
            TextReader programString = File.OpenText("code73.txt");
            DefaultSprakRunner program = new DefaultSprakRunner(programString);
            program.run();
            program.printOutputToConsole();
            program.getCompileTimeErrorHandler().printErrorsToConsole();
            object result1 = program.RunFunction ("foo", new object[] {});
            object result2 = program.RunFunction ("bar", new object[] {});

            Console.WriteLine ("Result from foo: " + result1.ToString ());
            Console.WriteLine ("Result from bar: " + result2.ToString ());

            Assert.AreEqual (42, (int)(float)result1);
            Assert.AreEqual (127, (int)(float)result2);
        }
Esempio n. 4
0
        public void CallFunctionFromOutsideWithArgument()
        {
            TextReader programString = File.OpenText("code74.txt");
            DefaultSprakRunner program = new DefaultSprakRunner(programString);
            program.run();
            program.printOutputToConsole();
            program.getCompileTimeErrorHandler().printErrorsToConsole();

            object result = program.RunFunction ("double", new object[] { 40 });
            Console.WriteLine ("Result from double: " + result.ToString ());
            Assert.AreEqual (80, (int)(float)result);
        }
Esempio n. 5
0
        public void RemoteFunctionCallShouldNotRunCodeInGlobalScope()
        {
            TextReader programString = File.OpenText("code84.txt");
            DefaultSprakRunner program = new DefaultSprakRunner(programString);

            //program.run();
            program.printOutputToConsole();
            program.getCompileTimeErrorHandler().printErrorsToConsole();

            object result = program.RunFunction ("double", new object[] { 32 });

            Console.WriteLine ("Result from double: " + result.ToString ());
            Assert.AreEqual (64, (int)(float)result);

            Assert.AreEqual(1, program.Output.Count);
        }