diff --git a/test/ZoneCodeGeneratorTests/Parsing/C_Header/Impl/PreprocessorTest.cs b/test/ZoneCodeGeneratorTests/Parsing/C_Header/Impl/PreprocessorTest.cs index 4c49bc47..7dbf642f 100644 --- a/test/ZoneCodeGeneratorTests/Parsing/C_Header/Impl/PreprocessorTest.cs +++ b/test/ZoneCodeGeneratorTests/Parsing/C_Header/Impl/PreprocessorTest.cs @@ -25,6 +25,27 @@ namespace ZoneCodeGeneratorTests.Parsing.C_Header.Impl preprocessor = new Preprocessor(headerStreamTest, headerParserState); } + [TestMethod] + public void EnsureReturnsUnmodifiedText() + { + string[] stringsThatShouldNotBeModified = + { + "This is a normal string", + "There is nothing to be preprocessed!", + "0124124124 # 124124124", + "...", + "asdf", + "" + }; + + headerStreamTest.Lines.AddRange(stringsThatShouldNotBeModified); + + foreach (var stringThatShouldNotBeModified in stringsThatShouldNotBeModified) + { + Assert.AreEqual(stringThatShouldNotBeModified, preprocessor.ReadLine()); + } + } + [TestMethod] public void EnsureDefinesArePlacedCorrectly() { diff --git a/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Impl/CommandFilePreprocessorTest.cs b/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Impl/CommandFilePreprocessorTest.cs new file mode 100644 index 00000000..7a36faf8 --- /dev/null +++ b/test/ZoneCodeGeneratorTests/Parsing/CommandFile/Impl/CommandFilePreprocessorTest.cs @@ -0,0 +1,76 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ZoneCodeGenerator.Parsing.CommandFile.Impl; +using ZoneCodeGeneratorTests.Parsing.Mock; + +namespace ZoneCodeGeneratorTests.Parsing.CommandFile.Impl +{ + [TestClass] + public class PreprocessorTest + { + private IncludingParsingStreamTest headerStreamTest; + + private CommandFilePreprocessor preprocessor; + + [TestInitialize] + public void Setup() + { + headerStreamTest = new IncludingParsingStreamTest("file.h"); + preprocessor = new CommandFilePreprocessor(headerStreamTest); + } + + [TestMethod] + public void EnsureReturnsUnmodifiedText() + { + string[] stringsThatShouldNotBeModified = + { + "This is a normal string", + "There is nothing to be preprocessed!", + "0124124124 # 124124124", + "...", + "asdf", + "" + }; + + headerStreamTest.Lines.AddRange(stringsThatShouldNotBeModified); + + foreach (var stringThatShouldNotBeModified in stringsThatShouldNotBeModified) + { + Assert.AreEqual(stringThatShouldNotBeModified, preprocessor.ReadLine()); + } + } + + [TestMethod] + public void EnsureIncludeChangesFileWhenUsingQuotationMarks() + { + headerStreamTest.Lines.AddRange(new[] + { + "include \"asdf.h\"", + "include \"file/path/to/header.h\"" + }); + preprocessor.ReadLine(); + Assert.AreEqual(1, headerStreamTest.IncludeCount); + Assert.AreEqual("asdf.h", headerStreamTest.LastInclude); + + preprocessor.ReadLine(); + Assert.AreEqual(2, headerStreamTest.IncludeCount); + Assert.AreEqual("file/path/to/header.h", headerStreamTest.LastInclude); + } + + [TestMethod] + public void EnsureIncludeChangesFileWhenUsingCarets() + { + headerStreamTest.Lines.AddRange(new[] + { + "include ", + "include " + }); + preprocessor.ReadLine(); + Assert.AreEqual(1, headerStreamTest.IncludeCount); + Assert.AreEqual("asdf.h", headerStreamTest.LastInclude); + + preprocessor.ReadLine(); + Assert.AreEqual(2, headerStreamTest.IncludeCount); + Assert.AreEqual("file/path/to/header.h", headerStreamTest.LastInclude); + } + } +}