Пример #1
0
        public Task CallSubrutineAsync(string name)
        {
            if (subrutineTask != null)
            {
                Assert.Fail("Cannot run more subrutines in parallel.");
            }

            subrutineTask = Task.Run(() => runtime.CallSubrutine(name));

            return(subrutineTask);
        }
Пример #2
0
        public Task CallSubrutineAsync(string name)
        {
            if (subrutineTask != null)
            {
                Assert.Fail("Cannot run more subrutines in parallel.");
            }

            ScriptCancellation = new CancellationTokenSource();

            subrutineTask = Task.Run(() => runtime.CallSubrutine(name));

            return(subrutineTask);
        }
Пример #3
0
        public static InjectionValue Execute(string subName, string codeBlock)
        {
            var runtime = new InjectionRuntime();

            var parser = new Parser();

            runtime.Load(parser.ParseFile(codeBlock, new FailTestErrorListener()));

            return(runtime.CallSubrutine(subName));
        }
Пример #4
0
        public static Task <InjectionValue> RunSubrutine(string subrutineName, Func <CancellationToken?> retrieveCancellationToken, string file)
        {
            return(Task.Run(() =>
            {
                var runtime = new InjectionRuntime(retrieveCancellationToken);
                var parser = new Parser();
                runtime.Load(parser.ParseFile(file, new FailTestErrorListener()));

                return runtime.CallSubrutine(subrutineName);
            }));
        }
Пример #5
0
        public static void TestSubrutine(int expected, string subrutineName, string file)
        {
            var runtime = new InjectionRuntime();
            var parser  = new Parser();

            runtime.Load(parser.ParseFile(file, new FailTestErrorListener()));

            var actual = runtime.CallSubrutine(subrutineName);

            Assert.AreEqual(InjectionValueKind.Integer, actual.Kind, file);
            Assert.AreEqual(expected, actual.Integer, file);
        }
Пример #6
0
        public static void TestSubrutine(string expected, string codeBlock, NativeSubrutineDefinition[] natives = null)
        {
            var subrutine = $"sub test()\r\n{codeBlock}\r\n end sub";
            var runtime   = new InjectionRuntime();

            if (natives != null)
            {
                runtime.Metadata.Add(natives);
            }

            var parser = new Parser();

            runtime.Load(parser.ParseFile(subrutine, new FailTestErrorListener()));

            var actual = runtime.CallSubrutine("test");

            Assert.AreEqual(InjectionValueKind.String, actual.Kind, codeBlock);
            Assert.AreEqual(expected, actual.String, codeBlock);
        }
Пример #7
0
        public static void TestSubrutine(string codeBlock, NativeSubrutineDefinition[] natives = null, NativeSubrutineDefinition[] intrinsicVariables = null)
        {
            var subrutine = $"sub test()\r\n{codeBlock}\r\n end sub";
            var runtime   = new InjectionRuntime();

            if (natives != null)
            {
                runtime.Metadata.Add(natives);
            }
            if (intrinsicVariables != null)
            {
                runtime.Metadata.AddIntrinsicVariables(intrinsicVariables);
            }

            var parser = new Parser();

            runtime.Load(parser.ParseFile(subrutine, new FailTestErrorListener()));

            runtime.CallSubrutine("test");
        }