From c261f0c205149648113407b16c364dfb1687988c Mon Sep 17 00:00:00 2001 From: peelz Date: Sat, 17 Sep 2022 00:08:48 -0400 Subject: [PATCH] Add tests for ambiguous Hook.Patch signatures --- .../BarotraumaTest/LuaCs/HookPatchTests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Barotrauma/BarotraumaTest/LuaCs/HookPatchTests.cs b/Barotrauma/BarotraumaTest/LuaCs/HookPatchTests.cs index 57537317d..de2169909 100644 --- a/Barotrauma/BarotraumaTest/LuaCs/HookPatchTests.cs +++ b/Barotrauma/BarotraumaTest/LuaCs/HookPatchTests.cs @@ -32,6 +32,7 @@ namespace TestProject.LuaCs UserData.RegisterType(); UserData.RegisterType(); UserData.RegisterType(); + UserData.RegisterType(); UserData.RegisterType(); UserData.RegisterType(); @@ -307,6 +308,41 @@ namespace TestProject.LuaCs Assert.Equal("{X:1 Y:2}", returnValue); } + private class PatchTargetAmbiguous + { + public PatchTargetAmbiguous() { } + + public PatchTargetAmbiguous(int a) { } + + public void Blah() { } + + public void Blah(int a) { } + } + + [Fact] + public void TestPatchAmbiguous() + { + using var patchTargetHandle = HookPatchHelpers.LockPatchTarget(); + + Assert.Throws(() => + { + using var postfixHandle = luaCs.AddPostfix("", ".ctor"); + }); + Assert.Throws(() => + { + using var prefixHandle = luaCs.AddPrefix("", ".ctor"); + }); + + Assert.Throws(() => + { + using var postfixHandle = luaCs.AddPostfix("", nameof(PatchTargetAmbiguous.Blah)); + }); + Assert.Throws(() => + { + using var prefixHandle = luaCs.AddPrefix("", nameof(PatchTargetAmbiguous.Blah)); + }); + } + private class PatchTargetConstructor { public enum CtorType