Additional enum tests for System.Linq.Expressions.Interpreter.CallInstruction (dotnet...
authorCharles Stoner <chucks@microsoft.com>
Mon, 23 Sep 2019 16:24:45 +0000 (09:24 -0700)
committerGitHub <noreply@github.com>
Mon, 23 Sep 2019 16:24:45 +0000 (09:24 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/f9919e1ce5ca407f55d078af003af642c1b44d92

src/libraries/System.Linq.Expressions/tests/Call/CallTests.cs

index b67b1d8..bae12c9 100644 (file)
@@ -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<Func<DayOfWeek[]>> 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<Func<DayOfWeek[]>> 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<Func<DayOfWeek[]>> 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<Func<DayOfWeek?[]>> expr = () => new[] { ToDayOfWeekOpt0() };
+            Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0].Value);
+        }
+
+        [Theory]
+        [ClassData(typeof(CompilationTypes))]
+        public static void NullableEnumReturnType1(bool useInterpreter)
+        {
+            Expression<Func<DayOfWeek?[]>> expr = () => new[] { ToDayOfWeekOpt1(1) };
+            Assert.Equal(DayOfWeek.Monday, expr.Compile(useInterpreter)()[0].Value);
+        }
+
+        [Theory]
+        [ClassData(typeof(CompilationTypes))]
+        public static void NullableEnumReturnType2(bool useInterpreter)
+        {
+            Expression<Func<DayOfWeek?[]>> 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<T>
         {
             public static void NonGenericMethod() { }