Fix the MiniYaml unit tests. Fixes #7999.
This commit is contained in:
@@ -21,17 +21,22 @@ namespace OpenRA.Test
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class MiniYamlTest
|
public class MiniYamlTest
|
||||||
{
|
{
|
||||||
readonly string yamlForParent = @"
|
readonly string mixedMergeA = @"
|
||||||
^Parent:
|
Merge:
|
||||||
FromParent:
|
FromA:
|
||||||
FromParentRemove:
|
FromARemovedB:
|
||||||
|
FromARemovedA:
|
||||||
|
-FromBRemovedA:
|
||||||
|
-FromARemovedA:
|
||||||
";
|
";
|
||||||
|
|
||||||
readonly string yamlForChild = @"
|
readonly string mixedMergeB = @"
|
||||||
Child:
|
Merge:
|
||||||
Inherits: ^Parent
|
FromB:
|
||||||
FromChild:
|
FromBRemovedA:
|
||||||
-FromParentRemove:
|
FromBRemovedB:
|
||||||
|
-FromARemovedB:
|
||||||
|
-FromBRemovedB:
|
||||||
";
|
";
|
||||||
|
|
||||||
readonly string yamlTabStyle = @"
|
readonly string yamlTabStyle = @"
|
||||||
@@ -60,58 +65,28 @@ Root2:
|
|||||||
Attribute1: Test
|
Attribute1: Test
|
||||||
";
|
";
|
||||||
|
|
||||||
List<MiniYamlNode> parentList;
|
[TestCase(TestName = "Merging: mixed addition and removal")]
|
||||||
List<MiniYamlNode> childList;
|
|
||||||
MiniYaml parent;
|
|
||||||
MiniYaml child;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void SetUp()
|
|
||||||
{
|
|
||||||
parentList = MiniYaml.FromString(yamlForParent);
|
|
||||||
childList = MiniYaml.FromString(yamlForChild);
|
|
||||||
parent = parentList.First().Value;
|
|
||||||
child = childList.First().Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InheritanceTest(List<MiniYamlNode> nodes)
|
|
||||||
{
|
|
||||||
Assert.That(nodes.Any(n => n.Key == "FromParent"), Is.True, "Node from parent");
|
|
||||||
Assert.That(nodes.Any(n => n.Key == "FromChild"), Is.True, "Node from child");
|
|
||||||
Assert.That(nodes.Any(n => n.Key == "FromParentRemove"), Is.Not.True, "Node from parent - node from child");
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestCase(TestName = "MergeStrict(MiniYaml, MiniYaml)")]
|
|
||||||
public void MergeYamlA()
|
public void MergeYamlA()
|
||||||
{
|
{
|
||||||
var res = MiniYaml.MergeStrict(parent, child);
|
var a = MiniYaml.FromString(mixedMergeA, "mixedMergeA");
|
||||||
InheritanceTest(res.Nodes);
|
var b = MiniYaml.FromString(mixedMergeB, "mixedMergeB");
|
||||||
|
|
||||||
|
// Merge order should not matter
|
||||||
|
// Note: All the Merge* variants are different plumbing over the same
|
||||||
|
// internal logic. Testing only MergeStrict is sufficent.
|
||||||
|
TestMixedMerge(MiniYaml.MergeStrict(a, b).First().Value);
|
||||||
|
TestMixedMerge(MiniYaml.MergeStrict(b, a).First().Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Ignore("Disabled until the code is fixed so we don't break continuous integration.")]
|
void TestMixedMerge(MiniYaml result)
|
||||||
[TestCase(TestName = "MergeLiberal(MiniYaml, MiniYaml)")]
|
|
||||||
public void MergeYamlB()
|
|
||||||
{
|
{
|
||||||
var res = MiniYaml.MergeLiberal(parent, child);
|
Console.WriteLine(result.ToLines("result").JoinWith("\n"));
|
||||||
InheritanceTest(res.Nodes);
|
Assert.That(result.Nodes.Any(n => n.Key == "FromA"), Is.True, "Node from A");
|
||||||
}
|
Assert.That(result.Nodes.Any(n => n.Key == "FromB"), Is.True, "Node from B");
|
||||||
|
Assert.That(result.Nodes.Any(n => n.Key == "FromARemovedA"), Is.Not.True, "Node from A removed by A");
|
||||||
[Ignore("Disabled until the code is fixed so we don't break continuous integration.")]
|
Assert.That(result.Nodes.Any(n => n.Key == "FromARemovedB"), Is.Not.True, "Node from A removed by B");
|
||||||
[TestCase(TestName = "MergeStrict(List<MiniYamlNode>, List<MiniYamlNode>)")]
|
Assert.That(result.Nodes.Any(n => n.Key == "FromBRemovedA"), Is.Not.True, "Node from B removed by A");
|
||||||
public void MergeYamlC()
|
Assert.That(result.Nodes.Any(n => n.Key == "FromBRemovedB"), Is.Not.True, "Node from B removed by B");
|
||||||
{
|
|
||||||
var res = MiniYaml.MergeStrict(parentList, childList).Last();
|
|
||||||
Assert.That(res.Key, Is.EqualTo("Child"));
|
|
||||||
InheritanceTest(res.Value.Nodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Ignore("Disabled until the code is fixed so we don't break continuous integration.")]
|
|
||||||
[TestCase(TestName = "MergeLiberal(List<MiniYamlNode>, List<MiniYamlNode>)")]
|
|
||||||
public void MergeYamlD()
|
|
||||||
{
|
|
||||||
var res = MiniYaml.MergeLiberal(parentList, childList).Last();
|
|
||||||
Assert.That(res.Key, Is.EqualTo("Child"));
|
|
||||||
InheritanceTest(res.Value.Nodes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(TestName = "Mixed tabs & spaces indents")]
|
[TestCase(TestName = "Mixed tabs & spaces indents")]
|
||||||
|
|||||||
Reference in New Issue
Block a user