-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...onCompiler.IssueTests/Issue307_Switch_with_fall_through_throws_InvalidProgramException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Func<int, string>>( | ||
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); | ||
} | ||
} | ||
} |