-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...piler.IssueTests/Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile.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,60 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using NUnit.Framework; | ||
|
||
#if LIGHT_EXPRESSION | ||
using FastExpressionCompiler.LightExpression; | ||
using static FastExpressionCompiler.LightExpression.Expression; | ||
namespace FastExpressionCompiler.LightExpression.IssueTests; | ||
#else | ||
using static System.Linq.Expressions.Expression; | ||
namespace FastExpressionCompiler.IssueTests; | ||
#endif | ||
|
||
[TestFixture] | ||
public class Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile : ITest | ||
{ | ||
public int Run() | ||
{ | ||
Original_case(); | ||
return 1; | ||
} | ||
|
||
public class HasDateTime | ||
{ | ||
public DateTime? T { get; } | ||
public HasDateTime(DateTime? t) => T = t; | ||
} | ||
|
||
[Test] | ||
public void Original_case() | ||
{ | ||
var time = DateTime.UtcNow; | ||
|
||
var p = new ParameterExpression[1]; // the parameter expressions | ||
var e = new Expression[3]; // the unique expressions | ||
var expr = Lambda<Func<HasDateTime, bool>>( | ||
e[0] = MakeBinary(ExpressionType.Equal, | ||
e[1] = Property( | ||
p[0] = Parameter(typeof(HasDateTime), nameof(HasDateTime)), | ||
typeof(HasDateTime).GetProperty(nameof(HasDateTime.T))), | ||
e[2] = Constant(time, typeof(DateTime?)), | ||
liftToNull: false, | ||
typeof(DateTime).GetMethods().Single(x => !x.IsGenericMethod && x.Name == "op_Equality" && x.GetParameters().Select(y => y.ParameterType).SequenceEqual(new[] { typeof(System.DateTime), typeof(System.DateTime) }))), | ||
p[0 // (HasDateTime) | ||
]); | ||
|
||
expr.PrintCSharp(); | ||
|
||
var fs = expr.CompileSys(); | ||
fs.PrintIL(); | ||
|
||
var ff = expr.CompileFast(true, CompilerFlags.ThrowOnNotSupportedExpression); | ||
ff.PrintIL(); | ||
|
||
var hasDT = new HasDateTime(time); | ||
Assert.IsTrue(fs(hasDT)); | ||
Assert.IsTrue(ff(hasDT)); | ||
} | ||
} |
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
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