Skip to content

Commit

Permalink
Add GetGenericTypeDefinition() intrinsic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jan 18, 2024
1 parent 859adb8 commit 93ae46f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/tests/JIT/Intrinsics/TypeIntrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public static int TestEntryPoint()
GetEnumUnderlyingType.TestGetEnumUnderlyingType();

IsPrimitiveTests();
GetGenericTypeDefinitionTests();

return 100 + _errors;
}
Expand Down Expand Up @@ -186,6 +187,30 @@ private static void IsPrimitiveTests()
IsFalse(typeof(Dictionary<,>).IsPrimitive);
}

private static void GetGenericTypeDefinitionTests()
{
AreEqual(typeof(GenericEnumClass<SimpleEnum>).GetGenericTypeDefinition(), typeof(GenericEnumClass<>));
AreEqual(typeof(GenericEnumClass<>).GetGenericTypeDefinition(), typeof(GenericEnumClass<>));
AreEqual(typeof(IGenericInterface<string>).GetGenericTypeDefinition(), typeof(IGenericInterface<>));
AreEqual(typeof(IGenericInterface<>).GetGenericTypeDefinition(), typeof(IGenericInterface<>));
AreEqual(typeof(GenericStruct<string>).GetGenericTypeDefinition(), typeof(GenericStruct<>));
AreEqual(typeof(GenericStruct<>).GetGenericTypeDefinition(), typeof(GenericStruct<>));
AreEqual(typeof(SimpleEnum?).GetGenericTypeDefinition(), typeof(Nullable<>));
AreEqual(typeof(int?).GetGenericTypeDefinition(), typeof(Nullable<>));
AreEqual(typeof(IntPtr?).GetGenericTypeDefinition(), typeof(Nullable<>));
AreEqual(typeof(Nullable<>).GetGenericTypeDefinition(), typeof(Nullable<>));
AreEqual(typeof(KeyValuePair<int,string>).GetGenericTypeDefinition(), typeof(KeyValuePair<,>));
AreEqual(typeof(KeyValuePair<,>).GetGenericTypeDefinition(), typeof(KeyValuePair<,>));
AreEqual(typeof(Dictionary<int,string>).GetGenericTypeDefinition(), typeof(Dictionary<,>));
AreEqual(typeof(Dictionary<,>).GetGenericTypeDefinition(), typeof(Dictionary<,>));
AreEqual(typeof(List<string>).GetGenericTypeDefinition(), typeof(List<>));
AreEqual(typeof(List<>).GetGenericTypeDefinition(), typeof(List<>));
AreEqual(typeof(Action<>).GetGenericTypeDefinition(), typeof(Action<>));
AreEqual(typeof(Action<string>).GetGenericTypeDefinition(), typeof(Action<>));
AreEqual(typeof(Func<string, int>).GetGenericTypeDefinition(), typeof(Func<,>));
AreEqual(typeof(Func<,>).GetGenericTypeDefinition(), typeof(Func<,>));
}

private static int _varInt = 42;
private static int? _varNullableInt = 42;
private static decimal _varDecimal = 42M;
Expand Down Expand Up @@ -239,6 +264,16 @@ static void IsFalse(bool expression, [CallerLineNumber] int line = 0, [CallerFil
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void AreEqual(Type left, Type right, [CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
{
if (left != right)
{
Console.WriteLine($"{file}:L{line} test failed (expected: '{left}' to be equal to '{right}').");
_errors++;
}
}

static void ThrowsNRE(Action action, [CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
{
try
Expand Down

0 comments on commit 93ae46f

Please sign in to comment.