Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ internal static string Validate(string pathToFile)
return ValidateLayoutTypeElement(childElement);
case "layout":
return ValidateLayoutElement(childElement);
case "part":
return ValidatePartElement(childElement);
default:
return "Layout file contains unrecognized child element.";
return "Layout file contains unrecognized child element: " + childElement.Name.LocalName + ".";
}
}
}
Expand Down Expand Up @@ -108,7 +110,7 @@ private static string ValidateLayoutElement(XElement layout)
case "generate":
return ValidateGenerateElement(childElement);
default:
return "Layout element contains unrecognized child element.";
return "Layout element contains unrecognized child element" + childElement.Name.LocalName + ".";
}
}
return null;
Expand All @@ -118,6 +120,14 @@ private static string ValidatePartElement(XElement part)
{
if (part.Attribute("ref") == null)
return "Required 'ref' attribute is missing.";
foreach (var childElement in part.Elements())
{
if (childElement.Name.LocalName == "indent")
foreach (var grandChildElement in childElement.Elements())
{
ValidatePartElement(grandChildElement);
}
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using NUnit.Framework;
using SIL.IO;
using SIL.Progress;
using System.Text.RegularExpressions;

namespace LibFLExBridgeChorusPluginTests.Handling.ConfigLayout
{
Expand Down Expand Up @@ -109,6 +110,24 @@ public void ShouldNotBeAbleToValidateFile()
Assert.IsNotNull(FileHandler.ValidateFile(_ourFile.Path, new NullProgress()));
}

[Test]
public void ShouldBeAbleToValidateFileWithPartAndIndent()
{
const string data =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<LayoutInventory>
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
<indent>
<part ref=""Exemplar"" visibility=""ifdata"" />
<part ref=""ReversalEntries"" visibility=""ifdata"" />
</indent>
</part>
</LayoutInventory>";

File.WriteAllText(_ourFile.Path, data);
Assert.IsNull(FileHandler.ValidateFile(_ourFile.Path, new NullProgress()));
}

[Test]
public void ShouldBeAbleToValidateFile()
{
Expand Down Expand Up @@ -357,5 +376,45 @@ public void SampleMergeWithEmptyAncestor()
Assert.IsFalse(results.Contains("combinedkey"));

}

[Test]
public void SampleMergeWithPartAndIndent()
{
const string commonAncestor =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<LayoutInventory>
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
<indent>
<part ref=""Exemplar"" visibility=""ifdata"" />
<part ref=""ReversalEntries"" visibility=""ifdata"" />
</indent>
</part>
</LayoutInventory>";
const string ourContent =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<LayoutInventory>
<part ref=""HeavySummary"" param=""Summary"" collapsedLayout=""SummaryCollapsed"" expansion=""expanded"" menu=""mnuDataTree-Sense"" hotlinks=""mnuDataTree-Sense-Hotlinks"" notifyVirtual=""LexSenseOutline"">
<indent>
<part ref=""ReversalEntries"" visibility=""ifdata"" />
<part ref=""Exemplar"" visibility=""ifdata"" />
</indent>
</part>
</LayoutInventory>";

const string theirContent = commonAncestor;

var results = FieldWorksTestServices.DoMerge(
FileHandler,
_ourFile, ourContent,
_commonFile, commonAncestor,
_theirFile, theirContent,
null, null,
0, new List<Type>(),
1, new List<Type> { typeof(XmlChangedRecordReport) });
string normalizedResults = Regex.Replace(results, @"\s", "");
string normalizedOurContent = Regex.Replace(ourContent, @"\s", "");
Assert.AreEqual(normalizedResults, normalizedOurContent);
}

}
}
Loading