FIL-18: Fixed first comment block being merged into the script description

This commit is contained in:
Ben Wallis 2017-12-09 16:16:20 +00:00
parent f838b35b4c
commit 3f437c0109
2 changed files with 35 additions and 5 deletions
Filtration.Parser.Tests/Services
Filtration.Parser/Services

@ -393,6 +393,39 @@ namespace Filtration.Parser.Tests.Services
Assert.AreEqual("My Block Group", secondBlock.BlockGroup.GroupName);
}
[Test]
public void TranslateStringToItemFilterScript_SectionBeforeFirstBlock_ParsesCorrectly()
{
//Arrange
var testInputScript = "# Filter Description Line 1" + Environment.NewLine +
"# Filter Description Line 2" + Environment.NewLine +
"# Filter Description Line 3" + Environment.NewLine +
Environment.NewLine +
"# Section: Test" + Environment.NewLine +
Environment.NewLine +
" Show" + Environment.NewLine +
"Class \"Pantheon Soul\"";
var blockTranslator = CreateItemFilterScriptTranslator(itemFilterBlockTranslator: new ItemFilterBlockTranslator(Mock.Of<IBlockGroupHierarchyBuilder>()));
//Act
var result = blockTranslator.TranslateStringToItemFilterScript(testInputScript);
//Assert
var expectedDescription = "Filter Description Line 1" + Environment.NewLine +
"Filter Description Line 2" + Environment.NewLine +
"Filter Description Line 3";
Assert.AreEqual(expectedDescription, result.Description);
var firstItemFilterCommentBlock = result.ItemFilterBlocks.OfType<ItemFilterCommentBlock>().FirstOrDefault();
Assert.IsNotNull(firstItemFilterCommentBlock);
Assert.AreEqual(" Section: Test", firstItemFilterCommentBlock.Comment);
var firstItemFilterBlock = result.ItemFilterBlocks.OfType<ItemFilterBlock>().FirstOrDefault();
Assert.IsNotNull(firstItemFilterBlock);
Assert.AreEqual(BlockAction.Show, firstItemFilterBlock.Action);
}
private ItemFilterScriptTranslator CreateItemFilterScriptTranslator(IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder = null,
IItemFilterBlockTranslator itemFilterBlockTranslator = null,
IItemFilterScriptFactory itemFilterScriptFactory = null)

@ -198,12 +198,9 @@ namespace Filtration.Parser.Services
}
// A line starting with a comment where the previous line was null represents the start of a new comment (unless we're on the first
// line in which case it's not a new comment).
else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentItemFilterBlockBoundary.BoundaryType != ItemFilterBlockBoundaryType.ScriptDescription)
else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentLine > 0)
{
if (blockBoundaries.Count > 0)
{
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
}
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock);
}