Skip to content

Commit

Permalink
added the test for the #307
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Jul 21, 2021
1 parent b90ba8c commit 3a04eed
Showing 1 changed file with 56 additions and 0 deletions.
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);
}
}
}

0 comments on commit 3a04eed

Please sign in to comment.