From e5bd994164f43176377043bf1a455dc7b0d3f79f Mon Sep 17 00:00:00 2001 From: GlenCFL Date: Thu, 7 Dec 2017 11:57:36 -0500 Subject: [PATCH] Fix the existing tests. --- .../Services/TestItemFilterBlockTranslator.cs | 43 +++++++++++++------ .../Services/ItemFilterBlockTranslator.cs | 14 ++---- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index 48b561e..e8ac194 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -609,7 +609,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); var blockItem = result.BlockItems.OfType().First(); - Assert.AreEqual(4, blockItem.Value); + Assert.AreEqual("4", blockItem.Value); Assert.AreEqual(79, blockItem.SecondValue); } @@ -627,7 +627,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); var blockItem = result.BlockItems.OfType().First(); - Assert.AreEqual(2, blockItem.Value); + Assert.AreEqual("2", blockItem.Value); Assert.AreEqual(95, blockItem.SecondValue); } @@ -660,6 +660,9 @@ namespace Filtration.Parser.Tests.Services " Rarity <= Unique" + Environment.NewLine + " Identified True" + Environment.NewLine + " Corrupted false" + Environment.NewLine + + " ElderItem true" + Environment.NewLine + + " ShaperItem False" + Environment.NewLine + + " ShapedMap TRUE" + Environment.NewLine + @" Class ""My Item Class"" AnotherClass ""AndAnotherClass""" + Environment.NewLine + @" BaseType MyBaseType ""Another BaseType""" + Environment.NewLine + " JunkLine Let's ignore this one!" + Environment.NewLine + @@ -671,7 +674,7 @@ namespace Filtration.Parser.Tests.Services " SetBackgroundColor 255 100 5" + Environment.NewLine + " SetBorderColor 0 0 0" + Environment.NewLine + " SetFontSize 50" + Environment.NewLine + - " PlayAlertSound 3"; + " PlayAlertSound 3" + Environment.NewLine; // Act var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); @@ -688,6 +691,15 @@ namespace Filtration.Parser.Tests.Services var identifiedBlockItem = result.BlockItems.OfType().First(); Assert.IsTrue(identifiedBlockItem.BooleanValue); + var elderItemBlockItem = result.BlockItems.OfType().First(); + Assert.IsTrue(elderItemBlockItem.BooleanValue); + + var shaperItemBlockItem = result.BlockItems.OfType().First(); + Assert.IsFalse(shaperItemBlockItem.BooleanValue); + + var shapedMapBlockItem = result.BlockItems.OfType().First(); + Assert.IsTrue(shapedMapBlockItem.BooleanValue); + var dropLevelblockItem = result.BlockItems.OfType().First(); Assert.AreEqual(FilterPredicateOperator.LessThan, dropLevelblockItem.FilterPredicate.PredicateOperator); Assert.AreEqual(70, dropLevelblockItem.FilterPredicate.PredicateOperand); @@ -746,7 +758,7 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(50, fontSizeblockItem.Value); var soundblockItem = result.BlockItems.OfType().First(); - Assert.AreEqual(3, soundblockItem.Value); + Assert.AreEqual("3", soundblockItem.Value); Assert.AreEqual(79, soundblockItem.SecondValue); } @@ -836,7 +848,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); var blockItem = result.BlockItems.OfType().First(); - Assert.AreEqual(2, blockItem.Value); + Assert.AreEqual("2", blockItem.Value); Assert.AreEqual(79, blockItem.SecondValue); } @@ -1523,21 +1535,23 @@ namespace Filtration.Parser.Tests.Services { // Arrange var expectedResult = "Show" + Environment.NewLine + - " LinkedSockets >= 4" + Environment.NewLine + " Sockets <= 6" + Environment.NewLine + " Quality > 2" + Environment.NewLine + " Identified True" + Environment.NewLine + " Corrupted False" + Environment.NewLine + + " ElderItem True" + Environment.NewLine + + " ShaperItem False" + Environment.NewLine + + " ShapedMap True" + Environment.NewLine + " Height <= 6" + Environment.NewLine + " Height >= 2" + Environment.NewLine + " Width = 3" + Environment.NewLine + - " DropLevel > 56" + Environment.NewLine + - " Class \"Body Armour\" \"Gloves\" \"Belt\" \"Two Hand Axes\"" + Environment.NewLine + - " BaseType \"Greater Life Flask\" \"Simple Robe\" \"Full Wyrmscale\"" + Environment.NewLine + - " Rarity = Unique" + Environment.NewLine + " ItemLevel > 70" + Environment.NewLine + " ItemLevel <= 85" + Environment.NewLine + + " DropLevel > 56" + Environment.NewLine + + " Rarity = Unique" + Environment.NewLine + + " Class \"Body Armour\" \"Gloves\" \"Belt\" \"Two Hand Axes\"" + Environment.NewLine + + " BaseType \"Greater Life Flask\" \"Simple Robe\" \"Full Wyrmscale\"" + Environment.NewLine + " SetTextColor 255 89 0 56" + Environment.NewLine + " SetBackgroundColor 0 0 0" + Environment.NewLine + " SetBorderColor 255 1 254" + Environment.NewLine + @@ -1574,6 +1588,9 @@ namespace Filtration.Parser.Tests.Services _testUtility.TestBlock.BlockItems.Add(new BorderColorBlockItem(new Color { A = 255, R = 255, G = 1, B = 254 })); _testUtility.TestBlock.BlockItems.Add(new FontSizeBlockItem(50)); _testUtility.TestBlock.BlockItems.Add(new SoundBlockItem("6", 90)); + _testUtility.TestBlock.BlockItems.Add(new ElderItemBlockItem(true)); + _testUtility.TestBlock.BlockItems.Add(new ShaperItemBlockItem(false)); + _testUtility.TestBlock.BlockItems.Add(new ShapedMapBlockItem(true)); // Act var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock); @@ -1619,7 +1636,7 @@ namespace Filtration.Parser.Tests.Services var soundBlockItem = testInputBlockItems.First(b => b is SoundBlockItem) as SoundBlockItem; Assert.IsNotNull(soundBlockItem); Assert.AreNotSame(testInputBlockItem, soundBlockItem); - Assert.AreEqual(7, soundBlockItem.Value); + Assert.AreEqual("7", soundBlockItem.Value); Assert.AreEqual(280, soundBlockItem.SecondValue); } @@ -1705,7 +1722,7 @@ namespace Filtration.Parser.Tests.Services var soundBlockItem = testInputBlockItems.First(b => b is SoundBlockItem) as SoundBlockItem; Assert.IsNotNull(soundBlockItem); Assert.AreNotSame(testInputSoundBlockItem, soundBlockItem); - Assert.AreEqual(7, soundBlockItem.Value); + Assert.AreEqual("7", soundBlockItem.Value); Assert.AreEqual(280, soundBlockItem.SecondValue); } @@ -1738,7 +1755,7 @@ namespace Filtration.Parser.Tests.Services var soundBlockItem = testInputBlockItems.First(b => b is SoundBlockItem) as SoundBlockItem; Assert.IsNotNull(soundBlockItem); - Assert.AreEqual(7, soundBlockItem.Value); + Assert.AreEqual("7", soundBlockItem.Value); Assert.AreEqual(280, soundBlockItem.SecondValue); } diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index 9fbdeb8..e40b224 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -223,26 +223,20 @@ namespace Filtration.Parser.Services RemoveExistingBlockItemsOfType(block); RemoveExistingBlockItemsOfType(block); - var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s+(\d+)?"); + var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?"); if (match.Success) { - string firstValue; + string firstValue = match.Groups[1].Value; int secondValue; - if (match.Groups.Count == 2) + if (match.Groups[2].Success) { - firstValue = match.Groups[1].Value; - secondValue = 79; - } - else if (match.Groups.Count == 3) - { - firstValue = match.Groups[1].Value; secondValue = Convert.ToInt16(match.Groups[2].Value); } else { - break; + secondValue = 79; } if (lineOption == "PlayAlertSound")