Skip to content

Commit

Permalink
Fix :LAST when mod doesn't exist
Browse files Browse the repository at this point in the history
Per the original feature design (#96) it should still run
  • Loading branch information
blowfishpro committed Jul 6, 2020
1 parent a2fdef4 commit c4ad2c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 9 additions & 4 deletions ModuleManager/PatchList.cs
Expand Up @@ -76,6 +76,7 @@ public ModPassCollection(IEnumerable<string> modList)
private readonly Pass finalPatches = new Pass(":FINAL");

private readonly ModPassCollection modPasses;
private readonly SortedDictionary<string, Pass> lastPasses = new SortedDictionary<string, Pass>(StringComparer.InvariantCultureIgnoreCase);

public PatchList(IEnumerable<string> modList, IEnumerable<IPatch> patches, IPatchProgress progress)
{
Expand Down Expand Up @@ -114,8 +115,12 @@ public PatchList(IEnumerable<string> modList, IEnumerable<IPatch> patches, IPatc
}
else if (patch.PassSpecifier is LastPassSpecifier lastPassSpecifier)
{
EnsureMod(lastPassSpecifier.mod);
modPasses[lastPassSpecifier.mod].AddLastPatch(patch);
if (!lastPasses.TryGetValue(lastPassSpecifier.mod, out Pass thisPass))
{
thisPass = new Pass($":LAST[{lastPassSpecifier.mod.ToUpperInvariant()}]");
lastPasses.Add(lastPassSpecifier.mod.ToLowerInvariant(), thisPass);
}
thisPass.Add(patch);
}
else if (patch.PassSpecifier is FinalPassSpecifier)
{
Expand Down Expand Up @@ -143,9 +148,9 @@ public IEnumerator<IPass> GetEnumerator()
yield return modPass.afterPass;
}

foreach (ModPass modPass in modPasses)
foreach (Pass lastPass in lastPasses.Values)
{
yield return modPass.lastPass;
yield return lastPass;
}

yield return finalPatches;
Expand Down
16 changes: 11 additions & 5 deletions ModuleManagerTests/PatchListTest.cs
Expand Up @@ -113,6 +113,7 @@ public void Test__Lifecycle()
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
Substitute.For<IPatch>(),
};

UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE"));
Expand All @@ -139,8 +140,9 @@ public void Test__Lifecycle()
patches[19].PassSpecifier.Returns(new AfterPassSpecifier("MOD2", urlConfig));
patches[20].PassSpecifier.Returns(new LastPassSpecifier("mod2"));
patches[21].PassSpecifier.Returns(new LastPassSpecifier("MOD2"));
patches[22].PassSpecifier.Returns(new FinalPassSpecifier());
patches[22].PassSpecifier.Returns(new LastPassSpecifier("mod3"));
patches[23].PassSpecifier.Returns(new FinalPassSpecifier());
patches[24].PassSpecifier.Returns(new FinalPassSpecifier());

patches[00].CountsAsPatch.Returns(false);
patches[01].CountsAsPatch.Returns(false);
Expand All @@ -166,14 +168,15 @@ public void Test__Lifecycle()
patches[21].CountsAsPatch.Returns(true);
patches[22].CountsAsPatch.Returns(true);
patches[23].CountsAsPatch.Returns(true);
patches[24].CountsAsPatch.Returns(true);

IPatchProgress progress = Substitute.For<IPatchProgress>();

PatchList patchList = new PatchList(new[] { "mod1", "mod2" }, patches, progress);

IPass[] passes = patchList.ToArray();

Assert.Equal(12, passes.Length);
Assert.Equal(13, passes.Length);

Assert.Equal(":INSERT (initial)", passes[0].Name);
Assert.Equal(new[] { patches[0], patches[1] }, passes[0]);
Expand Down Expand Up @@ -208,10 +211,13 @@ public void Test__Lifecycle()
Assert.Equal(":LAST[MOD2]", passes[10].Name);
Assert.Equal(new[] { patches[20], patches[21] }, passes[10]);

Assert.Equal(":FINAL", passes[11].Name);
Assert.Equal(new[] { patches[22], patches[23] }, passes[11]);
Assert.Equal(":LAST[MOD3]", passes[11].Name);
Assert.Equal(new[] { patches[22] }, passes[11]);

Assert.Equal(":FINAL", passes[12].Name);
Assert.Equal(new[] { patches[23], patches[24] }, passes[12]);

progress.Received(22).PatchAdded();
progress.Received(23).PatchAdded();
}
}
}

0 comments on commit c4ad2c3

Please sign in to comment.