Skip to content

Commit

Permalink
adds test for #640
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Dec 19, 2024
1 parent 5be64c9 commit 4852c9c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions HarmonyTests/Patching/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,23 @@ public void Test_RenamedArguments()
var log = RenamedArgumentsPatch.log.Join();
Assert.AreEqual("val1, patched, val2, hello", log);
}

[Test]
public void Test_NullableResults()
{
var res1 = new NullableResults().Method();
Assert.True(res1.HasValue);
Assert.False(res1.Value);

var harmony = new Harmony("test");
var processor = new PatchClassProcessor(harmony, typeof(NullableResultsPatch));
var patches = processor.Patch();
Assert.NotNull(patches, "patches");
Assert.AreEqual(1, patches.Count);

var res2 = new NullableResults().Method();
Assert.True(res2.HasValue);
Assert.True(res2.Value);
}
}
}
18 changes: 18 additions & 0 deletions HarmonyTests/Patching/Assets/ArgumentCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ public static void Postfix([HarmonyArgument("__instance")] RenamedArguments foo2
}
}

public class NullableResults
{
private string s = "foo";

[MethodImpl(MethodImplOptions.NoInlining)]
public bool? Method() => false;
}

[HarmonyPatch(typeof(NullableResults), nameof(NullableResults.Method))]
public static class NullableResultsPatch
{
public static bool Prefix(ref bool? __result)
{
__result = true;
return false;
}
}

public class ArgumentArrayMethods
{
public struct SomeStruct
Expand Down

0 comments on commit 4852c9c

Please sign in to comment.