From 4ff94aa23d0c662c9b5824861ccafc1ee6fa1b01 Mon Sep 17 00:00:00 2001 From: Washi Date: Fri, 22 Mar 2024 17:56:46 +0100 Subject: [PATCH] Add nested class constructors test. --- .../Emulation/CilVirtualMachineTest.cs | 17 +++++++++++++++++ .../Mocks/ClassWithNestedInitializer.cs | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/Platforms/Mocks/ClassWithNestedInitializer.cs diff --git a/test/Platforms/Echo.Platforms.AsmResolver.Tests/Emulation/CilVirtualMachineTest.cs b/test/Platforms/Echo.Platforms.AsmResolver.Tests/Emulation/CilVirtualMachineTest.cs index 4199ffdd..496189d5 100644 --- a/test/Platforms/Echo.Platforms.AsmResolver.Tests/Emulation/CilVirtualMachineTest.cs +++ b/test/Platforms/Echo.Platforms.AsmResolver.Tests/Emulation/CilVirtualMachineTest.cs @@ -588,6 +588,23 @@ public void CallAndThrowUnhandledException(string methodName, object parameter) Assert.Equal(expectedException.GetType().FullName, result.ExceptionObject.GetObjectType().FullName); } + [Fact] + public void SteppingWithNestedInitializers() + { + // Look up metadata. + var method = _fixture + .MockModule.LookupMember(typeof(ClassWithNestedInitializer.Class1).MetadataToken) + .Methods.First(m => m.Name == nameof(ClassWithNestedInitializer.Class1.Method)); + + // CAll method. + _vm.Invoker = DefaultInvokers.StepIn; + var result = _mainThread.Call(method, Array.Empty()); + + // Verify. + Assert.NotNull(result); + Assert.Equal(1337, result.AsSpan().I32); + } + [Fact] public void StaticFieldWithInitialValueUpdate() { diff --git a/test/Platforms/Mocks/ClassWithNestedInitializer.cs b/test/Platforms/Mocks/ClassWithNestedInitializer.cs new file mode 100644 index 00000000..8e1a5b11 --- /dev/null +++ b/test/Platforms/Mocks/ClassWithNestedInitializer.cs @@ -0,0 +1,16 @@ +namespace Mocks; + + public class ClassWithNestedInitializer + { + public class Class1 + { + public static int Field = Class2.Field; + + public static int Method() => Field; + } + + public class Class2 + { + public static int Field = 1337; + } + } \ No newline at end of file