Beispiel #1
0
        protected void TestCompileFailure(string sbCode, bool doOptimization = false)
        {
            sbCode = AttachOptimizationPragma(sbCode, doOptimization);

            using (EV3Compiler compiler = new EV3Compiler())
                using (StringReader stringReader = new StringReader(sbCode))
                    using (StringWriter writer = new StringWriter())
                    {
                        compiler.Compile(stringReader, writer);

                        Console.WriteLine(compiler.Dump());

                        compiler.Errors.Should().NotBeEmpty();
                    }
        }
Beispiel #2
0
        private string Compile(string fileName, bool withDump)
        {
            using (EV3Compiler compiler = new EV3Compiler())
                using (StreamReader streamReader = new StreamReader(fileName))
                    using (StringWriter writer = new StringWriter())
                    {
                        compiler.Compile(streamReader, writer);

                        if (withDump)
                        {
                            Console.WriteLine(compiler.Dump());
                        }

                        compiler.Errors.Should().BeEmpty();

                        return(writer.ToString());
                    }
        }
Beispiel #3
0
        protected void TestCompileFailure(string sbCode, string message, int line, int column, bool doOptimization = false)
        {
            sbCode = AttachOptimizationPragma(sbCode, doOptimization);

            using (EV3Compiler compiler = new EV3Compiler())
                using (StringReader stringReader = new StringReader(sbCode))
                    using (StringWriter writer = new StringWriter())
                    {
                        compiler.Compile(stringReader, writer);

                        Console.WriteLine(compiler.Dump());

                        Console.WriteLine("======> INPUT CODE <======");
                        Console.WriteLine(sbCode);
                        Console.WriteLine("======> END CODE <======");

                        compiler.Errors.Should().Contain(e => e.Message == message && e.Line == line && e.Column == column);
                    }
        }
Beispiel #4
0
        static void TestEV3Compiler()
        {
            String lmsFilename = Path.Combine(TEST_OUTPUT, Path.GetFileNameWithoutExtension(SOURCE_FILENAME)) + ".lms2";

            using (EV3Compiler compiler = new EV3Compiler())
                using (StreamReader reader = new StreamReader(SOURCE_FILENAME))
                    using (StreamWriter writer = new StreamWriter(lmsFilename))
                    {
                        compiler.Compile(reader, writer);

                        compiler.Errors.ForEach(e => Console.WriteLine($"ERROR: {e}"));

                        Console.Write(compiler.Dump());

                        writer.WriteLine();
                        writer.WriteLine("---------------------------------------------------");
                        writer.WriteLine();
                        writer.Write(compiler.Dump());
                    }
        }
        private string Compile(string fileName, bool withDump, bool doOptimization)
        {
            using (EV3Compiler compiler = new EV3Compiler())
                using (StringWriter writer = new StringWriter())
                {
                    string sbCode = File.ReadAllText(fileName);
                    sbCode = AttachOptimizationPragma(sbCode, doOptimization);
                    using (StringReader stringReader = new StringReader(sbCode))
                    {
                        compiler.Compile(stringReader, writer);

                        if (withDump)
                        {
                            Console.WriteLine(compiler.Dump());
                        }

                        compiler.Errors.Should().BeEmpty();

                        return(writer.ToString());
                    }
                }
        }
Beispiel #6
0
        protected void TestIt(string sbCode, string expectedCode, Func <string, string> extractCodeFunc, bool doOptimization = false)
        {
            sbCode = AttachOptimizationPragma(sbCode, doOptimization);

            using (EV3Compiler compiler = new EV3Compiler())
                using (StringReader stringReader = new StringReader(sbCode))
                    using (StringWriter writer = new StringWriter())
                    {
                        compiler.Compile(stringReader, writer);

                        string code = writer.ToString();

                        Console.WriteLine("======> ERRORS <======");
                        foreach (Error error in compiler.Errors)
                        {
                            Console.WriteLine(error);
                        }

                        string extractedCode = extractCodeFunc(code);
                        if (!string.IsNullOrWhiteSpace(expectedCode))
                        {
                            extractedCode = NormalizeReferences(NormalizeLabels(extractedCode));
                            expectedCode  = NormalizeReferences(NormalizeLabels(expectedCode));
                        }

                        Console.WriteLine("======> EXTRACTED/EXPECTED CODE <======");
                        DumpCodeSideBySide(extractedCode, expectedCode);
                        Console.WriteLine("======> FULL CODE <======");
                        Console.WriteLine(code);
                        Console.WriteLine("======> END CODE <======");

                        Console.WriteLine(compiler.Dump());

                        CleanupCode(extractedCode).Should().Be(CleanupCode(expectedCode));
                        compiler.Errors.Should().BeEmpty();
                    }
        }