-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CecilEmitter.Dump: Adding test for ILLabel dumping
- Loading branch information
1 parent
c4392ee
commit 6746d17
Showing
2 changed files
with
58 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using HarmonyLib.Internal.Util; | ||
using HarmonyLibTests; | ||
using MonoMod.Cil; | ||
using MonoMod.Utils; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
|
||
|
||
namespace HarmonyTests.Extras; | ||
|
||
[TestFixture] | ||
public class Dump : TestLogger | ||
{ | ||
[Test] | ||
public void Test_DumpIlLabel() | ||
{ | ||
using var dmd = new DynamicMethodDefinition("DumpIlLabelTestMethod", typeof(void), Type.EmptyTypes); | ||
var il = new ILContext(dmd.Definition); | ||
var cur = new ILCursor(il); | ||
|
||
var label = cur.DefineLabel(); | ||
cur.EmitBr(label); | ||
cur.EmitRet(); | ||
label.Target = cur.Prev; | ||
|
||
var method = cur.Method; | ||
|
||
using var dumpedModule = CecilEmitter.DumpImpl(method); | ||
var dumpedMethod = dumpedModule.Types.SelectMany(i => i.Methods).FirstOrDefault(); | ||
Assert.NotNull(dumpedMethod); | ||
|
||
var instructions = dumpedMethod!.Body.Instructions; | ||
Assert.True(instructions[0].Operand == instructions[1]); | ||
} | ||
} |