From 2edea43ded18e1bb349e90a4232eaea7fa6ba6f2 Mon Sep 17 00:00:00 2001 From: Charles Stoner Date: Mon, 23 Sep 2019 09:24:45 -0700 Subject: [PATCH] Additional enum tests for System.Linq.Expressions.Interpreter.CallInstruction (dotnet/corefx#41218) Commit migrated from https://github.com/dotnet/corefx/commit/f9919e1ce5ca407f55d078af003af642c1b44d92 --- .../tests/Call/CallTests.cs | 55 ++++++++++++++++------ 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/libraries/System.Linq.Expressions/tests/Call/CallTests.cs b/src/libraries/System.Linq.Expressions/tests/Call/CallTests.cs index b67b1d8..bae12c9 100644 --- a/src/libraries/System.Linq.Expressions/tests/Call/CallTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Call/CallTests.cs @@ -665,37 +665,62 @@ namespace System.Linq.Expressions.Tests } } - [Fact] - public static void EnumReturnType0() + [Theory] + [ClassData(typeof(CompilationTypes))] + public static void EnumReturnType0(bool useInterpreter) { Expression> expr = () => new[] { ToDayOfWeek0() }; - - Assert.Equal(DayOfWeek.Monday, expr.Compile(false)()[0]); - Assert.Equal(DayOfWeek.Monday, expr.Compile(true)()[0]); + Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0]); } - [Fact] - public static void EnumReturnType1() + [Theory] + [ClassData(typeof(CompilationTypes))] + public static void EnumReturnType1(bool useInterpreter) { Expression> expr = () => new[] { ToDayOfWeek1(1) }; - - Assert.Equal(DayOfWeek.Monday, expr.Compile(false)()[0]); - Assert.Equal(DayOfWeek.Monday, expr.Compile(true)()[0]); + Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0]); } - [Fact] - public static void EnumReturnType2() + [Theory] + [ClassData(typeof(CompilationTypes))] + public static void EnumReturnType2(bool useInterpreter) { Expression> expr = () => new[] { ToDayOfWeek2(0, 1) }; - - Assert.Equal(DayOfWeek.Monday, expr.Compile(false)()[0]); - Assert.Equal(DayOfWeek.Monday, expr.Compile(true)()[0]); + Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0]); } private static DayOfWeek ToDayOfWeek0() => DayOfWeek.Monday; private static DayOfWeek ToDayOfWeek1(int i) => (DayOfWeek)i; private static DayOfWeek ToDayOfWeek2(int i, int j) => (DayOfWeek)(i + j); + [Theory] + [ClassData(typeof(CompilationTypes))] + public static void NullableEnumReturnType0(bool useInterpreter) + { + Expression> expr = () => new[] { ToDayOfWeekOpt0() }; + Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0].Value); + } + + [Theory] + [ClassData(typeof(CompilationTypes))] + public static void NullableEnumReturnType1(bool useInterpreter) + { + Expression> expr = () => new[] { ToDayOfWeekOpt1(1) }; + Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0].Value); + } + + [Theory] + [ClassData(typeof(CompilationTypes))] + public static void NullableEnumReturnType2(bool useInterpreter) + { + Expression> expr = () => new[] { ToDayOfWeekOpt2(0, 1) }; + Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0].Value); + } + + private static DayOfWeek? ToDayOfWeekOpt0() => DayOfWeek.Monday; + private static DayOfWeek? ToDayOfWeekOpt1(int i) => (DayOfWeek)i; + private static DayOfWeek? ToDayOfWeekOpt2(int i, int j) => (DayOfWeek)(i + j); + public class GenericClass { public static void NonGenericMethod() { } -- 2.7.4