ZoneCodeGenerator: Add tests for CommandFilePreprocessor

This commit is contained in:
Jan 2019-10-27 15:05:17 +01:00
parent d4da8645b1
commit 090efd98f0
2 changed files with 97 additions and 0 deletions

View File

@ -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",
"...",
"<?php><html>asdf</html>",
""
};
headerStreamTest.Lines.AddRange(stringsThatShouldNotBeModified);
foreach (var stringThatShouldNotBeModified in stringsThatShouldNotBeModified)
{
Assert.AreEqual(stringThatShouldNotBeModified, preprocessor.ReadLine());
}
}
[TestMethod]
public void EnsureDefinesArePlacedCorrectly()
{

View File

@ -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",
"...",
"<?php><html>asdf</html>",
""
};
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 <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);
}
}
}