From d8e3f862eb861e557e4055db4719941d4ffb23d2 Mon Sep 17 00:00:00 2001 From: Alexander Luzgarev Date: Fri, 5 Oct 2018 19:52:35 +0200 Subject: [PATCH] Add "there and back again" test --- ConsoleDemo/Program.cs | 5 -- Parser.Tests/ThereAndBackAgain.cs | 82 +++++++++++++++++++++++++++++++ Parser/Internal/MParserGreen.cs | 2 +- 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 Parser.Tests/ThereAndBackAgain.cs diff --git a/ConsoleDemo/Program.cs b/ConsoleDemo/Program.cs index 424bd46..92fd6da 100644 --- a/ConsoleDemo/Program.cs +++ b/ConsoleDemo/Program.cs @@ -34,19 +34,14 @@ namespace ConsoleDemo private static void ProcessFile(string fileName) { var text = File.ReadAllText(fileName); - //Console.Write($"Parsing {fileName}..."); var window = new TextWindowWithNull(text, fileName); var parser = CreateParser(window); var tree = parser.Parse(); - //Console.WriteLine("Done."); var actual = tree.FullText; if (actual != text) { throw new ApplicationException(); } - //var printer = new PrettyPrinter(); - //printer.Visit(tree); - //Console.ReadKey(); } static Program() diff --git a/Parser.Tests/ThereAndBackAgain.cs b/Parser.Tests/ThereAndBackAgain.cs new file mode 100644 index 0000000..3822f7d --- /dev/null +++ b/Parser.Tests/ThereAndBackAgain.cs @@ -0,0 +1,82 @@ +using System; +using NUnit.Framework; +using System.Collections.Generic; +using System.IO; + +namespace Parser.Tests +{ + public class ThereAndBackAgain + { + static ThereAndBackAgain() + { + switch (Environment.OSVersion.Platform) + { + case PlatformID.MacOSX: + case PlatformID.Unix: + BaseDirectory = BaseDirectoryMacOs; + break; + default: + BaseDirectory = BaseDirectoryWindows; + break; + } + } + + private static readonly string BaseDirectory; + private const string BaseDirectoryMacOs = @"/Applications/MATLAB_R2017b.app/toolbox/matlab/"; + private const string BaseDirectoryWindows = @"D:\Program Files\MATLAB\R2018a\toolbox\matlab\"; + + private static readonly HashSet SkipFiles = new HashSet + { + @"codetools\private\template.m", // this is a template, so it contains '$' characters. + @"plottools\+matlab\+graphics\+internal\+propertyinspector\+views\CategoricalHistogramPropertyView.m", // this one contains a 0xA0 character (probably it's 'non-breakable space' in Win-1252). + @"plottools\+matlab\+graphics\+internal\+propertyinspector\+views\PrimitiveHistogram2PropertyView.m", // same + @"plottools\+matlab\+graphics\+internal\+propertyinspector\+views\PrimitiveHistogramPropertyView.m", // same + @"codetools/private/template.m", // this is a template, so it contains '$' characters. + @"plottools/+matlab/+graphics/+internal/+propertyinspector/+views/CategoricalHistogramPropertyView.m", // this one contains a 0xA0 character (probably it's 'non-breakable space' in Win-1252). + @"plottools/+matlab/+graphics/+internal/+propertyinspector/+views/PrimitiveHistogram2PropertyView.m", // same + @"plottools/+matlab/+graphics/+internal/+propertyinspector/+views/PrimitiveHistogramPropertyView.m", // same + }; + + private static MParser CreateParser(ITextWindow window) + { + return new MParser(window); + } + + private static void ProcessFile(string fileName) + { + var text = File.ReadAllText(fileName); + var window = new TextWindowWithNull(text, fileName); + var parser = CreateParser(window); + var tree = parser.Parse(); + var actual = tree.FullText; + Assert.That(actual == text); + } + + private static void ProcessDirectory(string directory) + { + var files = Directory.GetFiles(directory, "*.m"); + foreach (var file in files) + { + var relativePath = Path.GetRelativePath(BaseDirectory, file); + if (SkipFiles.Contains(relativePath)) + { + continue; + } + ProcessFile(file); + } + + var subDirectories = Directory.GetDirectories(directory); + foreach (var subDirectory in subDirectories) + { + ProcessDirectory(subDirectory); + } + } + + [Category("Slow")] + [Test] + public void TestEverything() + { + ProcessDirectory(BaseDirectory); + } + } +} diff --git a/Parser/Internal/MParserGreen.cs b/Parser/Internal/MParserGreen.cs index 129eae5..bfeb144 100644 --- a/Parser/Internal/MParserGreen.cs +++ b/Parser/Internal/MParserGreen.cs @@ -143,7 +143,7 @@ namespace Parser.Internal } else { - throw new ParsingException($"Unexpected token {CurrentToken} during parsing function output descritpion at {CurrentPosition}."); + throw new ParsingException($"Unexpected token {CurrentToken} during parsing function output description at {CurrentPosition}."); } return Factory.FunctionOutputDescriptionSyntax(builder.ToList(), assignmentSign);