コード例 #1
0
        public void Test()
        {
            string path = Path.GetTempFileName();

            try
            {
                Compiler compiler = new();

                // Define symbols used in source to prevent errors
                compiler.RegisterFunction("Color", 1, 2);
                compiler.RegisterFunction("ClearScreen", 0, 0);
                compiler.RegisterFunction("Print", 0, 99);
                compiler.RegisterFunction("PrintLine", 0, 99);
                compiler.RegisterVariable("White", new Variable());
                compiler.RegisterVariable("Blue", new Variable());
                Assert.IsTrue(compiler.CompileSource(Source, out CompiledProgram? program));

                program !.Save(path);
                program = CompiledProgram.FromFile(path);

                Runtime runtime = new(program !);

                Assert.AreEqual(5000, runtime.Execute());
            }
            finally
            {
                File.Delete(path);
            }
        }