Skip to content

Commit 781f007

Browse files
committed
added the test for the #305
1 parent 8aa8eaa commit 781f007

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Linq.Expressions;
4+
#if LIGHT_EXPRESSION
5+
using System.Text;
6+
using static FastExpressionCompiler.LightExpression.Expression;
7+
namespace FastExpressionCompiler.LightExpression.IssueTests
8+
#else
9+
using static System.Linq.Expressions.Expression;
10+
namespace FastExpressionCompiler.IssueTests
11+
#endif
12+
{
13+
[TestFixture]
14+
public class Issue305_CompileFast_generates_incorrect_code_with_arrays_and_printing : ITest
15+
{
16+
public int Run()
17+
{
18+
Test1();
19+
return 1;
20+
}
21+
22+
// [Test]
23+
public void Test1()
24+
{
25+
var arr = Variable(typeof(double[]), "arr");
26+
27+
var printDouble = typeof(Console).GetMethod(nameof(Console.WriteLine), new[] { typeof(double) });
28+
29+
var expr = Lambda<Func<double>>(
30+
Block(new[] { arr },
31+
Assign(arr, NewArrayBounds(typeof(double), Constant(1))),
32+
Assign(ArrayAccess(arr, Constant(0)), Constant(123.456)),
33+
34+
Call(printDouble, ArrayAccess(arr, Constant(0))),
35+
Call(printDouble, ArrayAccess(arr, Constant(0))),
36+
Call(printDouble, ArrayAccess(arr, Constant(0))),
37+
Call(printDouble, ArrayAccess(arr, Constant(0))),
38+
Call(printDouble, ArrayAccess(arr, Constant(0))),
39+
Call(printDouble, ArrayAccess(arr, Constant(0))),
40+
Call(printDouble, ArrayAccess(arr, Constant(0))),
41+
42+
ArrayAccess(arr, Constant(0))
43+
));
44+
45+
expr.PrintCSharp();
46+
47+
var fs = expr.CompileSys();
48+
fs.PrintIL();
49+
50+
var res = fs();
51+
Assert.AreEqual(123.456, res);
52+
53+
var ff = expr.CompileFast(true);
54+
ff.PrintIL();
55+
56+
var res2 = ff();
57+
Assert.AreEqual(123.456, res2);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)