Skip to content

Commit

Permalink
Added MiniYAML merging unit tests
Browse files Browse the repository at this point in the history
MockString:
	CollectionOfStrings:
		StringA: A

MockString:
	CollectionOfStrings:
		StringB: B

MockString:
	-CollectionOfStrings:

MockString:
	CollectionOfStrings:
		StringC: C

MockString:
	CollectionOfStrings:
		StringD: D

MockString:
	CollectionOfStrings:
		StringA: A
		StringB: B
		StringC: C
		StringD: D
	-CollectionOfStrings:

MockString:
	CollectionOfStrings:
		StringA: A
		StringB: B
	-CollectionOfStrings:
	CollectionOfStrings:
		StringC: C
		StringD: D
  • Loading branch information
RoosterDragon authored and PunkPun committed Apr 14, 2023
1 parent 0b61954 commit 0066010
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions OpenRA.Test/OpenRA.Game/MiniYamlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,48 @@ public void ChildCanBeRemovedAfterMultipleInheritance()
Assert.IsFalse(result.Any(n => n.Key == "MockA2"), "Node should not have the MockA2 child, but does.");
}

[TestCase(TestName = "Child can be immediately removed")]
public void ChildCanBeImmediatelyRemoved()
{
var baseYaml = @"
^BaseA:
MockString:
AString: Base
Test:
Inherits: ^BaseA
MockString:
AString: Override
-MockString:
";

var result = MiniYaml.Merge(new[] { baseYaml }.Select(s => MiniYaml.FromString(s, "")))
.First(n => n.Key == "Test").Value.Nodes;

Assert.IsFalse(result.Any(n => n.Key == "MockString"), "Node should not have the MockString child, but does.");
}

[TestCase(TestName = "Child can be removed and immediately overridden")]
public void ChildCanBeRemovedAndImmediatelyOverridden()
{
var baseYaml = @"
^BaseA:
MockString:
AString: Base
Test:
Inherits: ^BaseA
-MockString:
MockString:
AString: Override
";

var result = MiniYaml.Merge(new[] { baseYaml }.Select(s => MiniYaml.FromString(s, "")))
.First(n => n.Key == "Test").Value.Nodes;

Assert.IsTrue(result.Any(n => n.Key == "MockString"), "Node should have the MockString child, but does not.");
Assert.IsTrue(result.First(n => n.Key == "MockString").Value.ToDictionary()["AString"].Value == "Override",
"MockString value has not been set with the correct override value for AString.");
}

[TestCase(TestName = "Child can be removed and later overridden")]
public void ChildCanBeRemovedAndLaterOverridden()
{
Expand Down Expand Up @@ -155,6 +197,69 @@ public void ChildCanBeOverriddenThenRemoved()
"MockString value should have been removed, but was not.");
}

[TestCase(TestName = "Child subnode can be removed and immediately overridden")]
public void ChildSubNodeCanBeRemovedAndImmediatelyOverridden()
{
var baseYaml = @"
^BaseA:
MockString:
CollectionOfStrings:
StringA: A
StringB: B
Test:
Inherits: ^BaseA
MockString:
-CollectionOfStrings:
CollectionOfStrings:
StringC: C
";

var merged = MiniYaml.Merge(new[] { baseYaml }.Select(s => MiniYaml.FromString(s, "")))
.First(n => n.Key == "Test");

var traitNode = merged.Value.Nodes.Single();
var fieldNodes = traitNode.Value.Nodes;
var fieldSubNodes = fieldNodes.Single().Value.Nodes;

Assert.IsTrue(fieldSubNodes.Count == 1, "Collection of strings should only contain the overriding subnode.");
Assert.IsTrue(fieldSubNodes.Single(n => n.Key == "StringC").Value.Value == "C",
"CollectionOfStrings value has not been set with the correct override value for StringC.");
}

[TestCase(TestName = "Child subnode can be removed and later overridden")]
public void ChildSubNodeCanBeRemovedAndLaterOverridden()
{
var baseYaml = @"
^BaseA:
MockString:
CollectionOfStrings:
StringA: A
StringB: B
Test:
Inherits: ^BaseA
MockString:
-CollectionOfStrings:
";

var overrideYaml = @"
Test:
MockString:
CollectionOfStrings:
StringC: C
";

var merged = MiniYaml.Merge(new[] { baseYaml, overrideYaml }.Select(s => MiniYaml.FromString(s, "")))
.First(n => n.Key == "Test");

var traitNode = merged.Value.Nodes.Single();
var fieldNodes = traitNode.Value.Nodes;
var fieldSubNodes = fieldNodes.Single().Value.Nodes;

Assert.IsTrue(fieldSubNodes.Count == 1, "Collection of strings should only contain the overriding subnode.");
Assert.IsTrue(fieldSubNodes.Single(n => n.Key == "StringC").Value.Value == "C",
"CollectionOfStrings value has not been set with the correct override value for StringC.");
}

[TestCase(TestName = "Empty lines should count toward line numbers")]
public void EmptyLinesShouldCountTowardLineNumbers()
{
Expand Down

0 comments on commit 0066010

Please sign in to comment.