diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index 00fb6e2..2412bc0 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -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())); + + //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().FirstOrDefault(); + Assert.IsNotNull(firstItemFilterCommentBlock); + Assert.AreEqual(" Section: Test", firstItemFilterCommentBlock.Comment); + var firstItemFilterBlock = result.ItemFilterBlocks.OfType().FirstOrDefault(); + Assert.IsNotNull(firstItemFilterBlock); + Assert.AreEqual(BlockAction.Show, firstItemFilterBlock.Action); + } + private ItemFilterScriptTranslator CreateItemFilterScriptTranslator(IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder = null, IItemFilterBlockTranslator itemFilterBlockTranslator = null, IItemFilterScriptFactory itemFilterScriptFactory = null) diff --git a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs index 6c21e2b..c245487 100644 --- a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs @@ -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); }