Fix for line description being lost when reading disabled blocks
This commit is contained in:
parent
9fcb609a51
commit
56e163e3e0
|
@ -323,7 +323,34 @@ namespace Filtration.Tests.Translators
|
|||
Assert.AreEqual(3, firstBlock.BlockItems.Count);
|
||||
Assert.AreEqual(5, secondBlock.BlockItems.Count);
|
||||
Assert.AreEqual(3, thirdBlock.BlockItems.Count);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateStringToItemFilterScript_DisabledBlock_BlockDescriptionNotLost()
|
||||
{
|
||||
// Arrange
|
||||
var testInputScript = "Show" + Environment.NewLine +
|
||||
" ItemLevel > 2" + Environment.NewLine +
|
||||
" SetTextColor 255 40 0" + Environment.NewLine +
|
||||
Environment.NewLine +
|
||||
"#Disabled Block Start" + Environment.NewLine +
|
||||
"# This is a disabled block" + Environment.NewLine +
|
||||
"#Show" + Environment.NewLine +
|
||||
"# ItemLevel > 2" + Environment.NewLine +
|
||||
"#Disabled Block End";
|
||||
|
||||
|
||||
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 secondBlock = result.ItemFilterBlocks.Skip(1).First();
|
||||
Assert.AreEqual("This is a disabled block", secondBlock.Description);
|
||||
}
|
||||
|
||||
private class ItemFilterScriptTranslatorTestUtility
|
||||
|
|
|
@ -50,7 +50,7 @@ using System.Windows;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.7.*")]
|
||||
[assembly: AssemblyVersion("0.6.*")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Filtration.Tests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
|
@ -32,6 +32,7 @@ namespace Filtration.Translators
|
|||
public string PreprocessDisabledBlocks(string inputString)
|
||||
{
|
||||
bool inDisabledBlock = false;
|
||||
var showHideFound = false;
|
||||
|
||||
var lines = Regex.Split(inputString, "\r\n|\r|\n").ToList();
|
||||
var linesToRemove = new List<int>();
|
||||
|
@ -49,6 +50,7 @@ namespace Filtration.Translators
|
|||
if (lines[i].StartsWith("#Disabled Block End"))
|
||||
{
|
||||
inDisabledBlock = false;
|
||||
showHideFound = false;
|
||||
linesToRemove.Add(i);
|
||||
continue;
|
||||
}
|
||||
|
@ -56,13 +58,24 @@ namespace Filtration.Translators
|
|||
lines[i] = lines[i].TrimStart('#');
|
||||
var spaceOrEndOfLinePos = lines[i].IndexOf(" ", StringComparison.Ordinal) > 0 ? lines[i].IndexOf(" ", StringComparison.Ordinal) : lines[i].Length;
|
||||
var lineOption = lines[i].Substring(0, spaceOrEndOfLinePos);
|
||||
|
||||
// If we haven't found a Show or Hide line yet, then this is probably the block comment.
|
||||
// Put its # back on and skip to the next line.
|
||||
if (lineOption != "Show" && lineOption != "Hide" && showHideFound == false)
|
||||
{
|
||||
lines[i] = "#" + lines[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lineOption == "Show")
|
||||
{
|
||||
lines[i] = lines[i].Replace("Show", "ShowDisabled");
|
||||
showHideFound = true;
|
||||
}
|
||||
else if (lineOption == "Hide")
|
||||
{
|
||||
lines[i] = lines[i].Replace("Hide", "HideDisabled");
|
||||
showHideFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue