Skip to content

Commit

Permalink
Fix :NEEDS clause sometimes not getting removed
Browse files Browse the repository at this point in the history
Fixes #94
  • Loading branch information
blowfishpro committed Feb 11, 2018
1 parent 94e57a9 commit 07547be
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
14 changes: 5 additions & 9 deletions ModuleManager/NeedsChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ public static void CheckNeeds(UrlDir gameDatabaseRoot, IEnumerable<string> mods,

private static void CheckNeeds(NodeStack stack, PatchContext context, IEnumerable<string> mods)
{
bool needsCopy = false;
ConfigNode original = stack.value;
ConfigNode copy = new ConfigNode(original.name);
for (int i = 0; i < original.values.Count; ++i)
{
ConfigNode.Value val = original.values[i];
Expand All @@ -90,11 +88,12 @@ private static void CheckNeeds(NodeStack stack, PatchContext context, IEnumerabl
{
if (CheckNeeds(ref valname, mods))
{
copy.AddValue(valname, val.value);
val.name = valname;
}
else
{
needsCopy = true;
original.values.Remove(val);
i--;
context.progress.NeedsUnsatisfiedValue(context.patchUrl, stack, val.name);
}
}
Expand Down Expand Up @@ -127,11 +126,11 @@ private static void CheckNeeds(NodeStack stack, PatchContext context, IEnumerabl
{
node.name = nodeName;
CheckNeeds(stack.Push(node), context, mods);
copy.AddNode(node);
}
else
{
needsCopy = true;
original.nodes.Remove(node);
i--;
context.progress.NeedsUnsatisfiedNode(context.patchUrl, stack.Push(node));
}
}
Expand All @@ -146,9 +145,6 @@ private static void CheckNeeds(NodeStack stack, PatchContext context, IEnumerabl
throw;
}
}

if (needsCopy)
original.ShallowCopyFrom(copy);
}

/// <summary>
Expand Down
32 changes: 32 additions & 0 deletions ModuleManagerTests/NeedsCheckerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,38 @@ public void TestCheckNeeds__ExceptionWhileLoggingException()
Assert.Equal(new[] { config1, config3 }, root.AllConfigs);
}

[Fact]
public void TestCheckNeeds__AllNeedsSatisfied()
{
string[] modList = { "mod1", "mod2" };

UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig(new TestConfigNode("SOME_NODE")
{
{ "value", "1" },
}, file);
UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig(new TestConfigNode("@SOME_NODE")
{
{ "@value", "2" },
{ "@value:NEEDS[mod1] +", "4" },
}, file);

NeedsChecker.CheckNeeds(root, modList, progress, logger);

progress.DidNotReceiveWithAnyArgs().Exception(null, null);
progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
progress.DidNotReceiveWithAnyArgs().Error(null, null);

ConfigNode node = root.AllConfigs.ToArray().Last().config;
Assert.Equal("@SOME_NODE", node.name);
Assert.Equal("@value", node.values[0].name);
Assert.Equal("2", node.values[0].value);
Assert.Equal("@value +", node.values[1].name);
Assert.Equal("4", node.values[1].value);

progress.DidNotReceiveWithAnyArgs().NeedsUnsatisfiedValue(null, null, null);

}

private UrlDir.UrlConfig CreateConfig(string name)
{
ConfigNode node = new TestConfigNode(name)
Expand Down

0 comments on commit 07547be

Please sign in to comment.