Skip to content

Commit 9b1e8ec

Browse files
author
Maksim Volkau
committed
added tests (passing) from the #492 PR by @ayyyabean-alt
1 parent 12b7248 commit 9b1e8ec

File tree

2 files changed

+86
-11
lines changed

2 files changed

+86
-11
lines changed

test/FastExpressionCompiler.IssueTests/Issue490_Regression_in_compiling_lambdas_with_ref_struct_parameters.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public struct Issue490_Regression_in_compiling_lambdas_with_ref_struct_parameter
1717
{
1818
public void Run(TestRun t)
1919
{
20+
Return_true_when_token_is_null();
21+
Return_false_when_token_is_not_null();
2022
Original_case(t);
2123
}
2224

@@ -74,5 +76,79 @@ public void Original_case(TestContext t)
7476
var b = ff(ref reader);
7577
t.AreEqual(default, b);
7678
}
79+
80+
public delegate bool RefStructReaderDelegate(ref MyJsonReader reader);
81+
82+
public enum MyJsonTokenType : byte
83+
{
84+
None = 0,
85+
StartObject = 1,
86+
Null = 11
87+
}
88+
89+
public ref struct MyJsonReader
90+
{
91+
public MyJsonTokenType TokenType { get; set; }
92+
}
93+
94+
public void Return_true_when_token_is_null(TestContext t = default)
95+
{
96+
var readerParam = Parameter(typeof(MyJsonReader).MakeByRefType(), "reader");
97+
var tokenType = Property(readerParam, nameof(MyJsonReader.TokenType));
98+
var nullToken = Constant(MyJsonTokenType.Null);
99+
100+
var body = Condition(
101+
Equal(tokenType, nullToken),
102+
Constant(true),
103+
Constant(false));
104+
105+
var lambda = Lambda<RefStructReaderDelegate>(body, readerParam);
106+
lambda.PrintCSharp();
107+
108+
var fs = lambda.CompileSys();
109+
fs.PrintIL();
110+
111+
var reader = new MyJsonReader();
112+
reader.TokenType = MyJsonTokenType.Null;
113+
114+
var a = fs(ref reader);
115+
t.AreEqual(true, a);
116+
117+
var ff = lambda.CompileFast();
118+
ff.PrintIL();
119+
120+
var b = ff(ref reader);
121+
t.AreEqual(true, b);
122+
}
123+
124+
public void Return_false_when_token_is_not_null(TestContext t = default)
125+
{
126+
var readerParam = Parameter(typeof(MyJsonReader).MakeByRefType(), "reader");
127+
var tokenType = Property(readerParam, nameof(MyJsonReader.TokenType));
128+
var nullToken = Constant(MyJsonTokenType.Null);
129+
130+
var body = Condition(
131+
Equal(tokenType, nullToken),
132+
Constant(true),
133+
Constant(false));
134+
135+
var lambda = Lambda<RefStructReaderDelegate>(body, readerParam);
136+
lambda.PrintCSharp();
137+
138+
var fs = lambda.CompileSys();
139+
fs.PrintIL();
140+
141+
var reader = new MyJsonReader();
142+
reader.TokenType = MyJsonTokenType.StartObject;
143+
144+
var a = fs(ref reader);
145+
t.AreEqual(false, a);
146+
147+
var ff = lambda.CompileFast();
148+
ff.PrintIL();
149+
150+
var b = ff(ref reader);
151+
t.AreEqual(false, b);
152+
}
77153
}
78154
#endif

test/FastExpressionCompiler.TestsRunner/Program.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void Main()
1818
// ILGeneratorTools.DisableILGeneratorPooling = true;
1919
// LightExpression.ILGeneratorTools.DisableILGeneratorPooling = true;
2020

21-
new ConditionalOperatorsTests().Run();
21+
// new ConditionalOperatorsTests().Run();
2222
// new ConstantAndConversionTests().Run();
2323
// new Issue284_Invalid_Program_after_Coalesce().Run(); // test print cs
2424
// new Issue440_Errors_with_simplified_Switch_cases().Run(); // test print cs
@@ -34,16 +34,6 @@ public static void Main()
3434
// new Issue441_Fails_to_pass_Constant_as_call_parameter_by_reference().Run();
3535
// new Issue461_InvalidProgramException_when_null_checking_type_by_ref().Run();
3636

37-
38-
var st = new TestRun(TestFlags.RethrowException);
39-
40-
st.Run(new Issue480_CLR_detected_an_invalid_program_exception());
41-
42-
#if NET8_0_OR_GREATER
43-
st.Run(new Issue487_Fix_ToCSharpString_output_for_boolean_equality_expressions());
44-
st.Run(new Issue475_Reuse_DynamicMethod_if_possible());
45-
#endif
46-
4737
var lt = new LightExpression.TestRun(LightExpression.TestFlags.RethrowException);
4838

4939
#if NET8_0_OR_GREATER
@@ -56,6 +46,15 @@ public static void Main()
5646
lt.Run(new LightExpression.IssueTests.Issue473_InvalidProgramException_when_using_Expression_Condition_with_converted_decimal_expression());
5747
lt.Run(new LightExpression.IssueTests.Issue476_System_ExecutionEngineException_with_nullables_on_repeated_calls_to_ConcurrentDictionary());
5848

49+
var st = new TestRun(TestFlags.RethrowException);
50+
51+
st.Run(new Issue480_CLR_detected_an_invalid_program_exception());
52+
53+
#if NET8_0_OR_GREATER
54+
st.Run(new Issue487_Fix_ToCSharpString_output_for_boolean_equality_expressions());
55+
st.Run(new Issue475_Reuse_DynamicMethod_if_possible());
56+
#endif
57+
5958
RunAllTests();
6059
}
6160

0 commit comments

Comments
 (0)