Ejemplo n.º 1
0
        protected void TestItOld(string sbCode, string expectedCode, Func <string, string> extractCodeFunc, bool doOptimization = false)
        {
            sbCode = Regex.Replace(sbCode, @"[ \r\n\t]*'PRAGMA", "'PRAGMA");
            using (MemoryStream fs = new MemoryStream(Encoding.ASCII.GetBytes(sbCode)))
                using (MemoryStream ofs = new MemoryStream())
                {
                    List <String> errors = new List <String>();

                    EV3BasicCompiler.Compiler c = new EV3BasicCompiler.Compiler();
                    c.Compile(fs, ofs, errors);
                    string code = Encoding.ASCII.GetString(ofs.ToArray());

                    Console.WriteLine("======> ERRORS <======");
                    foreach (string error in 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 <======");

                    CleanupCode(extractedCode).Should().Be(CleanupCode(expectedCode));
                    errors.Should().BeEmpty();
                }
        }
Ejemplo n.º 2
0
        private string CompileOld(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open))
                using (MemoryStream ofs = new MemoryStream())
                {
                    List <String> errors = new List <String>();

                    EV3BasicCompiler.Compiler c = new EV3BasicCompiler.Compiler();
                    c.Compile(fs, ofs, errors);

                    errors.Should().BeEmpty();

                    return(Encoding.ASCII.GetString(ofs.ToArray()));
                }
        }