Skip to content

Commit 3a04eed

Browse files
committed
added the test for the #307
1 parent b90ba8c commit 3a04eed

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Linq;
4+
using System.Collections.Generic;
5+
#if LIGHT_EXPRESSION
6+
using static FastExpressionCompiler.LightExpression.Expression;
7+
namespace FastExpressionCompiler.LightExpression.IssueTests
8+
#else
9+
using static System.Linq.Expressions.Expression;
10+
namespace FastExpressionCompiler.IssueTests
11+
#endif
12+
{
13+
[TestFixture]
14+
public class Issue307_Switch_with_fall_through_throws_InvalidProgramException : ITest
15+
{
16+
public int Run()
17+
{
18+
Test1();
19+
return 1;
20+
}
21+
22+
// [Test]
23+
public void Test1()
24+
{
25+
var param = Parameter(typeof(int), "p");
26+
var label = Label(typeof(string));
27+
28+
var switchStatement = Switch(
29+
typeof(void),
30+
param,
31+
Return(label, Constant("bar")),
32+
null,
33+
SwitchCase(Return(label, Constant("foo")), Constant(1), Constant(2)));
34+
35+
var lambda = Lambda<Func<int, string>>(
36+
Block(
37+
switchStatement,
38+
Label(label, Constant(string.Empty))),
39+
param);
40+
41+
lambda.PrintCSharp();
42+
43+
var compiled = lambda.CompileSys();
44+
compiled.PrintIL();
45+
46+
var res = compiled(1);
47+
Assert.AreEqual("foo", res);
48+
49+
var compiledFast = lambda.CompileFast();
50+
compiledFast.PrintIL();
51+
52+
var resFast = compiledFast(1);
53+
Assert.AreEqual("foo", resFast);
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)