Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Jul 27, 2024
1 parent f713475 commit 6191eb0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/InlineIL.Tests.Common/ReferencedAssemblyType.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
namespace InlineIL.Tests.Common;

public class TypeFromReferencedAssembly
public unsafe class TypeFromReferencedAssembly
{
public readonly StructFromReferencedAssembly FieldWithTypeFromThisAssembly = default;
public readonly StructFromReferencedAssembly* PointerField = default;
}

public unsafe class TypeFromReferencedAssembly<T>
where T : unmanaged
{
public readonly T* PointerField = default;
}

public struct StructFromReferencedAssembly;
public struct OtherStructFromReferencedAssembly;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using InlineIL.Tests.Common;
using static InlineIL.IL.Emit;
Expand All @@ -18,4 +19,30 @@ public void ReadFieldFromReferencedAssemblyType()
Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.FieldWithTypeFromThisAssembly)));
Pop();
}

public void ReadPointerFieldFromReferencedAssemblyType()
{
IL.Push(new TypeFromReferencedAssembly());
Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.PointerField)));
Pop();
}

public void ReadGenericPointerFieldFromReferencedAssemblyType()
{
IL.Push(new TypeFromReferencedAssembly<OtherStructFromReferencedAssembly>());
Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly<OtherStructFromReferencedAssembly>), nameof(TypeFromReferencedAssembly<OtherStructFromReferencedAssembly>.PointerField)));
Pop();

IL.Push(new TypeFromReferencedAssembly<DateTime>());
Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly<DateTime>), nameof(TypeFromReferencedAssembly<DateTime>.PointerField)));
Pop();

IL.Push(new TypeFromReferencedAssembly<InternalStruct>());
Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly<InternalStruct>), nameof(TypeFromReferencedAssembly<InternalStruct>.PointerField)));
Pop();
}
}

internal struct InternalStruct
{
}
14 changes: 14 additions & 0 deletions src/InlineIL.Tests/Weaving/FieldRefTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ public void should_handle_fields_with_types_from_referenced_assemblies()
instance.ReadFieldFromReferencedAssemblyType();
}

[Fact]
public void should_handle_pointer_fields_with_types_from_referenced_assemblies()
{
var instance = GetUnverifiableInstance();
instance.ReadPointerFieldFromReferencedAssemblyType();
}

[Fact]
public void should_handle_generic_fields_with_types_from_referenced_assemblies()
{
var instance = GetUnverifiableInstance();
instance.ReadGenericPointerFieldFromReferencedAssemblyType();
}

[Fact]
public void should_reference_field_in_different_ways()
{
Expand Down

0 comments on commit 6191eb0

Please sign in to comment.