Esempio n. 1
0
        void Test(int testNum, string exprToParse, int terminatingChar = -1)
        {
            ++_testsRun;
            var testName = string.Format("results-test-{0}.txt", testNum);

            using (var tw = File.CreateText(_testDir + testName)) {
                string tc = terminatingChar >= 0 ? ((char)terminatingChar).ToString() : "";
                tw.WriteLine("------ Test: {0} ------\t{1}\t{2}", testNum, tc, exprToParse.Replace("\n", "\r\n"));
                tw.WriteLine();
                var utf8Stream = CodePointStream.FromString(exprToParse);
                var scanner    = new ScanIt(utf8Stream, testName, tw);
                var parser     = new ExpressionParser(scanner, new NotMuchOfASymbolTable());
                var result     = terminatingChar >= 0 ?
                                 parser.TryParse(new CodePoint((byte)terminatingChar)) :
                                 parser.TryParse();
                scanner.Message("Parse End");
                tw.WriteLine();
                result.Dump(tw);
                tw.WriteLine();
            }

            using (var tr = new StreamReader(File.OpenRead(_testDir + testName))) {
                var trBytes = tr.ReadToEnd();
                System.Console.WriteLine();
                System.Console.WriteLine();
                System.Console.WriteLine(trBytes);
                StreamReader mr = null;
                try {
                    mr = new StreamReader(File.OpenRead(_masterDir + testName));
                    using ( mr ) {
                        var mrBytes = mr.ReadToEnd();
                        int len     = mrBytes.Length;
                        if (len != trBytes.Length)
                        {
                            System.Console.WriteLine("Test {0} FAILURE: lengths differ!!!!", testNum);
                            return;
                        }
                        for (int i = 0; i < len; i++)
                        {
                            if (trBytes [i] != mrBytes [i])
                            {
                                System.Console.WriteLine("Test {0} FAILURE: bytes differ!!!!", testNum);
                                return;
                            }
                        }
                    }
                } catch (System.Exception) {
                    System.Console.WriteLine("Test {0}: No Master!!!", testNum);
                    return;
                }
            }

            System.Console.WriteLine("Test {0}: SUCCESS!!", testNum);
            ++_testsPassed;
        }
Esempio n. 2
0
        void Test(int testNum, string exprToParse, int terminatingChar = -1)
        {
            ++_testsRun;
            var testName = string.Format("results-test-{0}.txt", testNum);

            using (var tw = File.CreateText(_testDir + testName)) {
                string tc = terminatingChar >= 0 ? ((char)terminatingChar).ToString() : "";
                tw.WriteLine("------ Test: {0} ------\t{1}\t{2}", testNum, tc, exprToParse.Replace("\n", "\r\n"));
                tw.WriteLine();
                var utf8Stream  = CodePointStream.FromString(exprToParse);
                var scanner     = new ScanIt(utf8Stream, testName, tw);
                var symbolTable = new SimpleSymbolTable();
                var parser      = new StatementParser(scanner, symbolTable);
                var result      = parser.TryParse();
                scanner.Message("Parse End");
                tw.WriteLine();
                result.Dump(tw);
                tw.WriteLine();
                if (!result.HasErrors)
                {
                    using (var context = new CodeGenContext(tw)) {
                        try
                        {
                            Dump.CommentFormat();
                            symbolTable.GenerateVariables(context);
                            //result.Result.PrettyPrint ();
                            result.Result.GenerateCodeWithPrettyPrint(context);
                        } catch (Exception ex) {
                            System.Console.WriteLine(ex);
                        }
                    }
                }
                tw.WriteLine();
            }

            using (var tr = new StreamReader(File.OpenRead(_testDir + testName))) {
                var trBytes = tr.ReadToEnd();
                System.Console.WriteLine();
                System.Console.WriteLine();
                System.Console.WriteLine(trBytes);
                StreamReader mr = null;
                try {
                    mr = new StreamReader(File.OpenRead(_masterDir + testName));
                    using ( mr ) {
                        var mrBytes = mr.ReadToEnd();
                        int len     = mrBytes.Length;
                        if (len != trBytes.Length)
                        {
                            System.Console.WriteLine("Test {0} FAILURE: lengths differ!!!!", testNum);
                            return;
                        }
                        for (int i = 0; i < len; i++)
                        {
                            if (trBytes [i] != mrBytes [i])
                            {
                                System.Console.WriteLine("Test {0} FAILURE: bytes differ!!!!", testNum);
                                return;
                            }
                        }
                    }
                } catch (System.Exception) {
                    System.Console.WriteLine("Test {0}: No Master!!!", testNum);
                    return;
                }
            }

            System.Console.WriteLine("Test {0}: SUCCESS!!", testNum);
            ++_testsPassed;
        }