Example #1
0
        private static void DoNamedTest([CallerMemberName] string name = "")
        {
            if (!name.StartsWith("Test"))
            {
                Assert.Fail("Named test should only be called from test framework with Test[Name] pattern");
            }

            name = name.Remove(0, 4);
            const string resourcesParser  = @"..\..\Resources\Parser";
            const string goldExtension    = ".gold";
            const string tempExtension    = ".temp";
            const string parserExtension  = ".txt";
            var          currentInputFile = Path.Combine(resourcesParser, name, name + parserExtension);
            var          currentTempFile  = Path.Combine(resourcesParser, name, name + tempExtension);
            var          currentGoldFile  = Path.Combine(resourcesParser, name, name + goldExtension);

            Assert.True(File.Exists(currentInputFile), $"Input file does not exists: {currentInputFile}");
            var    fileInfo = new FileInfo(currentInputFile);
            string text;

            using (var streamReader = fileInfo.OpenText())
            {
                var exp = new Parser.Parser(new Lexer(streamReader)).Parse();
                text = exp + "\n" + exp.GetInternalRepresentation();
            }

            using (var tempStream = File.CreateText(currentTempFile))
            {
                tempStream.Write(text);
            }

            Assert.True(File.Exists(currentGoldFile), "No gold found");
            var gold = File.ReadAllText(currentGoldFile);

            Assert.AreEqual(gold, text, "Temp not equals gold");
            File.Delete(currentTempFile);
        }