Skip to content

Commit f8182b1

Browse files
Add tests for ExtensionEncodingV1 and ExtensionEncodingV2.
1 parent b07e8e4 commit f8182b1

File tree

9 files changed

+778
-19
lines changed

9 files changed

+778
-19
lines changed

ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ internal static async Task Initialize()
133133

134134
await vswhereToolset.Fetch().ConfigureAwait(false);
135135
await RefAssembliesToolset.Fetch("5.0.0", sourcePath: "ref/net5.0").ConfigureAwait(false);
136-
await RefAssembliesToolset.Fetch("10.0.0-preview.4.25258.110", sourcePath: "ref/net10.0").ConfigureAwait(false);
136+
await RefAssembliesToolset.Fetch("10.0.0-rc.2.25502.107", sourcePath: "ref/net10.0").ConfigureAwait(false);
137137

138138

139139
#if DEBUG

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
<None Include="TestCases\Disassembler\Pretty\InterfaceImplAttributes.il" />
9797
<None Include="TestCases\Disassembler\Pretty\SortMembers.expected.il" />
9898
<None Include="TestCases\Disassembler\Pretty\SortMembers.il" />
99+
<None Include="TestCases\ILPretty\ExtensionEncodingV2.il" />
100+
<None Include="testcases\ilpretty\ExtensionEncodingV1.il" />
99101
<None Include="TestCases\ILPretty\GuessAccessors.cs" />
100102
<None Include="TestCases\ILPretty\GuessAccessors.il" />
101103
<None Include="TestCases\ILPretty\Issue2260SwitchString.il" />
@@ -145,6 +147,8 @@
145147
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
146148
<Compile Include="ProjectDecompiler\WholeProjectDecompilerTests.cs" />
147149
<Compile Include="TestAssemblyResolver.cs" />
150+
<Compile Include="TestCases\ILPretty\ExtensionEncodingV2.cs" />
151+
<Compile Include="TestCases\ILPretty\ExtensionEncodingV1.cs" />
148152
<Compile Include="TestCases\ILPretty\Issue3344CkFinite.cs" />
149153
<Compile Include="TestCases\ILPretty\Issue3421.cs" />
150154
<Compile Include="TestCases\ILPretty\Issue3465.cs" />

ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,22 @@ public async Task MonoFixed()
323323
await Run();
324324
}
325325

326+
[Test]
327+
public async Task ExtensionEncodingV1()
328+
{
329+
// uses Microsoft.Net.Compilers.Toolset 5.0.0-2.25380.108
330+
// see ExtensionEncodingV1.il for details
331+
await Run();
332+
}
333+
334+
[Test]
335+
public async Task ExtensionEncodingV2()
336+
{
337+
// uses Microsoft.Net.Compilers.Toolset 5.0.0-2.25451.107
338+
// see ExtensionEncodingV2.il for details
339+
await Run();
340+
}
341+
326342
async Task Run([CallerMemberName] string testName = null, DecompilerSettings settings = null,
327343
AssemblerOptions assemblerOptions = AssemblerOptions.Library)
328344
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
5+
{
6+
internal static class ExtensionPropertiesV1
7+
{
8+
extension<T>(ICollection<T> collection) where T : notnull
9+
{
10+
public bool IsEmpty => collection.Count == 0;
11+
12+
public int Test {
13+
get {
14+
return 42;
15+
}
16+
set {
17+
}
18+
}
19+
20+
public void AddIfNotNull(T item)
21+
{
22+
if (item != null)
23+
{
24+
collection.Add(item);
25+
}
26+
}
27+
28+
public T2 Cast<T2>(int index) where T2 : T
29+
{
30+
return (T2)(object)collection.ElementAt(index);
31+
}
32+
33+
public static void StaticExtension()
34+
{
35+
}
36+
}
37+
}
38+
}
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
// To extend use:
2+
// see https://lab.razor.fyi/#fVHNbhMxEFYRqrBP0CcYbpsDVlioVDU_UrSNUBCqImVPnHC8k8TgtRd7tiSqcuMh-gbceQBeihdA66bJNlK5WDPzfTPffGP-65TzqXdLL0uhwtndaR20XcJsEwjLHm9nInPGoCLtbBAf0KLX6j-MSVnWJOcGjzhXWi6tC6RVeBoRmStwZKXZBH1M-6Tt96NSvvIoC22XT9VFLsO30OPcyhJDJRXCJJutpK8aIXGFypWVNuhFjoFCfDMZMIipR6INv-VMW0JvpYFAkrQCZWQIMF4T2qCdnXpXoSeNgbNbzhg-AP18mEwOl-nnQ1D7rAM_VugRcrgE68jWxnAW-1lVz41WMHfOwCSMy4o2MGj3iszVlmAwgG6Ptzq0JWgMQBzDlvgQMY9Uewvv017Mt_ENezzm2_aoG6cLGBXFZHHt6Lo2JslBE5adhnPfpBeQNCV4PYBm_QjtMNZadlQUkddpaT_SylPIZKB-ng6TxoK2Ba7390nhEvKD6s5JkqedxM2_oqJOS2tssERLI0ruh0TJR2K7P4z-ZjHef2RyMNcsueVsy7f87NW56Irum1Sk5-8uuuJt9-LjM20-sxd3P__-_rN4-fzLyfrkHw
3+
// created using https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-tools/NuGet/Microsoft.Net.Compilers.Toolset/overview/5.0.0-2.25380.108
4+
5+
.class private auto ansi abstract sealed beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.ExtensionPropertiesV1
6+
extends [System.Runtime]System.Object
7+
{
8+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = (
9+
01 00 01 00 00
10+
)
11+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = (
12+
01 00 00 00 00
13+
)
14+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = (
15+
01 00 00 00
16+
)
17+
// Nested Types
18+
.class nested public auto ansi sealed specialname beforefieldinit '<>E__0`1'<T>
19+
extends [System.Runtime]System.Object
20+
{
21+
// Methods
22+
.method private hidebysig specialname static
23+
void '<Extension>$' (
24+
class [System.Runtime]System.Collections.Generic.ICollection`1<!T> collection
25+
) cil managed
26+
{
27+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
28+
01 00 00 00
29+
)
30+
// Method begins at RVA 0x209d
31+
// Header size: 1
32+
// Code size: 1 (0x1)
33+
.maxstack 8
34+
35+
IL_0000: ret
36+
} // end of method '<>E__0`1'::'<Extension>$'
37+
38+
.method public hidebysig specialname
39+
instance bool get_IsEmpty () cil managed
40+
{
41+
// Method begins at RVA 0x209f
42+
// Header size: 1
43+
// Code size: 2 (0x2)
44+
.maxstack 8
45+
46+
IL_0000: ldnull
47+
IL_0001: throw
48+
} // end of method '<>E__0`1'::get_IsEmpty
49+
50+
.method public hidebysig specialname
51+
instance int32 get_Test () cil managed
52+
{
53+
// Method begins at RVA 0x209f
54+
// Header size: 1
55+
// Code size: 2 (0x2)
56+
.maxstack 8
57+
58+
IL_0000: ldnull
59+
IL_0001: throw
60+
} // end of method '<>E__0`1'::get_Test
61+
62+
.method public hidebysig specialname
63+
instance void set_Test (
64+
int32 'value'
65+
) cil managed
66+
{
67+
// Method begins at RVA 0x209f
68+
// Header size: 1
69+
// Code size: 2 (0x2)
70+
.maxstack 8
71+
72+
IL_0000: ldnull
73+
IL_0001: throw
74+
} // end of method '<>E__0`1'::set_Test
75+
76+
.method public hidebysig
77+
instance void AddIfNotNull (
78+
!T item
79+
) cil managed
80+
{
81+
// Method begins at RVA 0x209f
82+
// Header size: 1
83+
// Code size: 2 (0x2)
84+
.maxstack 8
85+
86+
IL_0000: ldnull
87+
IL_0001: throw
88+
} // end of method '<>E__0`1'::AddIfNotNull
89+
90+
.method public hidebysig
91+
instance !!T2 Cast<(!T) T2> (
92+
int32 index
93+
) cil managed
94+
{
95+
.param type T2
96+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = (
97+
01 00 00 00 00
98+
)
99+
// Method begins at RVA 0x209f
100+
// Header size: 1
101+
// Code size: 2 (0x2)
102+
.maxstack 8
103+
104+
IL_0000: ldnull
105+
IL_0001: throw
106+
} // end of method '<>E__0`1'::Cast
107+
108+
.method public hidebysig static
109+
void StaticExtension () cil managed
110+
{
111+
// Method begins at RVA 0x209f
112+
// Header size: 1
113+
// Code size: 2 (0x2)
114+
.maxstack 8
115+
116+
IL_0000: ldnull
117+
IL_0001: throw
118+
} // end of method '<>E__0`1'::StaticExtension
119+
120+
// Properties
121+
.property instance bool IsEmpty()
122+
{
123+
.get instance bool ICSharpCode.Decompiler.Tests.TestCases.ILPretty.ExtensionPropertiesV1/'<>E__0`1'::get_IsEmpty()
124+
}
125+
.property instance int32 Test()
126+
{
127+
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.ILPretty.ExtensionPropertiesV1/'<>E__0`1'::get_Test()
128+
.set instance void ICSharpCode.Decompiler.Tests.TestCases.ILPretty.ExtensionPropertiesV1/'<>E__0`1'::set_Test(int32)
129+
}
130+
131+
} // end of class <>E__0`1
132+
133+
134+
// Methods
135+
.method public hidebysig static
136+
bool get_IsEmpty<T> (
137+
class [System.Runtime]System.Collections.Generic.ICollection`1<!!T> collection
138+
) cil managed
139+
{
140+
// Method begins at RVA 0x2050
141+
// Header size: 1
142+
// Code size: 10 (0xa)
143+
.maxstack 8
144+
145+
IL_0000: ldarg.0
146+
IL_0001: callvirt instance int32 class [System.Runtime]System.Collections.Generic.ICollection`1<!!T>::get_Count()
147+
IL_0006: ldc.i4.0
148+
IL_0007: ceq
149+
IL_0009: ret
150+
} // end of method ExtensionProperties::get_IsEmpty
151+
152+
.method public hidebysig static
153+
int32 get_Test<T> (
154+
class [System.Runtime]System.Collections.Generic.ICollection`1<!!T> collection
155+
) cil managed
156+
{
157+
// Method begins at RVA 0x205b
158+
// Header size: 1
159+
// Code size: 4 (0x4)
160+
.maxstack 8
161+
162+
IL_0000: nop
163+
IL_0001: ldc.i4.s 42
164+
IL_0003: ret
165+
} // end of method ExtensionProperties::get_Test
166+
167+
.method public hidebysig static
168+
void set_Test<T> (
169+
class [System.Runtime]System.Collections.Generic.ICollection`1<!!T> collection,
170+
int32 'value'
171+
) cil managed
172+
{
173+
// Method begins at RVA 0x2060
174+
// Header size: 1
175+
// Code size: 2 (0x2)
176+
.maxstack 8
177+
178+
IL_0000: nop
179+
IL_0001: ret
180+
} // end of method ExtensionProperties::set_Test
181+
182+
.method public hidebysig static
183+
void AddIfNotNull<T> (
184+
class [System.Runtime]System.Collections.Generic.ICollection`1<!!T> collection,
185+
!!T item
186+
) cil managed
187+
{
188+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = (
189+
01 00 00 00
190+
)
191+
// Method begins at RVA 0x2064
192+
// Header size: 12
193+
// Code size: 25 (0x19)
194+
.maxstack 2
195+
.locals init (
196+
[0] bool
197+
)
198+
199+
IL_0000: nop
200+
IL_0001: ldarg.1
201+
IL_0002: box !!T
202+
IL_0007: ldnull
203+
IL_0008: cgt.un
204+
IL_000a: stloc.0
205+
IL_000b: ldloc.0
206+
IL_000c: brfalse.s IL_0018
207+
208+
IL_000e: nop
209+
IL_000f: ldarg.0
210+
IL_0010: ldarg.1
211+
IL_0011: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1<!!T>::Add(!0)
212+
IL_0016: nop
213+
IL_0017: nop
214+
215+
IL_0018: ret
216+
} // end of method ExtensionProperties::AddIfNotNull
217+
218+
.method public hidebysig static
219+
!!T2 Cast<T, (!!T) T2> (
220+
class [System.Runtime]System.Collections.Generic.ICollection`1<!!T> collection,
221+
int32 index
222+
) cil managed
223+
{
224+
.custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = (
225+
01 00 00 00
226+
)
227+
// Method begins at RVA 0x2089
228+
// Header size: 1
229+
// Code size: 19 (0x13)
230+
.maxstack 8
231+
232+
IL_0000: nop
233+
IL_0001: ldarg.0
234+
IL_0002: ldarg.1
235+
IL_0003: call !!0 [System.Linq]System.Linq.Enumerable::ElementAt<!!T>(class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0>, int32)
236+
IL_0008: box !!T
237+
IL_000d: unbox.any !!T2
238+
IL_0012: ret
239+
} // end of method ExtensionProperties::Cast
240+
241+
.method public hidebysig static
242+
void StaticExtension<T> () cil managed
243+
{
244+
// Method begins at RVA 0x2060
245+
// Header size: 1
246+
// Code size: 2 (0x2)
247+
.maxstack 8
248+
249+
IL_0000: nop
250+
IL_0001: ret
251+
} // end of method ExtensionProperties::StaticExtension
252+
253+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.ExtensionPropertiesV1
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
4+
{
5+
internal static class ExtensionPropertiesV2
6+
{
7+
extension<T>(ICollection<T> collection) where T : notnull
8+
{
9+
public bool IsEmpty => collection.Count == 0;
10+
public int Test {
11+
get {
12+
return 42;
13+
}
14+
set {
15+
}
16+
}
17+
public void AddIfNotNull(T item)
18+
{
19+
if (item != null)
20+
{
21+
collection.Add(item);
22+
}
23+
}
24+
public T2 Cast<T2>(int index) where T2 : T
25+
{
26+
return (T2)(object)collection.ElementAt(index);
27+
}
28+
public static void StaticExtension()
29+
{
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)