Exemplo n.º 1
0
        public static void Run()
        {
            Globals globals = new Globals();

            var script = string.Join(
                Environment.NewLine,
                "while (ShouldQuit == false)",
                "{",
                "Console.WriteLine($\"Script running - time is {DateTime.Now:HH:mm:ss.fff}\");",
                "Thread.Sleep(500);",
                "}",
                "Console.WriteLine(\"Script complete\");");

            Console.WriteLine(script);

            Console.WriteLine("\nStarting... press any key to signal the script to stop");
            var easyScriptTask = EasyScript <object> .AsyncGo(script, globals);

            Console.ReadKey(intercept: true);

            Console.WriteLine("Signalling the script to stop asap and waiting for completion...");
            globals.ShouldQuit = true;
            easyScriptTask.Wait();

            var easyScript = easyScriptTask.Result;

            Console.WriteLine(easyScript.Summary);
        }
Exemplo n.º 2
0
        public void Go_BlankScript_NoCompilationWarnings()
        {
            var easyScript = EasyScript <object> .Go("");

            Assert.Equal(
                expected: 0,
                actual: easyScript.CompilationOutput.WarningCount);
        }
Exemplo n.º 3
0
        public void Go_BadScript_OneCompilationError()
        {
            var easyScript = EasyScript <object> .Go("int x = unknown_variable;");

            Assert.Equal(
                expected: 1,
                actual: easyScript.CompilationOutput.ErrorCount);
        }
Exemplo n.º 4
0
        public void Go_ReturnValue_AsExpected()
        {
            var script     = "1";
            var easyScript = EasyScript <int> .Go(script);

            Assert.Equal(
                expected: 1,
                actual: easyScript.ScriptResults);
        }
Exemplo n.º 5
0
        public void Go_BlankScript_SummaryAllOk()
        {
            var easyScript = EasyScript <object> .Go("");

            Assert.Contains(
                expectedSubstring: "all ok",
                actualString: easyScript.Summary,
                comparisonType: System.StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 6
0
        public void Go_InvalidReturnValue_FailsToCompile()
        {
            var script     = "1.2";
            var easyScript = EasyScript <int> .Go(script);

            Assert.Equal(
                expected: 1,
                actual: easyScript.CompilationOutput.ErrorCount);
        }
        public static void Run()
        {
            var easyScript = EasyScript <object> .Go("var x = y");

            Console.WriteLine(easyScript.Summary);
            foreach (var message in easyScript.CompilationOutput.Messages)
            {
                Console.WriteLine($"Message: {message}");
            }
        }
        public static void Run()
        {
            Console.WriteLine("Enter your own script");
            var script     = Console.ReadLine();
            var easyScript = EasyScript <object> .Go(script);

            Console.WriteLine($"Summary: {easyScript.Summary}");
            Console.WriteLine($"Runtime exception: {easyScript.RuntimeException}");
            Console.WriteLine($"Return data: {easyScript.ScriptResults}");
        }
Exemplo n.º 9
0
        public void Go_Globals_CanWriteGlobalProperty()
        {
            var globals = new Globals()
            {
                C = 1
            };
            var script     = "C = 9";
            var easyScript = EasyScript <int> .Go(script, globals);

            Assert.Equal(
                expected: 9,
                actual: globals.C);
        }
Exemplo n.º 10
0
        public void Go_Globals_CanReadGlobalProperty()
        {
            var globals = new Globals()
            {
                C = 1
            };
            var script     = "C + 1";
            var easyScript = EasyScript <int> .Go(script, globals);

            Assert.Equal(
                expected: globals.C + 1,
                actual: easyScript.ScriptResults);
        }
Exemplo n.º 11
0
        public void Go_PoorScript_OneCompilationMessage()
        {
            var script = string.Join(
                separator: Environment.NewLine,
                "int Double(int x)      ",
                "{                      ",
                "    return 0;          ",
                "    return x * 2;      ",
                "}                      ");

            var easyScript = EasyScript <object> .Go(script);

            Assert.Single(easyScript.CompilationOutput.Messages);
        }
Exemplo n.º 12
0
        public static void Run()
        {
            var script = string.Join(
                separator: Environment.NewLine,
                "Console.WriteLine($\"Script: Global variable Counter = {Counter}\");",
                "Counter *= 2;",
                "Console.WriteLine($\"Script: Global variable Counter = {Counter}\");");

            globals.Counter = 999;

            EasyScript <object> .Go(script, globals);

            Console.WriteLine($"Host: Counter = {globals.Counter}");
        }
Exemplo n.º 13
0
        public void Go_PoorScript_OneCompilationWarning()
        {
            var script = string.Join(
                separator: Environment.NewLine,
                "int Double(int x)      ",
                "{                      ",
                "    return 0;          ",
                "    return x * 2;      ",
                "}                      ");

            var easyScript = EasyScript <object> .Go(script);

            Assert.Equal(
                expected: 1,
                actual: easyScript.CompilationOutput.WarningCount);
        }
Exemplo n.º 14
0
 public static void Run()
 {
     EasyScript <object> .Go("Console.WriteLine(\"Hello world, from the script!\");");
 }
Exemplo n.º 15
0
        public void Go_BlankScript_NoCompilationMessages()
        {
            var easyScript = EasyScript <object> .Go("");

            Assert.Empty(easyScript.CompilationOutput.Messages);
        }
Exemplo n.º 16
0
        public void Go_BlankScript_AllOk()
        {
            var easyScript = EasyScript <object> .Go("");

            Assert.True(easyScript.AllOk);
        }
Exemplo n.º 17
0
        public void Go_BlankScript_NoRuntimeException()
        {
            var easyScript = EasyScript <object> .Go("");

            Assert.Null(easyScript.RuntimeException);
        }
Exemplo n.º 18
0
        public static void Run()
        {
            var easyScript = EasyScript <string> .Go("return \"I am a message from the script!\";");

            Console.WriteLine(easyScript.ScriptResults);
        }
Exemplo n.º 19
0
        public void Go_BadScript_OneCompilationMessage()
        {
            var easyScript = EasyScript <object> .Go("int x = unknown_variable;");

            Assert.Single(easyScript.CompilationOutput.Messages);
        }