Skip to content

Commit

Permalink
adding another test
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Dec 22, 2024
1 parent e458d7d commit 75e314e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_v
{
public int Run()
{
More_simplified_test_no_inlining_for_SystemCompile_with_Execute_no_assigning();

More_simplified_test_no_inlining_for_SystemCompile_with_Execute();
More_simplified_test_no_inlining();
Simplified_test_no_inlining();
Expand All @@ -23,18 +25,60 @@ public int Run()
Nested_lambda_with_shared_variable_Workaround_with_struct();
Nested_lambda_with_shared_variable();
Nested_lambda_with_shared_variable_Workaround();
return 7;

return 8;
}

public class TestClass
{
public static void Execute(Action action) => action();
public static void ExecuteAction(Action action) => action();
public static int ExecuteFunc(Func<int> func) => func();
}

[Test]
public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute_no_assigning()
{
var execute = typeof(TestClass).GetMethod(nameof(TestClass.ExecuteFunc));

var myVar = Variable(typeof(int), "myVar");
var expr = Lambda<Func<int>>(
Block(
new[] { myVar },
Assign(myVar, Constant(5)),
Call(execute, Lambda<Func<int>>(Add(myVar, Constant(3)))),
myVar
)
);

expr.PrintCSharp();
// outputs:
var @cs = (Func<int>)(() => //int
{
int myVar = default;
myVar = 5;
TestClass.ExecuteFunc((Func<int>)(() => //int
myVar + 3));
return myVar;
});
Assert.AreEqual(5, @cs());

var fs = expr.CompileSys();
fs.PrintIL();

var sr = fs();
Assert.AreEqual(5, sr);

var ff = expr.CompileFast(false);
ff.PrintIL();

var fr = ff();
Assert.AreEqual(5, fr);
}

[Test]
public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute()
{
var execute = typeof(TestClass).GetMethod(nameof(TestClass.Execute));
var execute = typeof(TestClass).GetMethod(nameof(TestClass.ExecuteAction));

var myVar = Variable(typeof(int), "myVar");
var expr = Lambda<Func<int>>(
Expand All @@ -53,7 +97,7 @@ public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute()
var sr = fs();
Assert.AreEqual(3, sr);

var ff = expr.CompileFast(false, CompilerFlags.NoInvocationLambdaInlining);
var ff = expr.CompileFast(false);
ff.PrintIL();

var fr = ff();
Expand Down
2 changes: 1 addition & 1 deletion test/FastExpressionCompiler.TestsRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Program
public static void Main()
{
new LightExpression.IssueTests.Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values().Run();
new LightExpression.IssueTests.Issue353_NullReferenceException_when_calling_CompileFast_results().Run();
// new LightExpression.IssueTests.Issue353_NullReferenceException_when_calling_CompileFast_results().Run();
// new LightExpression.UnitTests.ArithmeticOperationsTests().Run();

RunAllTests();
Expand Down

0 comments on commit 75e314e

Please sign in to comment.