Browse Source

Move array initializer tests from correctness to pretty tests, so that misdetections can be spotted.

pull/1405/head
Siegfried Pammer 7 years ago
parent
commit
cbd824b07e
  1. 325
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs
  2. 744
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  3. 2010
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il
  4. 2653
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il
  5. 2511
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il
  6. 3023
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il

325
ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs

@ -130,332 +130,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
} }
#region Array Initializers #region Array Initializers
public static void Array1()
{
InitializerTests.X(InitializerTests.Y(), new int[]
{
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
});
}
public static void Array2(int a, int b, int c)
{
InitializerTests.X(InitializerTests.Y(), new int[]
{
a,
0,
b,
0,
c
});
}
public static void NestedArray(int a, int b, int c)
{
InitializerTests.X(InitializerTests.Y(), new int[][]
{
new int[]
{
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
},
new int[]
{
a,
b,
c
},
new int[]
{
1,
2,
3,
4,
5,
6
}
});
}
public static void NestedNullableArray(int a, int b, int c)
{
InitializerTests.X(InitializerTests.Y(), new int?[][]
{
new int?[]
{
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
null
},
new int?[]
{
a,
b,
c,
null
},
new int?[]
{
1,
2,
3,
4,
5,
6,
null
}
});
}
public unsafe static void NestedPointerArray(int a, int b, int c)
{
InitializerTests.X(InitializerTests.Y(), new void*[][]
{
new void*[]
{
null
},
new void*[]
{
(void*)200,
null
},
new void*[]
{
(void*)100,
null
}
});
}
public static void ArrayBoolean()
{
InitializerTests.X(InitializerTests.Y(), new bool[]
{
true,
false,
true,
false,
false,
false,
true,
true
});
}
public static void ArrayByte()
{
InitializerTests.X(InitializerTests.Y(), new byte[]
{
1,
2,
3,
4,
5,
6,
7,
8,
254,
255
});
}
public static void ArraySByte()
{
InitializerTests.X(InitializerTests.Y(), new sbyte[]
{
-128,
-127,
0,
1,
2,
3,
4,
127
});
}
public static void ArrayShort()
{
InitializerTests.X(InitializerTests.Y(), new short[]
{
-32768,
-1,
0,
1,
32767
});
}
public static void ArrayUShort()
{
InitializerTests.X(InitializerTests.Y(), new ushort[]
{
0,
1,
32767,
32768,
65534,
65535
});
}
public static void ArrayInt()
{
InitializerTests.X(InitializerTests.Y(), new int[]
{
1,
-2,
2000000000,
4,
5,
-6,
7,
8,
9,
10
});
}
public static void ArrayUInt()
{
InitializerTests.X(InitializerTests.Y(), new uint[]
{
1u,
2000000000u,
3000000000u,
4u,
5u,
6u,
7u,
8u,
9u,
10u
});
}
public static void ArrayLong()
{
InitializerTests.X(InitializerTests.Y(), new long[]
{
-4999999999999999999L,
-1L,
0L,
1L,
4999999999999999999L
});
}
public static void ArrayULong()
{
InitializerTests.X(InitializerTests.Y(), new ulong[]
{
1uL,
2000000000uL,
3000000000uL,
4uL,
5uL,
6uL,
7uL,
8uL,
4999999999999999999uL,
9999999999999999999uL
});
}
public static void ArrayFloat()
{
InitializerTests.X(InitializerTests.Y(), new float[]
{
-1.5f,
0f,
1.5f,
float.NegativeInfinity,
float.PositiveInfinity,
float.NaN
});
}
public static void ArrayDouble()
{
InitializerTests.X(InitializerTests.Y(), new double[]
{
-1.5,
0.0,
1.5,
double.NegativeInfinity,
double.PositiveInfinity,
double.NaN
});
}
public static void ArrayDecimal()
{
InitializerTests.X(InitializerTests.Y(), new decimal[]
{
-100m,
0m,
100m,
-79228162514264337593543950335m,
79228162514264337593543950335m,
0.0000001m
});
}
public static void ArrayString()
{
InitializerTests.X(InitializerTests.Y(), new string[]
{
"",
null,
"Hello",
"World"
});
}
public static void ArrayEnum()
{
InitializerTests.X(InitializerTests.Y(), new InitializerTests.MyEnum[]
{
InitializerTests.MyEnum.a,
InitializerTests.MyEnum.b,
InitializerTests.MyEnum.a,
InitializerTests.MyEnum.b
});
}
public static void RecursiveArrayInitializer()
{
int[] array = new int[3];
array[0] = 1;
array[1] = 2;
array[2] = array[1] + 1;
array[0] = 0;
}
#endregion #endregion
public static void CollectionInitializerList() public static void CollectionInitializerList()

744
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -279,180 +279,421 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
{ {
return c; return c;
} }
#endregion
public C Test1() private static int GetInt()
{ {
C c = new C(); return 1;
c.L = new List<S>();
c.L.Add(new S(1));
return c;
} }
public C Test1Alternative() private static string GetString()
{ {
return TestCall(1, new C { return "Test";
L = new List<S> {
new S(1)
}
});
} }
public C Test2() private static void NoOp(Guid?[] array)
{ {
C c = new C();
c.Z = 1;
c.Z = 2;
return c;
} }
public C Test3() private void Data_TestEvent(object sender, EventArgs e)
{ {
C c = new C(); throw new NotImplementedException();
c.Y = new S(1);
c.Y.A = 2;
return c;
} }
#endregion
public C Test3b() #region Array initializers
public static void Array1()
{ {
return TestCall(0, new C { X(Y(), new int[10] {
Z = 1, 1,
Y = { 2,
A = 2 3,
} 4,
5,
6,
7,
8,
9,
10
}); });
} }
public C Test4() public static void Array2(int a, int b, int c)
{ {
C c = new C(); X(Y(), new int[5] {
c.Y.A = 1; a,
c.Z = 2; 0,
c.Y.B = 3; b,
return c; 0,
c
});
} }
public static void InvalidIndices(int a) public static void NestedArray(int a, int b, int c)
{ {
int[] array = new int[1]; X(Y(), new int[3][] {
array[1] = a; new int[10] {
X(Y(), array); 1,
2,
3,
4,
5,
6,
7,
8,
9,
10
},
new int[3] {
a,
b,
c
},
new int[6] {
1,
2,
3,
4,
5,
6
}
});
} }
public static void InvalidIndices2(int a) public static void NestedNullableArray(int a, int b, int c)
{ {
#pragma warning disable 251 X(Y(), new int?[3][] {
int[] array = new int[1]; new int?[11] {
array[-1] = a; 1,
X(Y(), array); 2,
#pragma warning restore 3,
4,
5,
6,
7,
8,
9,
10,
null
},
new int?[4] {
a,
b,
c,
null
},
new int?[7] {
1,
2,
3,
4,
5,
6,
null
} }
});
public static void IndicesInWrongOrder(int a, int b) }
public unsafe static void NestedPointerArray(int a, int b, int c)
{ {
int[] array = new int[5]; X(Y(), new void*[3][] {
array[2] = b; new void*[1] {
array[1] = a; null
X(Y(), array); },
new void*[2] {
(void*)200,
null
},
new void*[2] {
(void*)100,
null
}
});
} }
public static void ExtensionMethodInCollectionInitializer() public static void ArrayBoolean()
{ {
#if CS60 X(Y(), new bool[8] {
X(Y(), new CustomList<int> { true,
false,
true,
false,
false,
false,
true,
true
});
}
public static void ArrayByte()
{ {
X(Y(), new byte[10] {
1, 1,
2 2,
3,
4,
5,
6,
7,
8,
254,
byte.MaxValue
});
} }
public static void ArraySByte()
{
X(Y(), new sbyte[8] {
sbyte.MinValue,
-127,
0,
1,
2,
3,
4,
sbyte.MaxValue
}); });
#else
CustomList<int> customList = new CustomList<int>();
customList.Add(1, 2);
X(Y(), customList);
#endif
} }
public static void NoCollectionInitializerBecauseOfTypeArguments() public static void ArrayShort()
{ {
CustomList<int> customList = new CustomList<int>(); X(Y(), new short[5] {
customList.Add<int>("int"); short.MinValue,
Console.WriteLine(customList); -1,
0,
1,
short.MaxValue
});
} }
public static void CollectionInitializerWithParamsMethod() public static void ArrayUShort()
{ {
X(Y(), new CustomList<int> { X(Y(), new ushort[6] {
0,
1,
32767,
32768,
65534,
ushort.MaxValue
});
}
public static void ArrayInt()
{ {
X(Y(), new int[10] {
1, 1,
2, -2,
3, 2000000000,
4, 4,
5, 5,
6, -6,
7, 7,
8, 8,
9, 9,
10 10
});
} }
public static void ArrayUInt()
{
X(Y(), new uint[10] {
1u,
2000000000u,
3000000000u,
4u,
5u,
6u,
7u,
8u,
9u,
10u
}); });
} }
public static void CollectionInitializerList() public static void ArrayLong()
{ {
X(Y(), new List<int> { X(Y(), new long[5] {
1, -4999999999999999999L,
2, -1L,
3 0L,
1L,
4999999999999999999L
}); });
} }
public static object RecursiveCollectionInitializer() public static void ArrayULong()
{ {
List<object> list = new List<object>(); X(Y(), new ulong[10] {
list.Add(list); 1uL,
return list; 2000000000uL,
3000000000uL,
4uL,
5uL,
6uL,
7uL,
8uL,
4999999999999999999uL,
9999999999999999999uL
});
} }
public static void CollectionInitializerDictionary() public static void ArrayFloat()
{ {
X(Y(), new Dictionary<string, int> { X(Y(), new float[6] {
-1.5f,
0f,
1.5f,
float.NegativeInfinity,
float.PositiveInfinity,
float.NaN
});
}
public static void ArrayDouble()
{ {
"First", X(Y(), new double[6] {
1 -1.5,
}, 0.0,
1.5,
double.NegativeInfinity,
double.PositiveInfinity,
double.NaN
});
}
public static void ArrayDecimal()
{ {
"Second", X(Y(), new decimal[6] {
2 -100m,
}, 0m,
100m,
decimal.MinValue,
decimal.MaxValue,
0.0000001m
});
}
public static void ArrayString()
{ {
"Third", X(Y(), new string[4] {
3 "",
null,
"Hello",
"World"
});
} }
public static void ArrayEnum()
{
X(Y(), new MyEnum[4] {
MyEnum.a,
MyEnum.b,
MyEnum.a,
MyEnum.b
}); });
} }
public static void CollectionInitializerDictionaryWithEnumTypes() public static void RecursiveArrayInitializer()
{ {
X(Y(), new Dictionary<MyEnum, MyEnum2> { int[] array = new int[3];
array[0] = 1;
array[1] = 2;
array[2] = array[1] + 1;
array[0] = 0;
}
public static void InvalidIndices(int a)
{ {
MyEnum.a, int[] array = new int[1];
MyEnum2.c array[1] = a;
}, X(Y(), array);
}
public static void InvalidIndices2(int a)
{ {
MyEnum.b, #pragma warning disable 251
MyEnum2.d int[] array = new int[1];
array[-1] = a;
X(Y(), array);
#pragma warning restore
} }
public static void IndicesInWrongOrder(int a, int b)
{
int[] array = new int[5];
array[2] = b;
array[1] = a;
X(Y(), array);
}
public static void Issue953_MissingNullableSpecifierForArrayInitializer()
{
NoOp(new Guid?[1] {
Guid.Empty
}); });
} }
public static void NotACollectionInitializer() private void Issue907_Test3(string text)
{ {
List<int> list = new List<int>(); X(Y(), new Dictionary<string, object> {
list.Add(1); {
list.Add(2); "",
list.Add(3); text
X(Y(), list); }
});
}
#endregion
#region Object initializers
public C Test1()
{
C c = new C();
c.L = new List<S>();
c.L.Add(new S(1));
return c;
}
public C Test1Alternative()
{
return TestCall(1, new C {
L = new List<S> {
new S(1)
}
});
}
public C Test2()
{
C c = new C();
c.Z = 1;
c.Z = 2;
return c;
}
public C Test3()
{
C c = new C();
c.Y = new S(1);
c.Y.A = 2;
return c;
}
public C Test3b()
{
return TestCall(0, new C {
Z = 1,
Y = {
A = 2
}
});
}
public C Test4()
{
C c = new C();
c.Y.A = 1;
c.Z = 2;
c.Y.B = 3;
return c;
} }
public static void ObjectInitializer() public static void ObjectInitializer()
@ -515,87 +756,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
{ {
X(Y(), new Data { X(Y(), new Data {
a = MyEnum.a, a = MyEnum.a,
PropertyList = { PropertyList = {
MyEnum2.c, MyEnum2.c,
MyEnum2.d MyEnum2.d
}
});
}
public static void ObjectInitializerWithInitializationOfNestedObjects()
{
X(Y(), new Data {
MoreData = {
a = MyEnum.a,
MoreData = {
a = MyEnum.b
}
}
});
}
private static int GetInt()
{
return 1;
}
private static string GetString()
{
return "Test";
}
private static void NoOp(Guid?[] array)
{
}
#if CS60
public static void SimpleDictInitializer()
{
X(Y(), new Data {
MoreData = {
a = MyEnum.a,
[2] = null
} }
}); });
} }
public static void MixedObjectAndDictInitializer() public static void ObjectInitializerWithInitializationOfNestedObjects()
{ {
X(Y(), new Data { X(Y(), new Data {
MoreData = { MoreData = {
a = MyEnum.a, a = MyEnum.a,
[GetInt()] = { MoreData = {
a = MyEnum.b, a = MyEnum.b
FieldList = {
MyEnum2.c
},
[GetInt(), GetString()] = new Data(),
[2] = null
} }
} }
}); });
} }
private void NestedListWithIndexInitializer(MyEnum myEnum)
{
#if !OPT
List<List<int>> list = new List<List<int>> {
#else
List<List<int>> obj = new List<List<int>> {
#endif
[0] = {
1,
2,
3
},
[1] = {
(int)myEnum
}
};
}
#endif
public static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() public static void ObjectInitializerWithInitializationOfDeeplyNestedObjects()
{ {
X(Y(), new Data { X(Y(), new Data {
@ -687,11 +866,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
}); });
} }
public static void Bug270_NestedInitialisers() public static void Issue270_NestedInitialisers()
{ {
NumberFormatInfo[] source = null; NumberFormatInfo[] source = null;
TestCall(0, new Thread(Bug270_NestedInitialisers) { TestCall(0, new Thread(Issue270_NestedInitialisers) {
Priority = ThreadPriority.BelowNormal, Priority = ThreadPriority.BelowNormal,
CurrentCulture = new CultureInfo(0) { CurrentCulture = new CultureInfo(0) {
DateTimeFormat = new DateTimeFormatInfo { DateTimeFormat = new DateTimeFormatInfo {
@ -704,53 +883,44 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
}); });
} }
public static void Bug953_MissingNullableSpecifierForArrayInitializer() public OtherItem2 Issue1345()
{
NoOp(new Guid?[1] {
Guid.Empty
});
}
private void Issue907_Test3(string text)
{
X(Y(), new Dictionary<string, object> {
{ {
"", OtherItem2 otherItem = new OtherItem2();
text otherItem.Data.Nullable = 3m;
} return otherItem;
});
} }
private void Issue1250_Test1(MyEnum value) public OtherItem2 Issue1345b()
{ {
X(Y(), new C { OtherItem2 otherItem = new OtherItem2();
Z = (int)value otherItem.Data2.Nullable = 3m;
}); return otherItem;
} }
#if CS60 #if CS60
private void Issue1250_Test2(MyEnum value) public OtherItem2 Issue1345c()
{ {
X(Y(), new C { OtherItem2 otherItem = new OtherItem2();
[(int)value] = new S((int)value) otherItem.Data3.Nullable = 3m;
}); return otherItem;
} }
private void Issue1250_Test3(int value) private Data Issue1345_FalsePositive()
{ {
X(Y(), new C { return new Data {
[value] = new S(value) ReadOnlyPropertyList = {
}); MyEnum2.c,
MyEnum2.d
}
};
} }
#endif
private void Issue1250_Test4(int value) private void Issue1250_Test1(MyEnum value)
{ {
X(Y(), new C { X(Y(), new C {
[(object)value] = new S(value) Z = (int)value
}); });
} }
#endif
private void Issue1251_Test(List<Item> list, OtherItem otherItem) private void Issue1251_Test(List<Item> list, OtherItem otherItem)
{ {
@ -776,41 +946,175 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
return null; return null;
} }
private void Data_TestEvent(object sender, EventArgs e) #endregion
#region Collection initializer
public static void ExtensionMethodInCollectionInitializer()
{ {
throw new NotImplementedException(); #if CS60
X(Y(), new CustomList<int> {
{
1,
2
}
});
#else
CustomList<int> customList = new CustomList<int>();
customList.Add(1, 2);
X(Y(), customList);
#endif
} }
public OtherItem2 Issue1345() public static void NoCollectionInitializerBecauseOfTypeArguments()
{ {
OtherItem2 otherItem = new OtherItem2(); CustomList<int> customList = new CustomList<int>();
otherItem.Data.Nullable = 3m; customList.Add<int>("int");
return otherItem; Console.WriteLine(customList);
} }
public OtherItem2 Issue1345b() public static void CollectionInitializerWithParamsMethod()
{ {
OtherItem2 otherItem = new OtherItem2(); X(Y(), new CustomList<int> {
otherItem.Data2.Nullable = 3m; {
return otherItem; 1,
2,
3,
4,
5,
6,
7,
8,
9,
10
} }
#if CS60 });
public OtherItem2 Issue1345c() }
public static void CollectionInitializerList()
{ {
OtherItem2 otherItem = new OtherItem2(); X(Y(), new List<int> {
otherItem.Data3.Nullable = 3m; 1,
return otherItem; 2,
3
});
} }
private Data Issue1345_FalsePositive() public static object RecursiveCollectionInitializer()
{ {
return new Data { List<object> list = new List<object>();
ReadOnlyPropertyList = { list.Add(list);
MyEnum2.c, return list;
}
public static void CollectionInitializerDictionary()
{
X(Y(), new Dictionary<string, int> {
{
"First",
1
},
{
"Second",
2
},
{
"Third",
3
}
});
}
public static void CollectionInitializerDictionaryWithEnumTypes()
{
X(Y(), new Dictionary<MyEnum, MyEnum2> {
{
MyEnum.a,
MyEnum2.c
},
{
MyEnum.b,
MyEnum2.d MyEnum2.d
} }
});
}
public static void NotACollectionInitializer()
{
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
X(Y(), list);
}
#if CS60
public static void SimpleDictInitializer()
{
X(Y(), new Data {
MoreData = {
a = MyEnum.a,
[2] = null
}
});
}
public static void MixedObjectAndDictInitializer()
{
X(Y(), new Data {
MoreData = {
a = MyEnum.a,
[GetInt()] = {
a = MyEnum.b,
FieldList = {
MyEnum2.c
},
[GetInt(), GetString()] = new Data(),
[2] = null
}
}
});
}
private void NestedListWithIndexInitializer(MyEnum myEnum)
{
#if !OPT
List<List<int>> list = new List<List<int>> {
#else
List<List<int>> obj = new List<List<int>> {
#endif
[0] = {
1,
2,
3
},
[1] = {
(int)myEnum
}
}; };
} }
private void Issue1250_Test2(MyEnum value)
{
X(Y(), new C {
[(int)value] = new S((int)value)
});
}
private void Issue1250_Test3(int value)
{
X(Y(), new C {
[value] = new S(value)
});
}
private void Issue1250_Test4(int value)
{
X(Y(), new C {
[(object)value] = new S(value)
});
}
#endif #endif
#endregion
} }
} }

2010
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il

File diff suppressed because it is too large Load Diff

2653
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il

File diff suppressed because it is too large Load Diff

2511
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il

File diff suppressed because it is too large Load Diff

3023
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save