Fixed failing tests
This commit is contained in:
parent
4def27c49d
commit
43c6149832
|
@ -232,33 +232,6 @@ namespace Filtration.Parser.Tests.Services
|
||||||
Assert.AreEqual(expectedOutput, result);
|
Assert.AreEqual(expectedOutput, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TranslateStringToItemFilterScript_SectionDirectlyBeforeBlockWithoutDescription_ReturnsCorrectObject()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var testInputScript = "# My Script" + Environment.NewLine +
|
|
||||||
Environment.NewLine +
|
|
||||||
"# Section: Chance Bases" + Environment.NewLine +
|
|
||||||
"Show" + Environment.NewLine +
|
|
||||||
" BaseType \"Lapis Amulet\" \"Amber Amulet\"" + Environment.NewLine +
|
|
||||||
" SetBorderColor 255 0 255" + Environment.NewLine +
|
|
||||||
" SetFontSize 25";
|
|
||||||
|
|
||||||
var blockTranslator = new ItemFilterBlockTranslator(_testUtility.MockBlockGroupHierarchyBuilder.Object);
|
|
||||||
var translator = new ItemFilterScriptTranslator(blockTranslator,
|
|
||||||
_testUtility.MockBlockGroupHierarchyBuilder.Object);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = translator.TranslateStringToItemFilterScript(testInputScript);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.AreEqual(2, result.ItemFilterBlocks.Count);
|
|
||||||
var block = result.ItemFilterBlocks.OfType<ItemFilterBlock>().First(l => l.GetType() != typeof(ItemFilterSection));
|
|
||||||
Assert.AreEqual(4, block.BlockItems.Count);
|
|
||||||
var baseTypeItem = block.BlockItems.OfType<BaseTypeBlockItem>().First();
|
|
||||||
Assert.AreEqual(2, baseTypeItem.Items.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TranslateStringToItemFilterScript_OneLineDescriptionNoBlockDescriptionAddsDescriptionToScript()
|
public void TranslateStringToItemFilterScript_OneLineDescriptionNoBlockDescriptionAddsDescriptionToScript()
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace Filtration.Parser.Services
|
||||||
|
|
||||||
internal enum ItemFilterBlockBoundaryType
|
internal enum ItemFilterBlockBoundaryType
|
||||||
{
|
{
|
||||||
|
ScriptDescription,
|
||||||
ItemFilterBlock,
|
ItemFilterBlock,
|
||||||
CommentBlock
|
CommentBlock
|
||||||
}
|
}
|
||||||
|
@ -119,7 +120,7 @@ namespace Filtration.Parser.Services
|
||||||
var lines = Regex.Split(inputString, "\r\n|\r|\n");
|
var lines = Regex.Split(inputString, "\r\n|\r|\n");
|
||||||
|
|
||||||
// Process the script header
|
// Process the script header
|
||||||
for (var i = 0; i < conditionBoundaries.First.Value.StartLine; i++)
|
for (var i = 0; i < conditionBoundaries.Skip(1).First().StartLine; i++)
|
||||||
{
|
{
|
||||||
if (lines[i].StartsWith("#"))
|
if (lines[i].StartsWith("#"))
|
||||||
{
|
{
|
||||||
|
@ -136,6 +137,11 @@ namespace Filtration.Parser.Services
|
||||||
// and add that object to the ItemFilterBlocks list
|
// and add that object to the ItemFilterBlocks list
|
||||||
for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next)
|
for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next)
|
||||||
{
|
{
|
||||||
|
if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ScriptDescription)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var begin = boundary.Value.StartLine;
|
var begin = boundary.Value.StartLine;
|
||||||
var end = boundary.Next?.Value.StartLine ?? lines.Length;
|
var end = boundary.Next?.Value.StartLine ?? lines.Length;
|
||||||
var block = new string[end - begin];
|
var block = new string[end - begin];
|
||||||
|
@ -162,7 +168,7 @@ namespace Filtration.Parser.Services
|
||||||
var previousLine = string.Empty;
|
var previousLine = string.Empty;
|
||||||
var currentLine = -1;
|
var currentLine = -1;
|
||||||
|
|
||||||
var currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(1, ItemFilterBlockBoundaryType.CommentBlock);
|
var currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(0, ItemFilterBlockBoundaryType.ScriptDescription);
|
||||||
|
|
||||||
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
||||||
{
|
{
|
||||||
|
@ -177,14 +183,14 @@ namespace Filtration.Parser.Services
|
||||||
|
|
||||||
// A line starting with a comment when we're inside a ItemFilterBlock boundary represents the end of that block
|
// A line starting with a comment when we're inside a ItemFilterBlock boundary represents the end of that block
|
||||||
// as ItemFilterBlocks cannot have comment lines after the block description
|
// as ItemFilterBlocks cannot have comment lines after the block description
|
||||||
if (trimmedLine.StartsWith("#") && currentItemFilterBlockBoundary?.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock)
|
if (trimmedLine.StartsWith("#") && currentItemFilterBlockBoundary.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock)
|
||||||
{
|
{
|
||||||
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
|
blockBoundaries.AddLast(currentItemFilterBlockBoundary);
|
||||||
currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock);
|
currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock);
|
||||||
}
|
}
|
||||||
// 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
|
// 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).
|
// line in which case it's not a new comment).
|
||||||
else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentLine > 0)
|
else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentItemFilterBlockBoundary.BoundaryType != ItemFilterBlockBoundaryType.ScriptDescription)
|
||||||
{
|
{
|
||||||
if (blockBoundaries.Count > 0)
|
if (blockBoundaries.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue