Skip to content

Commit

Permalink
more cases converted
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Oct 23, 2024
1 parent 5d2114f commit 88bea4d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using NUnit.Framework;

#if LIGHT_EXPRESSION
using static FastExpressionCompiler.LightExpression.Expression;
namespace FastExpressionCompiler.LightExpression.IssueTests
#else
using static System.Linq.Expressions.Expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using NUnit.Framework;

#if LIGHT_EXPRESSION
using FastExpressionCompiler.LightExpression;
using static FastExpressionCompiler.LightExpression.Expression;
namespace FastExpressionCompiler.LightExpression.IssueTests
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

#if !LIGHT_EXPRESSION
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using NUnit.Framework;

#if LIGHT_EXPRESSION
using static FastExpressionCompiler.LightExpression.Expression;
namespace FastExpressionCompiler.LightExpression.IssueTests
#else
using System.Linq.Expressions;
using static System.Linq.Expressions.Expression;
namespace FastExpressionCompiler.IssueTests
#endif
{
[TestFixture]
public class Issue341_Equality_comparison_between_nullable_and_null_inside_Any_produces_incorrect_compiled_expression : ITest
Expand Down Expand Up @@ -36,7 +38,7 @@ public int Run()

public enum Ops { Equal, NotEqual, Greater, Less, GreaterOrEqual, LessOrEqual }

public static Expression<Func<decimal?, decimal?, bool>>[] twoParamsExpressions =
public static System.Linq.Expressions.Expression<Func<decimal?, decimal?, bool>>[] sysTwoParamsExpressions =
{
(a, b) => a == b,
(a, b) => a != b,
Expand All @@ -46,6 +48,9 @@ public enum Ops { Equal, NotEqual, Greater, Less, GreaterOrEqual, LessOrEqual }
(a, b) => a <= b,
};

public static Expression<Func<decimal?, decimal?, bool>>[] twoParamsExpressions =
sysTwoParamsExpressions.Select(e => e.FromSysExpression()).ToArray();

public static ParameterExpression aParam = Parameter(typeof(decimal?), "a");
public static Func<decimal?, Expression<Func<decimal?, bool>>>[] oneParamExpressions =
{
Expand Down Expand Up @@ -83,7 +88,7 @@ public void Nullable_decimal_parameters_comparison_cases(decimal? a, Ops op, dec
var expression = oneParamExpressions[(int)op](b);
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

compiledSys.PrintIL("sys");
Expand All @@ -102,7 +107,7 @@ public void Nullable_decimal_parameter_with_decimal_constant_comparison_cases(de
var expression = twoParamsExpressions[(int)op];
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

compiledSys.PrintIL("sys");
Expand All @@ -118,10 +123,11 @@ public void Nullable_decimal_parameter_with_decimal_constant_comparison_cases(de
[Test]
public void Nullable_decimal_not_equal_to_zero()
{
Expression<Func<decimal?, bool>> expression = n => n != 0M;
System.Linq.Expressions.Expression<Func<decimal?, bool>> sExpression = n => n != 0M;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = default(decimal);
Expand All @@ -139,10 +145,11 @@ public void Nullable_decimal_not_equal_to_zero()
[Test]
public void Nullable_decimal_greater_than_zero()
{
Expression<Func<decimal?, bool>> expression = n => n > 0M;
System.Linq.Expressions.Expression<Func<decimal?, bool>> sExpression = n => n > 0M;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = default(decimal);
Expand All @@ -160,10 +167,11 @@ public void Nullable_decimal_greater_than_zero()
[Test]
public void Nullable_decimal_not_equal_decimal()
{
Expression<Func<decimal?, bool>> expression = n => n != 1.11M;
System.Linq.Expressions.Expression<Func<decimal?, bool>> sExpression = n => n != 1.11M;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = 1.111M;
Expand All @@ -181,10 +189,11 @@ public void Nullable_decimal_not_equal_decimal()
[Test]
public void Nullable_decimal_less_then_decimal()
{
Expression<Func<decimal?, bool>> expression = n => n < 1.11M;
System.Linq.Expressions.Expression<Func<decimal?, bool>> sExpression = n => n < 1.11M;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = 1.101M;
Expand All @@ -202,10 +211,11 @@ public void Nullable_decimal_less_then_decimal()
[Test]
public void Nullable_decimal_not_equal_to_null()
{
Expression<Func<decimal?, bool>> expression = n => n != null;
System.Linq.Expressions.Expression<Func<decimal?, bool>> sExpression = n => n != null;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = default(decimal);
Expand All @@ -223,10 +233,11 @@ public void Nullable_decimal_not_equal_to_null()
[Test]
public void Null_not_equal_to_nullable_decimal()
{
Expression<Func<decimal?, bool>> expression = n => null != n;
System.Linq.Expressions.Expression<Func<decimal?, bool>> sExpression = n => null != n;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = default(decimal);
Expand All @@ -244,10 +255,11 @@ public void Null_not_equal_to_nullable_decimal()
[Test]
public void Nullable_decimal_equal_to_null()
{
Expression<Func<decimal?, bool>> expression = n => n == null;
System.Linq.Expressions.Expression<Func<decimal?, bool>> sExpression = n => n == null;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = default(decimal);
Expand All @@ -266,10 +278,11 @@ public void Nullable_decimal_equal_to_null()
public void Nullable_decimal_member_not_equal_to_null()
{
// todo: @perf optimize comparison of nullable with null
Expression<Func<Test2, bool>> expression = t => t.Value != null;
System.Linq.Expressions.Expression<Func<Test2, bool>> sExpression = t => t.Value != null;
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
var compiledFast = expression.CompileFast(true);

var instance = new Test2() { Value = 0 };
Expand All @@ -287,10 +300,11 @@ public void Nullable_decimal_member_not_equal_to_null()
[Test]
public void Nullable_decimal_member_not_equal_to_null_inside_predicate()
{
Expression<Func<Test, bool>> expression = t => t.A.Any(e => e.Value != null);
System.Linq.Expressions.Expression<Func<Test, bool>> sExpression = t => t.A.Any(e => e.Value != null);
var expression = sExpression.FromSysExpression();
expression.PrintCSharp(); // just for debug

var compiledSys = expression.Compile();
var compiledSys = expression.CompileSys();
compiledSys.PrintIL("sys");

var compiledFast = expression.CompileFast(true, CompilerFlags.EnableDelegateDebugInfo);
Expand Down Expand Up @@ -326,5 +340,4 @@ public class Test2
public decimal? Value { get; set; }
}
}
}
#endif
}

0 comments on commit 88bea4d

Please sign in to comment.