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. 750
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  3. 2012
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il
  4. 2653
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il
  5. 2513
      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 @@ -130,332 +130,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
#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
public static void CollectionInitializerList()

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

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

2012
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

2513
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