From 3a04eed4296d51bb9670bcaef38320243a17d138 Mon Sep 17 00:00:00 2001 From: dadhi Date: Wed, 21 Jul 2021 11:03:03 +0300 Subject: [PATCH] added the test for the #307 --- ..._through_throws_InvalidProgramException.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/FastExpressionCompiler.IssueTests/Issue307_Switch_with_fall_through_throws_InvalidProgramException.cs diff --git a/test/FastExpressionCompiler.IssueTests/Issue307_Switch_with_fall_through_throws_InvalidProgramException.cs b/test/FastExpressionCompiler.IssueTests/Issue307_Switch_with_fall_through_throws_InvalidProgramException.cs new file mode 100644 index 00000000..3d18fb8d --- /dev/null +++ b/test/FastExpressionCompiler.IssueTests/Issue307_Switch_with_fall_through_throws_InvalidProgramException.cs @@ -0,0 +1,56 @@ +using NUnit.Framework; +using System; +using System.Linq; +using System.Collections.Generic; +#if LIGHT_EXPRESSION +using static FastExpressionCompiler.LightExpression.Expression; +namespace FastExpressionCompiler.LightExpression.IssueTests +#else +using static System.Linq.Expressions.Expression; +namespace FastExpressionCompiler.IssueTests +#endif +{ + [TestFixture] + public class Issue307_Switch_with_fall_through_throws_InvalidProgramException : ITest + { + public int Run() + { + Test1(); + return 1; + } + + // [Test] + public void Test1() + { + var param = Parameter(typeof(int), "p"); + var label = Label(typeof(string)); + + var switchStatement = Switch( + typeof(void), + param, + Return(label, Constant("bar")), + null, + SwitchCase(Return(label, Constant("foo")), Constant(1), Constant(2))); + + var lambda = Lambda>( + Block( + switchStatement, + Label(label, Constant(string.Empty))), + param); + + lambda.PrintCSharp(); + + var compiled = lambda.CompileSys(); + compiled.PrintIL(); + + var res = compiled(1); + Assert.AreEqual("foo", res); + + var compiledFast = lambda.CompileFast(); + compiledFast.PrintIL(); + + var resFast = compiledFast(1); + Assert.AreEqual("foo", resFast); + } + } +} \ No newline at end of file