public static void CheckWithReplaceResultFile(string result, string testName) { string path = Path.Combine("Compiler", "Preprocessor", "ReplaceResultFiles", testName + ".txt"); string expected = System.IO.File.ReadAllText(PlatformUtils.GetPathForProjectFile(path)); TypeCobol.Test.TestUtils.compareLines(path, result, expected); }
public static void Check_ASCIICobolFile_LinuxReferenceFormat() { DocumentFormat docFormat = DocumentFormat.RDZReferenceFormat; SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(SampleFolder), false, null, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); DummyTextSourceListener textSourceListener = new DummyTextSourceListener(); CobolFile cobolFile; if (fileProvider.TryGetFile("AsciiLinuxFormat.14", out cobolFile)) { // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("AsciiLinuxFormat.14", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); // Send all text lines in one batch to the test observer textDocument.TextChanged += textSourceListener.OnTextChanged; textDocument.StartSendingChangeEvents(); } TextChangeMap tce1 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.First <TextChange>(), docFormat.ColumnsLayout); if (tce1.LineIndex != 0 || tce1.Type != TextChangeType.LineInserted || tce1.NewLineMap.SequenceNumberText != null || tce1.NewLineMap.IndicatorChar != ' ' || tce1.NewLineMap.SourceText != null || tce1.NewLineMap.CommentText != null) { throw new Exception("Error reading line 1 of the ASCII Linux text source (reference format)"); } TextChangeMap tce2 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[5], docFormat.ColumnsLayout); if (tce2.LineIndex != 5 || tce2.Type != TextChangeType.LineInserted || tce2.NewLineMap.SequenceNumberText != " " || tce2.NewLineMap.IndicatorChar != ' ' || tce2.NewLineMap.SourceText != "COPY \"copy.inc\"" || tce2.NewLineMap.CommentText != null) { throw new Exception("Error reading line 6 of the ASCII Linux text source (reference format)"); } TextChangeMap tce3 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[7], docFormat.ColumnsLayout); if (tce3.LineIndex != 7 || tce3.Type != TextChangeType.LineInserted || tce3.NewLineMap.SequenceNumberText != " " || tce3.NewLineMap.IndicatorChar != ' ' || tce3.NewLineMap.SourceText != " LEADING ==NORM== BY ==SECOND==." || tce3.NewLineMap.CommentText != null) { throw new Exception("Error reading line 8 of the ASCII Linux text source (reference format)"); } TextChangeMap tce4 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.Last <TextChange>(), docFormat.ColumnsLayout); if (tce4.LineIndex != 13 || tce4.Type != TextChangeType.LineInserted || tce4.NewLineMap.SequenceNumberText != " " || tce4.NewLineMap.IndicatorChar != ' ' || tce4.NewLineMap.SourceText != " STOP RUN." || tce4.NewLineMap.CommentText != null) { throw new Exception("Error reading line 14 of the ASCII Linux text source (reference format)"); } }
public void IncrementalPerformance() { // Sample program properties string folder = "Parser" + Path.DirectorySeparatorChar + "Samples"; string textName = "BigBatch"; DocumentFormat documentFormat = DocumentFormat.RDZReferenceFormat; // Create a FileCompiler for this program DirectoryInfo localDirectory = new DirectoryInfo(PlatformUtils.GetPathForProjectFile(folder)); if (!localDirectory.Exists) { throw new Exception(String.Format("Directory : {0} does not exist", localDirectory.FullName)); } CompilationProject project = new CompilationProject("test", localDirectory.FullName, new string[] { ".cbl", ".cpy" }, documentFormat.Encoding, documentFormat.EndOfLineDelimiter, documentFormat.FixedLineLength, documentFormat.ColumnsLayout, new TypeCobolOptions()); FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, documentFormat.ColumnsLayout, new TypeCobolOptions(), null, false, project); //Make an incremental change to the source code TestUtils.CompilationStats stats = new TestUtils.CompilationStats(); ExecuteInceremental(compiler, stats); // Display a performance report TestUtils.CreateRunReport(TestUtils.GetReportDirectoryPath(), compiler.CobolFile.Name + "-Incremental", stats, compiler.CompilationResultsForProgram); }
public static void Check_ASCIICobolFile_ReferenceFormat() { DocumentFormat docFormat = DocumentFormat.RDZReferenceFormat; SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(SampleFolder), false, new string[] { ".cpy" }, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); DummyTextSourceListener textSourceListener = new DummyTextSourceListener(); CobolFile cobolFile; if (fileProvider.TryGetFile("AsciiRefFormat", out cobolFile)) { // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("MSVCOUT.cpy", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); // Send all text lines in one batch to the test observer textDocument.TextChanged += textSourceListener.OnTextChanged; textDocument.StartSendingChangeEvents(); } TextChangeMap tce1 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.First <TextChange>(), docFormat.ColumnsLayout); if (tce1.LineIndex != 0 || tce1.Type != TextChangeType.LineInserted || tce1.NewLineMap.SequenceNumberText != "000100" || tce1.NewLineMap.IndicatorChar != '*' || tce1.NewLineMap.SourceText != "----------------------------------------------------------------*" || tce1.NewLineMap.CommentText != "00010000") { throw new Exception("Error reading line 1 of the ASCII text source (reference format)"); } TextChangeMap tce2 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[114], docFormat.ColumnsLayout); if (tce2.LineIndex != 114 || tce2.Type != TextChangeType.LineInserted || tce2.NewLineMap.SequenceNumberText != "001780" || tce2.NewLineMap.IndicatorChar != ' ' || tce2.NewLineMap.SourceText != " 20 FILLER PIC X(020). " || tce2.NewLineMap.CommentText != "01550001") { throw new Exception("Error reading line 115 of the ASCII text source (reference format)"); } TextChangeMap tce3 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[132], docFormat.ColumnsLayout); if (tce3.LineIndex != 132 || tce3.Type != TextChangeType.LineInserted || tce3.NewLineMap.SequenceNumberText != "002030" || tce3.NewLineMap.IndicatorChar != ' ' || tce3.NewLineMap.SourceText != " 15 :MSVCOUT:-DataElm OCCURS 10 TIMES " || tce3.NewLineMap.CommentText != "01800001") { throw new Exception("Error reading line 132 of the ASCII text source (reference format)"); } TextChangeMap tce4 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.Last <TextChange>(), docFormat.ColumnsLayout); if (tce4.LineIndex != 147 || tce4.Type != TextChangeType.LineInserted || tce4.NewLineMap.SequenceNumberText != "002240" || tce4.NewLineMap.IndicatorChar != ' ' || tce4.NewLineMap.SourceText != " 05 PIC X(08) VALUE '/MSVCOUT'. " || tce4.NewLineMap.CommentText != "02010001") { throw new Exception("Error reading line 224 of the ASCII text source (reference format)"); } }
public static void Check_EBCDICCobolFile() { DocumentFormat docFormat = DocumentFormat.ZOsReferenceFormat; SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(SampleFolder), false, new string[] { ".txt" }, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); DummyTextSourceListener textSourceListener = new DummyTextSourceListener(); CobolFile cobolFile; if (fileProvider.TryGetFile("EbcdicRefFormat", out cobolFile)) { // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("EbcdicRefFormat.TXT", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); // Send all text lines in one batch to the test observer textDocument.TextChanged += textSourceListener.OnTextChanged; textDocument.StartSendingChangeEvents(); } TextChangeMap tce1 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.First <TextChange>(), docFormat.ColumnsLayout); if (tce1.LineIndex != 0 || tce1.Type != TextChangeType.LineInserted || tce1.NewLineMap.SequenceNumberText != "000010" || tce1.NewLineMap.IndicatorChar != ' ' || tce1.NewLineMap.SourceText != "CBL DATA(31) " || tce1.NewLineMap.CommentText != " ") { throw new Exception("Error reading line 1 of the EBCDIC text source"); } TextChangeMap tce2 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[9], docFormat.ColumnsLayout); if (tce2.LineIndex != 9 || tce2.Type != TextChangeType.LineInserted || tce2.NewLineMap.SequenceNumberText != "000200" || tce2.NewLineMap.IndicatorChar != '*' || tce2.NewLineMap.SourceText != "REMARKS. COPY=(YACMERM YACMCTL). " || tce2.NewLineMap.CommentText != "00600000") { throw new Exception("Error reading line 10 of the EBCDIC text source"); } TextChangeMap tce3 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[31], docFormat.ColumnsLayout); if (tce3.LineIndex != 31 || tce3.Type != TextChangeType.LineInserted || tce3.NewLineMap.SequenceNumberText != "000420" || tce3.NewLineMap.IndicatorChar != ' ' || tce3.NewLineMap.SourceText != " 05 FILLER PIC XXX VALUE ' ; '. " || tce3.NewLineMap.CommentText != "00860000") { throw new Exception("Error reading line 32 of the EBCDIC text source"); } TextChangeMap tce4 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.Last <TextChange>(), docFormat.ColumnsLayout); if (tce4.LineIndex != 223 || tce4.Type != TextChangeType.LineInserted || tce4.NewLineMap.SequenceNumberText != "002340" || tce4.NewLineMap.IndicatorChar != '*' || tce4.NewLineMap.SourceText != " CALL 'ILBOABN0' USING LCP-ABND-CODE. " || tce4.NewLineMap.CommentText != "02740000") { throw new Exception("Error reading line 224 of the EBCDIC text source"); } }
public static void CheckWithDirectiveResultFile(string result, string testName) { string path = Path.Combine(Root, "DirectiveResultFiles", testName + ".txt"); string expected = System.IO.File.ReadAllText(PlatformUtils.GetPathForProjectFile(path)); TypeCobol.Test.TestUtils.compareLines(path, result, expected, PlatformUtils.GetPathForProjectFile(path)); }
public static CompilationUnit ParseCobolFile(string textName, DocumentFormat documentFormat = null, string folder = null, ExecutionStep execToStep = ExecutionStep.SemanticCheck) { if (folder == null) { folder = "Parser" + Path.DirectorySeparatorChar + "CodeElements"; } DirectoryInfo localDirectory = new DirectoryInfo(PlatformUtils.GetPathForProjectFile(folder)); if (!localDirectory.Exists) { throw new Exception(String.Format("Directory : {0} does not exist", localDirectory.FullName)); } if (documentFormat == null) { documentFormat = DocumentFormat.RDZReferenceFormat; } TypeCobolOptions options = new TypeCobolOptions { ExecToStep = execToStep }; //Create CompilerOptions. ExecToStep / AutoRemarks / HaltOnMissingCopy have to be set here. CompilationProject project = new CompilationProject("test", //First use *.cpy as tests will use file WITH extension for program but without extension for copy inside programs => small perf gain localDirectory.FullName, new string[] { ".cpy", ".cbl" }, documentFormat.Encoding, documentFormat.EndOfLineDelimiter, documentFormat.FixedLineLength, documentFormat.ColumnsLayout, options); FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, documentFormat.ColumnsLayout, options, null, false, project); compiler.CompileOnce(); return(compiler.CompilationResultsForProgram); }
public static void ParseGenerateCompare(string path, List <Skeleton> skeletons, DocumentFormat format, string typeCobolVersion, bool autoRemarks = false, IList <string> copies = null) { var document = Parser.Parse(Path.Combine(ROOT, INPUT, path), format, autoRemarks, copies); var columns = document.Results.ProgramClassDocumentSnapshot.TextSourceInfo.ColumnsLayout; var writer = new StringWriter(); // write parsing errors WriteErrors(writer, document.Results.AllDiagnostics(), columns); // write generated code var generatedCobolStringBuilder = new StringBuilder(); var codegen = new Generators.DefaultGenerator(document.Results, generatedCobolStringBuilder, skeletons, typeCobolVersion); try { codegen.Generate(document.Results, columns); if (codegen.Diagnostics != null) { WriteErrors(writer, codegen.Diagnostics, columns); } } finally { writer.Write(generatedCobolStringBuilder); // flush writer.Close(); } // compare with expected result string expected = File.ReadAllText(Path.Combine(ROOT, OUTPUT, path), format.Encoding); TypeCobol.Test.TestUtils.compareLines(path, writer.ToString(), expected, PlatformUtils.GetPathForProjectFile(Path.Combine(ROOT, OUTPUT, path), "Codegen\\Test")); }
public static void CheckAllFilesForExceptions() { CompilationProject project = new CompilationProject("test", PlatformUtils.GetPathForProjectFile(@"Compiler\Scanner\Samples"), new string[] { ".txt" }, IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147), EndOfLineDelimiter.FixedLengthLines, 80, ColumnsLayout.CobolReferenceFormat, new TypeCobolOptions()); //int filesCount = 0; //int linesCount = 0; //Stopwatch chrono = new Stopwatch(); foreach (string fileName in PlatformUtils.ListFilesInSubdirectory(@"Compiler\Scanner\Samples")) { string textName = Path.GetFileNameWithoutExtension(fileName); // Initialize a CompilationDocument FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, ColumnsLayout.CobolReferenceFormat, new TypeCobolOptions(), null, true, project); // Start compilation try { //chrono.Start(); compiler.CompileOnce(); //chrono.Stop(); } catch (Exception e) { throw new Exception("Error while scanning file " + fileName, e); } // Stats //filesCount++; //linesCount += compiler.CompilationResultsForCopy.TokensDocumentSnapshot.Lines.Count; //string result = compiler.CompilationResultsForCopy.TokensDocumentSnapshot.GetDebugString(); } // throw new Exception("Test OK for " + filesCount + " files and " + linesCount + " lines : " + chrono.ElapsedMilliseconds + " ms"); }
/*TODO#249 * private static void Dump(StringBuilder str, IList<Function> functions) { * if (functions == null || functions.Count < 1) return; * str.AppendLine("FUNCTIONS:"); * foreach(var function in functions) { * str.Append(" £ ").Append(function.Name).Append(':').Append(function.Visibility); * str.AppendLine(); * foreach(var parameter in function.Profile.InputParameters) { * str.Append(" in: "); * Dump(str, parameter); * str.AppendLine(); * } * foreach(var parameter in function.Profile.OutputParameters) { * str.Append(" out: "); * Dump(str, parameter); * str.AppendLine(); * } * foreach(var parameter in function.Profile.InoutParameters) { * str.Append(" io: "); * Dump(str, parameter); * str.AppendLine(); * } * if (function.Profile.ReturningParameter != null) { * str.Append(" return: "); * Dump(str, function.Profile.ReturningParameter); * str.AppendLine(); * } * } * } * private static void Dump(StringBuilder str, ParameterDescription parameter) { * str.Append(parameter.Name).Append(':'); * var entry = (ParameterDescriptionEntry)parameter.CodeElement; * if (entry.CustomType != null) str.Append(entry.CustomType); * else * if (entry.Picture != null) str.Append(entry.Picture); * else str.Append("?"); * } * // [/TYPECOBOL] * * private static void Dump(StringBuilder str, Dictionary<string, List<Named>> map) { * foreach(string key in map.Keys) { * foreach (var data in map[key]) { * Dump(str, data, 1); * str.Append("\n"); * } * } * } * * private static StringBuilder Dump(StringBuilder str, Named data, int indent = 0) * { * DumpIndent(str, indent); * str.Append(data.Name); * return str; * } * * private static StringBuilder DumpIndent(StringBuilder str, int indent) * { * for (int c=0; c<indent; c++) str.Append(" "); * return str; * } */ public static void CheckWithResultFile(string result, string testName) { using (StreamReader reader = new StreamReader(PlatformUtils.GetStreamForProjectFile(@"Parser\CodeElements\" + testName + ".txt"))) { CheckWithResultReader(testName, result, reader, PlatformUtils.GetPathForProjectFile(@"Parser\CodeElements\" + testName + ".txt")); }; }
public static void CheckWithResultFile(string result, string testName) { string expectedResult; using (StreamReader reader = new StreamReader(PlatformUtils.GetStreamForProjectFile(@"Parser\Scanner\ResultFiles\" + testName + ".txt"))) { expectedResult = reader.ReadToEnd(); } TestUtils.compareLines(testName, result, expectedResult, PlatformUtils.GetPathForProjectFile(@"Parser\Scanner\ResultFiles\" + testName + ".txt")); }
public void CheckPerformance() { // Sample program properties string folder = "Parser" + Path.DirectorySeparatorChar + "Samples"; string textName = "BigBatch"; DocumentFormat documentFormat = DocumentFormat.RDZReferenceFormat; // Create a FileCompiler for this program DirectoryInfo localDirectory = new DirectoryInfo(PlatformUtils.GetPathForProjectFile(folder)); if (!localDirectory.Exists) { throw new Exception(String.Format("Directory : {0} does not exist", localDirectory.FullName)); } CompilationProject project = new CompilationProject("test", localDirectory.FullName, new string[] { ".cbl", ".cpy" }, documentFormat.Encoding, documentFormat.EndOfLineDelimiter, documentFormat.FixedLineLength, documentFormat.ColumnsLayout, new TypeCobolOptions()); FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, documentFormat.ColumnsLayout, new TypeCobolOptions(), null, false, project); // Execute a first (complete) compilation compiler.CompileOnce(); // Append one line in the middle of the program ITextLine newLine = new TextLineSnapshot(9211, "094215D DISPLAY '-ICLAUA = ' ICLAUA. 0000000", null); TextChangedEvent textChangedEvent = new TextChangedEvent(); textChangedEvent.TextChanges.Add(new TextChange(TextChangeType.LineInserted, 9211, newLine)); compiler.CompilationResultsForProgram.UpdateTextLines(textChangedEvent); // Execute a second (incremental) compilation compiler.CompileOnce(); // Display a performance report StringBuilder report = new StringBuilder(); report.AppendLine("Program properties :"); report.AppendLine("- " + compiler.CompilationResultsForProgram.CobolTextLines.Count + " lines"); report.AppendLine("- " + compiler.CompilationResultsForProgram.CodeElementsDocumentSnapshot.CodeElements.Count() + " code elements"); report.AppendLine("First compilation performance"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForText.FirstCompilationTime + " ms : text update"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForScanner.FirstCompilationTime + " ms : scanner"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForPreprocessor.FirstCompilationTime + " ms : preprocessor"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForCodeElementsParser.FirstCompilationTime + " ms : code elements parser"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForTemporarySemantic.FirstCompilationTime + " ms : temporary semantic class parser"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForProgramCrossCheck.FirstCompilationTime + " ms : cross check class parser"); report.AppendLine("Incremental compilation performance"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForText.LastRefreshTime + " ms : text update"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForScanner.LastRefreshTime + " ms : scanner"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForPreprocessor.LastRefreshTime + " ms : preprocessor"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForCodeElementsParser.LastRefreshTime + " ms : code elements parser"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForTemporarySemantic.LastRefreshTime + " ms : temporary semantic class parser"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForProgramCrossCheck.LastRefreshTime + " ms : cross check class parser"); Console.WriteLine(report.ToString()); }
static PreprocessorUtils() { DirectivesProject = new CompilationProject("directives", PlatformUtils.GetPathForProjectFile(Root + Path.DirectorySeparatorChar + "DirectiveTestFiles"), new string[] { ".cbl", ".cpy" }, Encoding.Unicode, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.CobolReferenceFormat, CompilerOptions); CopyProject = new CompilationProject("copy", PlatformUtils.GetPathForProjectFile(Root + Path.DirectorySeparatorChar + "CopyTestFiles"), new string[] { ".cbl", ".cpy" }, Encoding.Unicode, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.CobolReferenceFormat, CompilerOptions); ReplaceProject = new CompilationProject("replace", PlatformUtils.GetPathForProjectFile(Root + Path.DirectorySeparatorChar + "ReplaceTestFiles"), new string[] { ".cbl", ".cpy" }, Encoding.Unicode, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.CobolReferenceFormat, CompilerOptions); }
public static CompilationDocument ScanCobolFile(string relativePath, string textName, DocumentFormat documentFormat) { DirectoryInfo localDirectory = new DirectoryInfo(PlatformUtils.GetPathForProjectFile(relativePath)); if (!localDirectory.Exists) { throw new Exception(String.Format("Directory : {0} does not exist", relativePath)); } CompilationProject project = new CompilationProject("test", localDirectory.FullName, new string[] { ".cbl", ".cpy" }, documentFormat.Encoding, documentFormat.EndOfLineDelimiter, documentFormat.FixedLineLength, documentFormat.ColumnsLayout, new TypeCobolOptions()); FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, documentFormat.ColumnsLayout, new TypeCobolOptions(), null, true, project); compiler.CompileOnce(); return(compiler.CompilationResultsForCopy); }
public static void Check_UTF8File() { DocumentFormat docFormat = new DocumentFormat(Encoding.UTF8, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.FreeTextFormat); SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(SampleFolder), false, null, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); DummyTextSourceListener textSourceListener = new DummyTextSourceListener(); string filename = "UTF8Format.txt"; CobolFile cobolFile; if (fileProvider.TryGetFile(filename, out cobolFile)) { // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument(filename, docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); // Send all text lines in one batch to the test observer textDocument.TextChanged += textSourceListener.OnTextChanged; textDocument.StartSendingChangeEvents(); } TextChangeMap tce; tce = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.First <TextChange>(), docFormat.ColumnsLayout); CheckLine(filename, tce, 0, "english: hello, world"); tce = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[1], docFormat.ColumnsLayout); bool okay = false; try { CheckLine(filename, tce, 1, "français: salut, tout le monde"); } catch (Exception) { okay = true; } if (!okay) { throw new Exception("Exception should have been thrown!"); } CheckLine(filename, tce, 1, "arabic: مرحبا بالعالم"); tce = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[2], docFormat.ColumnsLayout); CheckLine(filename, tce, 2, "japanese: こんにちは世界"); }
public static void Check_EBCDICCobolFileWithUnsupportedChar() { DocumentFormat docFormat = DocumentFormat.ZOsReferenceFormat; SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(SampleFolder), false, new string[] { ".txt" }, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); bool exceptionWasThrownWithCorrectMessage = false; CobolFile cobolFile; if (fileProvider.TryGetFile("EbcdicRefFormatWithBadChars", out cobolFile)) { try { // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("EbcdicRefFormatWithBadChars.TXT", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); } catch (Exception e) { if (e.Message == "The character code 13 in source encoding IBM EBCDIC (France-Euro) found at position 3072 can not be safely converted to the internal Unicode representation : please replace it with the alphanumeric hexadecimal literal X'0D' in the source text") { exceptionWasThrownWithCorrectMessage = true; } } } if (!exceptionWasThrownWithCorrectMessage) { throw new Exception("Unsupported chars in fixed length EBCDIC source file were not correctly filtered"); } }
public static void Check_ReferenceFormatDocument() { DocumentFormat docFormat = DocumentFormat.RDZReferenceFormat; SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(@"Compiler\Text\Samples"), false, new string[] { ".cpy" }, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); CobolFile cobolFile; if (!fileProvider.TryGetFile("MSVCOUT", out cobolFile)) { throw new Exception("File MSVCOUT.cpy not found"); } // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("MSVCOUT.cpy", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); if (textDocument.CharAt(0) != '0') { throw new Exception("Character at position 0 should be 0"); } if (textDocument.CharAt(90) != 'M') { throw new Exception("Character at position 90 should be M"); } if (textDocument.CharAt(18345) != '/') { throw new Exception("Character at position 18345 should be /"); } if (textDocument.CharAt(18365) != '1') { throw new Exception("Character at position 18365 should be 1"); } if (textDocument.Chars.Skip(88).First() != 'M') { throw new Exception("Character enumerator after 88 iterations should return M"); } ReadOnlyTextLine line = (ReadOnlyTextLine)textDocument.GetLineByIndex(0); if (line.Length != 80 || line.LineIndex != 0 || line.StartOffset != 0 || line.Text != "000010*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- 00001001") { throw new Exception("Incorrect line at index 0"); } line = (ReadOnlyTextLine)textDocument.GetLineByIndex(1); if (line.Length != 80 || line.LineIndex != 1 || line.StartOffset != 82 || line.Text != "000020*-Maintenance frame - Created on 14 Oct 2013 at 17:27:08 00002001") { throw new Exception("Incorrect line at index 1"); } line = (ReadOnlyTextLine)textDocument.GetLineByIndex(223); if (line.Length != 80 || line.LineIndex != 223 || line.StartOffset != 18286 || line.Text != "002240 05 PIC X(08) VALUE '/MSVCOUT'. 02010001") { throw new Exception("Incorrect line at index 223"); } int indexOfCharInLine = -1; line = (ReadOnlyTextLine)textDocument.GetLineByOffset(12, out indexOfCharInLine); if (line.LineIndex != 0 || indexOfCharInLine != 12) { throw new Exception("Incorrect line at offset 12"); } line = (ReadOnlyTextLine)textDocument.GetLineByOffset(159, out indexOfCharInLine); if (line.LineIndex != 1 || indexOfCharInLine != 77) { throw new Exception("Incorrect line at offset 159"); } line = (ReadOnlyTextLine)textDocument.GetLineByOffset(17899, out indexOfCharInLine); if (line.LineIndex != 218 || indexOfCharInLine != 23) { throw new Exception("Incorrect line at offset 17899"); } if (textDocument.Length != 18366) { throw new Exception("Document should have length 18366"); } if (textDocument.LineCount != 224) { throw new Exception("Document should have 224 line count"); } if (textDocument.Lines.Count() != 224) { throw new Exception("Document should have 224 lines"); } }
public static void Check_FreeFormatDocument() { DocumentFormat docFormat = DocumentFormat.FreeTextFormat; SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(@"Compiler\Text\Samples"), false, new string[] { ".cpy" }, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); CobolFile cobolFile; if (!fileProvider.TryGetFile("MSVCINP free format", out cobolFile)) { throw new Exception("File MSVCINP free format.cpy not found"); } // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("MSVCINP free format.cpy", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); if (textDocument.CharAt(0) != '/') { throw new Exception("Character at position 0 should be 0"); } if (textDocument.CharAt(92) != 'a') { throw new Exception("Character at position 92 should be a"); } if (textDocument.CharAt(2582) != '/') { throw new Exception("Character at position 2582 should be /"); } if (textDocument.CharAt(2522) != ' ') { throw new Exception("Character at position 2522 should be space"); } if (textDocument.Chars.Skip(90).First() != 'a') { throw new Exception("Character enumerator after 90 iterations should return a"); } ReadOnlyTextLine line = (ReadOnlyTextLine)textDocument.GetLineByIndex(0); if (line.Length != 65 || line.LineIndex != 0 || line.StartOffset != 0 || line.Text != "/----------------------------------------------------------------") { throw new Exception("Incorrect line at index 0"); } line = (ReadOnlyTextLine)textDocument.GetLineByIndex(1); if (line.Length != 96 || line.LineIndex != 1 || line.StartOffset != 67 || line.Text != "* MSVCINP partie ALLER FIXE des MESSAGES échangés avec tout SERVICE APPLICATIF C14") { throw new Exception("Incorrect line at index 1"); } line = (ReadOnlyTextLine)textDocument.GetLineByIndex(36); if (line.Length != 66 || line.LineIndex != 36 || line.StartOffset != 2529 || line.Text != "d 05 PIC X(008) VALUE '/MSVCINP'. ") { throw new Exception("Incorrect line at index 36"); } int indexOfCharInLine = -1; line = (ReadOnlyTextLine)textDocument.GetLineByOffset(12, out indexOfCharInLine); if (line.LineIndex != 0 || indexOfCharInLine != 12) { throw new Exception("Incorrect line at offset 12"); } line = (ReadOnlyTextLine)textDocument.GetLineByOffset(881, out indexOfCharInLine); if (line.LineIndex != 11 || indexOfCharInLine != 48) { throw new Exception("Incorrect line at offset 881"); } line = (ReadOnlyTextLine)textDocument.GetLineByOffset(2509, out indexOfCharInLine); if (line.LineIndex != 35 || indexOfCharInLine != 48) { throw new Exception("Incorrect line at offset 2509"); } if (textDocument.Length != 2595) { throw new Exception("Document should have length 2595"); } if (textDocument.LineCount != 37) { throw new Exception("Document should have 37 line count"); } if (textDocument.Lines.Count() != 37) { throw new Exception("Document should have 37 lines"); } }
public static void Check_ASCIICobolFile_FreeTextFormat() { DocumentFormat docFormat = DocumentFormat.FreeTextFormat; SourceFileProvider fileProvider = new SourceFileProvider(); fileProvider.AddLocalDirectoryLibrary( PlatformUtils.GetPathForProjectFile(SampleFolder), false, new string[] { ".cpy" }, docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength); DummyTextSourceListener textSourceListener = new DummyTextSourceListener(); CobolFile cobolFile; if (fileProvider.TryGetFile("AsciiFreeFormat", out cobolFile)) { // Load the CobolFile in a TextDocument ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("AsciiFreeFormat.cpy", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars()); // Send all text lines in one batch to the test observer textDocument.TextChanged += textSourceListener.OnTextChanged; textDocument.StartSendingChangeEvents(); } TextChangeMap tce1 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.First <TextChange>(), docFormat.ColumnsLayout); if (tce1.LineIndex != 0 || tce1.Type != TextChangeType.LineInserted || tce1.NewLineMap.SequenceNumberText != null || tce1.NewLineMap.IndicatorChar != '/' || tce1.NewLineMap.SourceText != "----------------------------------------------------------------" || tce1.NewLineMap.CommentText != null) { throw new Exception("Error reading line 1 of the ASCII text source (free text format)"); } TextChangeMap tce2 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[4], docFormat.ColumnsLayout); if (tce2.LineIndex != 4 || tce2.Type != TextChangeType.LineInserted || tce2.NewLineMap.SequenceNumberText != null || tce2.NewLineMap.IndicatorChar != '*' || tce2.NewLineMap.SourceText != " Comportant TAGs (ou BALISEs) standards/normalisés apposées via commentaires standards à respecter " || tce2.NewLineMap.CommentText != null) { throw new Exception("Error reading line 5 of the ASCII text source (free text format)"); } TextChangeMap tce3 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[7], docFormat.ColumnsLayout); if (tce3.LineIndex != 7 || tce3.Type != TextChangeType.LineInserted || tce3.NewLineMap.SequenceNumberText != null || tce3.NewLineMap.IndicatorChar != ' ' || tce3.NewLineMap.SourceText != " 10 PIC X(008) VALUE " || tce3.NewLineMap.CommentText != null) { throw new Exception("Error reading line 8 of the ASCII text source (free text format)"); } TextChangeMap tce4 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[8], docFormat.ColumnsLayout); if (tce4.LineIndex != 8 || tce4.Type != TextChangeType.LineInserted || tce4.NewLineMap.SequenceNumberText != null || tce4.NewLineMap.IndicatorChar != ' ' || tce4.NewLineMap.SourceText != " 'MSVCINP '. " || tce4.NewLineMap.CommentText != null) { throw new Exception("Error reading line 9 of the ASCII text source (free text format)"); } TextChangeMap tce5 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[13], docFormat.ColumnsLayout); if (tce5.LineIndex != 13 || tce5.Type != TextChangeType.LineInserted || tce5.NewLineMap.SequenceNumberText != null || tce5.NewLineMap.IndicatorChar != 'D' || tce5.NewLineMap.SourceText != " 15 :MSVCINP:-AppSessnId PIC X(064). " || tce5.NewLineMap.CommentText != null) { throw new Exception("Error reading line 14 of the ASCII text source (free text format)"); } TextChangeMap tce6 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[18], docFormat.ColumnsLayout); if (tce6.LineIndex != 18 || tce6.Type != TextChangeType.LineInserted || tce6.NewLineMap.SequenceNumberText != null || tce6.NewLineMap.IndicatorChar != ' ' || tce6.NewLineMap.SourceText != " 05 FILLER PIC X(499). " || tce6.NewLineMap.CommentText != null) { throw new Exception("Error reading line 19 of the ASCII text source (free text format)"); } TextChangeMap tce7 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.Last <TextChange>(), docFormat.ColumnsLayout); if (tce7.LineIndex != 27 || tce7.Type != TextChangeType.LineInserted || tce7.NewLineMap.SequenceNumberText != null || tce7.NewLineMap.IndicatorChar != 'd' || tce7.NewLineMap.SourceText != " 05 PIC X(008) VALUE '/MSVCINP'. " || tce7.NewLineMap.CommentText != null) { throw new Exception("Error reading line 28 of the ASCII text source (free text format)"); } }
/// <summary> /// Parse an file using a NodeListener and IReport instance and compare the resulting report. /// </summary> /// <typeparam name="TCtx"></typeparam> /// <param name="fileName">The file name to parse</param> /// <param name="reportFileName">The file that contains the expected report</param> /// <param name="reportType">The Type of the IReport instance to be instantiated.</param> public static void ParseWithNodeListenerReportCompare <TCtx>(string fileName, string reportFileName, System.Type reportType) where TCtx : class { Assert.IsTrue(Tools.Reflection.IsTypeOf(reportType, typeof(IReport))); IReport report = null;//Variable to receive the created report instance. TypeCobol.Compiler.Parser.NodeListenerFactory <TCtx> factory = () => { object obj = System.Activator.CreateInstance(reportType, args: Path.GetFullPath(reportFileName)); Assert.IsTrue(obj is NodeListener <TCtx>); TypeCobol.Compiler.Parser.NodeListener <TCtx> nodeListener = (TypeCobol.Compiler.Parser.NodeListener <TCtx>)obj; Assert.IsNotNull(nodeListener); report = (IReport)nodeListener; return(nodeListener); }; //Register the Node Listener Factory TypeCobol.Compiler.Parser.NodeDispatcher <TCtx> .RegisterStaticNodeListenerFactory(factory); try { string input = Path.Combine(ROOT_INPUT, fileName); string output = Path.Combine(ROOT_OUTPUT, reportFileName); DocumentFormat format = DocumentFormat.RDZReferenceFormat; var parser = new TypeCobol.Parser(); var typeCobolOption = new TypeCobolOptions { ExecToStep = ExecutionStep.CrossCheck }; #if EUROINFO_RULES typeCobolOption.AutoRemarksEnable = false; #endif String copyFolder = Path.Combine(Directory.GetCurrentDirectory(), ROOT_COPY); parser.Init(input, typeCobolOption, format, new List <string>() { copyFolder }); parser.Parse(input); var allDiags = parser.Results.AllDiagnostics(); if (allDiags.Count == 0) { if (report != null) { using (System.IO.StringWriter sw = new StringWriter()) { report.Report(sw); // compare with expected result string result = sw.ToString(); string expected = File.ReadAllText(output, format.Encoding); TypeCobol.Test.TestUtils.compareLines(input, result, expected, PlatformUtils.GetPathForProjectFile(output)); } } } } finally { TypeCobol.Compiler.Parser.NodeDispatcher <TCtx> .RemoveStaticNodeListenerFactory(factory); } }