Skip to content

Commit

Permalink
added failing test for #399
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Mar 30, 2024
1 parent 069080f commit ab971ef
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
10 changes: 8 additions & 2 deletions test/FastExpressionCompiler.ILDecoder/ILReaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@ public static StringBuilder ToILString(this MethodInfo method, StringBuilder s =
s.Append(' ').Append(sbr.TargetOffset);
else if (il is InlineStringInstruction si)
s.Append(" \"").Append(si.String).Append('"');
else if (il is InlineIInstruction ii)
s.Append(' ').Append(ii.Int32);
else if (il is ShortInlineIInstruction sii)
s.Append(' ').Append(sii.Byte);
else if (il is InlineIInstruction ii)
s.Append(' ').Append(ii.Int32);
else if (il is InlineI8Instruction i8)
s.Append(' ').Append(i8.Int64);
else if (il is ShortInlineRInstruction sir)
s.Append(' ').Append(sir.Single);
else if (il is InlineRInstruction ir)
s.Append(' ').Append(ir.Double);
else if (il is InlineVarInstruction iv)
s.Append(' ').Append(iv.Ordinal);
else if (il is ShortInlineVarInstruction siv)
Expand Down
3 changes: 3 additions & 0 deletions test/FastExpressionCompiler.TestsRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class Program
{
public static void Main()
{
new LightExpression.UnitTests.BinaryExpressionTests().Run();
// new LightExpression.IssueTests.Issue346_Is_it_possible_to_implement_ref_local_variables().Run();

RunAllTests();

// new Issue127_Switch_is_supported().Run();
Expand Down
41 changes: 40 additions & 1 deletion test/FastExpressionCompiler.UnitTests/BinaryExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BinaryExpressionTests : ITest
{
public int Run()
{
// Coalesce_for_nullable_long_Automapper_test_Should_substitute_zero_for_null();
Add_compiles();
AddAssign_compiles();
AddAssignChecked_compiles();
Expand Down Expand Up @@ -62,7 +63,7 @@ public int Run()
SubtractAssign_compiles();
SubtractAssignChecked_compiles();
SubtractChecked_compiles();
return 46;
return 47;
}

[Test]
Expand Down Expand Up @@ -394,6 +395,44 @@ public void MakeBinary_Coalesce_compiles()
Assert.AreEqual("<null>", result);
}

[Test]
public void Coalesce_for_nullable_long_Automapper_test_Should_substitute_zero_for_null()
{
var paramSource = Parameter(typeof(Source), "s");
var paramDest = Parameter(typeof(Destination), "d");
var tmpVar = Parameter(typeof(long?), "tmp");
var e = Lambda<Action<Source, Destination>>(
Block(new[] { tmpVar },
Assign(tmpVar, Coalesce(Property(paramSource, nameof(Source.Number)), Constant(0L, typeof(long?)))),
Assign(Property(paramDest, nameof(Destination.Number)), tmpVar)
),
paramSource, paramDest);

e.PrintCSharp();

var fs = e.CompileSys();
fs.PrintIL();
var d = new Destination();
fs(new Source(), d);
Assert.AreEqual(0, d.Number);

var ff = e.CompileFast(true);
ff.PrintIL();
d = new Destination();
ff(new Source(), d);
Assert.AreEqual(0, d.Number);
}

class Source
{
public long? Number { get; set; }
}
class Destination
{
public long? Number { get; set; }
}


[Test]
public void Modulo_compiles()
{
Expand Down

0 comments on commit ab971ef

Please sign in to comment.