public void TestCorrectlyLoadReversePatch() { TestPatch expectedPatch = CreateSmallPatchExample(reverse: true); var patches = PatchProcessor.CreatePatchesFromString(expectedPatch.PatchOutput, Encoding.UTF8); Patch createdPatch = patches.First(); Assert.AreEqual(expectedPatch.Patch.Header, createdPatch.Header, "header"); Assert.AreEqual(expectedPatch.Patch.FileNameB, createdPatch.FileNameA, "fileA"); Assert.AreEqual(expectedPatch.Patch.Index, createdPatch.Index); Assert.AreEqual(expectedPatch.Patch.ChangeType, createdPatch.ChangeType); Assert.AreEqual(expectedPatch.Patch.Text, createdPatch.Text); }
public void TestCorrectlyLoadPatch() { TestPatch expectedPatch = CreateSmallPatchExample(); var patches = PatchProcessor.CreatePatchesFromString(expectedPatch.PatchOutput, new Lazy <Encoding>(() => Encoding.UTF8)); Patch createdPatch = patches.First(); Assert.AreEqual(expectedPatch.Patch.Header, createdPatch.Header); Assert.AreEqual(expectedPatch.Patch.FileNameA, createdPatch.FileNameA); Assert.AreEqual(expectedPatch.Patch.Index, createdPatch.Index); Assert.AreEqual(expectedPatch.Patch.ChangeType, createdPatch.ChangeType); Assert.AreEqual(expectedPatch.Patch.Text, createdPatch.Text); }
public void TestCorrectlyLoadReversePatch() { var manager = new PatchManager(); TestPatch expectedPatch = CreateSmallPatchExample(true); manager.LoadPatch(expectedPatch.PatchOutput.ToString(), Encoding.UTF8); Patch createdPatch = manager.Patches.First(); Assert.AreEqual(expectedPatch.Patch.PatchHeader, createdPatch.PatchHeader, "header"); Assert.AreEqual(expectedPatch.Patch.FileNameB, createdPatch.FileNameA, "fileA"); Assert.AreEqual(expectedPatch.Patch.PatchIndex, createdPatch.PatchIndex); Assert.AreEqual(expectedPatch.Patch.Type, createdPatch.Type); Assert.AreEqual(expectedPatch.Patch.Text, createdPatch.Text); }
static IEnumerable <CodeInstruction> Transpiler(MethodBase original, IEnumerable <CodeInstruction> instructions) { logger.Debug("Loggin Codes: KMod.Manager.Load"); foreach (CodeInstruction code in instructions) { TestPatch.LogCode(code); if (code.opcode == OpCodes.Callvirt) { logger.Debug("Found VIRTUAL CALL::::::: {code}", code); logger.Debug("OPPERAND: {OP} : {module}", code.operand.GetType(), code.operand.GetType().Module.Name); } yield return(code); } yield break; }
public void TestCorrectlyLoadPatch() { PatchManager manager = NewManager(); TestPatch expectedPatch = CreateSmallPatchExample(); manager.LoadPatch(expectedPatch.PatchOutput.ToString(), false, Encoding.UTF8); PatchApply.Patch createdPatch = manager.Patches.First(); Assert.AreEqual(expectedPatch.Patch.PatchHeader, createdPatch.PatchHeader); Assert.AreEqual(expectedPatch.Patch.FileNameA, createdPatch.FileNameA); Assert.AreEqual(expectedPatch.Patch.PatchIndex, createdPatch.PatchIndex); Assert.AreEqual(expectedPatch.Patch.Rate, createdPatch.Rate); Assert.AreEqual(expectedPatch.Patch.Type, createdPatch.Type); Assert.AreEqual(expectedPatch.Patch.Text, createdPatch.Text); }
public TestPatch CreateSmallPatchExample() { TestPatch testPatch = new TestPatch(); Encoding fileEncoding = Encoding.UTF8; testPatch.Patch.Type = Patch.PatchType.ChangeFile; testPatch.Patch.Apply = true; testPatch.Patch.PatchHeader = "diff --git a/thisisatest.txt b/thisisatest.txt"; testPatch.Patch.PatchIndex = "index 5e4dce2..5eb1e6f 100644"; testPatch.Patch.FileNameA = "thisisatest.txt"; testPatch.Patch.FileNameB = "thisisatest.txt"; testPatch.AppendHeaderLine(testPatch.Patch.PatchHeader); testPatch.AppendHeaderLine(testPatch.Patch.PatchIndex); testPatch.AppendHeaderLine("--- a/" + testPatch.Patch.FileNameA); testPatch.AppendHeaderLine("+++ b/" + testPatch.Patch.FileNameB); testPatch.AppendDiffLine("@@ -1,2 +1,2 @@", fileEncoding); testPatch.AppendDiffLine(" iiiiii", fileEncoding); testPatch.AppendDiffLine("-ąśdkjaldskjlaksd", fileEncoding); testPatch.AppendDiffLine("+changed again€", fileEncoding); return testPatch; }
public TestPatch CreateSmallPatchExample(bool reverse = false) { TestPatch testPatch = new TestPatch(); Encoding fileEncoding = Encoding.UTF8; testPatch.Patch.Type = PatchApply.Patch.PatchType.ChangeFile; testPatch.Patch.Apply = true; if (reverse) { testPatch.Patch.PatchHeader = "diff --git b/thisisatestb.txt a/thisisatesta.txt"; } else { testPatch.Patch.PatchHeader = "diff --git a/thisisatesta.txt b/thisisatestb.txt"; } testPatch.Patch.PatchIndex = "index 5e4dce2..5eb1e6f 100644"; testPatch.Patch.FileNameA = "thisisatesta.txt"; testPatch.Patch.FileNameB = "thisisatestb.txt"; testPatch.AppendHeaderLine(testPatch.Patch.PatchHeader); testPatch.AppendHeaderLine(testPatch.Patch.PatchIndex); if (reverse) { testPatch.AppendHeaderLine("--- b/" + testPatch.Patch.FileNameB); testPatch.AppendHeaderLine("+++ a/" + testPatch.Patch.FileNameA); } else { testPatch.AppendHeaderLine("--- a/" + testPatch.Patch.FileNameA); testPatch.AppendHeaderLine("+++ b/" + testPatch.Patch.FileNameB); } testPatch.AppendDiffLine("@@ -1,2 +1,2 @@", fileEncoding); testPatch.AppendDiffLine(" iiiiii", fileEncoding); testPatch.AppendDiffLine("-ąśdkjaldskjlaksd", fileEncoding); testPatch.AppendDiffLine("+changed again€", fileEncoding); return(testPatch); }
private static TestPatch CreateSmallPatchExample(bool reverse = false) { var testPatch = new TestPatch { Patch = { Type = Patch.PatchType.ChangeFile, PatchHeader = reverse ? "diff --git b/thisisatestb.txt a/thisisatesta.txt" : "diff --git a/thisisatesta.txt b/thisisatestb.txt", PatchIndex = "index 5e4dce2..5eb1e6f 100644", FileNameA = "thisisatesta.txt", FileNameB = "thisisatestb.txt" } }; testPatch.AppendHeaderLine(testPatch.Patch.PatchHeader); testPatch.AppendHeaderLine(testPatch.Patch.PatchIndex); if (reverse) { testPatch.AppendHeaderLine("--- b/" + testPatch.Patch.FileNameB); testPatch.AppendHeaderLine("+++ a/" + testPatch.Patch.FileNameA); } else { testPatch.AppendHeaderLine("--- a/" + testPatch.Patch.FileNameA); testPatch.AppendHeaderLine("+++ b/" + testPatch.Patch.FileNameB); } var fileEncoding = Encoding.UTF8; testPatch.AppendDiffLine("@@ -1,2 +1,2 @@", fileEncoding); testPatch.AppendDiffLine(" iiiiii", fileEncoding); testPatch.AppendDiffLine("-ąśdkjaldskjlaksd", fileEncoding); testPatch.AppendDiffLine("+changed again€", fileEncoding); return(testPatch); }