Browse Source

Add more deconstruction tests

pull/2119/head
Siegfried Pammer 5 years ago
parent
commit
220deac757
  1. 301
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DeconstructionTests.cs

301
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DeconstructionTests.cs

@ -79,6 +79,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private class AssignmentTargets private class AssignmentTargets
{ {
public int IntField; public int IntField;
public long LongField;
public float FloatField;
public double DoubleField;
public decimal DecimalField;
public MyInt MyField;
public MyInt? NMyField;
public string StringField;
public object ObjectField;
public dynamic DynamicField;
public int? NullableIntField; public int? NullableIntField;
@ -91,6 +102,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
set; set;
} }
public long Long {
get;
set;
}
public float Float {
get;
set;
}
public double Double {
get;
set;
}
public decimal Decimal {
get;
set;
}
public string String {
get;
set;
}
public object Object {
get;
set;
}
public dynamic Dynamic {
get;
set;
}
public int? NInt { public int? NInt {
get; get;
set; set;
@ -147,49 +193,133 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return null; return null;
} }
public void LocalVariable_NoConversion() public void LocalVariable_NoConversion_Custom()
{ {
var (myInt3, x) = GetSource<MyInt?, MyInt>(); var (myInt3, x) = GetSource<MyInt?, MyInt>();
Console.WriteLine(myInt3); Console.WriteLine(myInt3);
Console.WriteLine(x); Console.WriteLine(x);
} }
public void LocalVariable_NoConversion_DiscardFirst() public void LocalVariable_NoConversion_Tuple()
{
var (myInt, x) = GetTuple<MyInt?, MyInt>();
Console.WriteLine(myInt);
Console.WriteLine(x);
}
public void LocalVariable_NoConversion_Custom_DiscardFirst()
{ {
var (_, x, value) = GetSource<MyInt?, MyInt, int>(); var (_, x, value) = GetSource<MyInt?, MyInt, int>();
Console.WriteLine(x); Console.WriteLine(x);
Console.WriteLine(value); Console.WriteLine(value);
} }
public void LocalVariable_NoConversion_DiscardLast() // currently we detect deconstruction, iff the first element is not discarded
//public void LocalVariable_NoConversion_Tuple_DiscardFirst()
//{
// var (_, x, value) = GetTuple<MyInt?, MyInt, int>();
// Console.WriteLine(x);
// Console.WriteLine(value);
//}
public void LocalVariable_NoConversion_Custom_DiscardLast()
{ {
var (myInt3, x, _) = GetSource<MyInt?, MyInt, int>(); var (myInt3, x, _) = GetSource<MyInt?, MyInt, int>();
Console.WriteLine(myInt3); Console.WriteLine(myInt3);
Console.WriteLine(x); Console.WriteLine(x);
} }
public void LocalVariable_NoConversion_DiscardSecond() public void LocalVariable_NoConversion_Tuple_DiscardLast()
{
var (myInt, x, _) = GetTuple<MyInt?, MyInt, int>();
Console.WriteLine(myInt);
Console.WriteLine(x);
}
public void LocalVariable_NoConversion_Custom_DiscardSecond()
{ {
var (myInt3, _, value) = GetSource<MyInt?, MyInt, int>(); var (myInt3, _, value) = GetSource<MyInt?, MyInt, int>();
Console.WriteLine(myInt3); Console.WriteLine(myInt3);
Console.WriteLine(value); Console.WriteLine(value);
} }
public void LocalVariable_NoConversion_ReferenceTypes() public void LocalVariable_NoConversion_Tuple_DiscardSecond()
{
var (myInt, _, value) = GetTuple<MyInt?, MyInt, int>();
Console.WriteLine(myInt);
Console.WriteLine(value);
}
public void LocalVariable_NoConversion_Custom_ReferenceTypes()
{ {
var (value, value2) = GetSource<string, string>(); var (value, value2) = GetSource<string, string>();
Console.WriteLine(value); Console.WriteLine(value);
Console.WriteLine(value2); Console.WriteLine(value2);
} }
public void LocalVariable_IntToLongConversion() public void LocalVariable_NoConversion_Tuple_ReferenceTypes()
{
var (value, value2) = GetTuple<string, string>();
Console.WriteLine(value);
Console.WriteLine(value2);
}
public void LocalVariable_IntToLongConversion_Custom()
{
int value;
long value2;
(value, value2) = GetSource<int, int>();
Console.WriteLine(value);
Console.WriteLine(value2);
}
public void LocalVariable_IntToLongConversion_Tuple()
{
int value;
long value2;
(value, value2) = GetTuple<int, int>();
Console.WriteLine(value);
Console.WriteLine(value2);
}
public void LocalVariable_FloatToDoubleConversion_Custom()
{ {
var (value, value2) = GetSource<int, int>(); int value;
double value2;
(value, value2) = GetSource<int, float>();
Console.WriteLine(value); Console.WriteLine(value);
Console.WriteLine(value2); Console.WriteLine(value2);
} }
public void LocalVariable_NoConversion_ComplexValue() public void LocalVariable_FloatToDoubleConversion_Tuple()
{
int value;
double value2;
(value, value2) = GetTuple<int, float>();
Console.WriteLine(value);
Console.WriteLine(value2);
}
// dynamic conversion is currently not supported
//public void LocalVariable_ImplicitReferenceConversion_Custom()
//{
// object value;
// dynamic value2;
// (value, value2) = GetSource<string, string>();
// Console.WriteLine(value);
// value2.UseMe();
//}
//public void LocalVariable_ImplicitReferenceConversion_Tuple()
//{
// object value;
// dynamic value2;
// (value, value2) = GetTuple<string, string>();
// Console.WriteLine(value);
// value2.UseMe();
//}
public void LocalVariable_NoConversion_ComplexValue_Custom()
{ {
var (myInt3, x) = new DeconstructionSource<MyInt?, MyInt> { var (myInt3, x) = new DeconstructionSource<MyInt?, MyInt> {
Dummy = 3 Dummy = 3
@ -198,46 +328,185 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine(x); Console.WriteLine(x);
} }
public void Property_NoConversion() public void Property_NoConversion_Custom()
{ {
(Get(0).NMy, Get(1).My) = GetSource<MyInt?, MyInt>(); (Get(0).NMy, Get(1).My) = GetSource<MyInt?, MyInt>();
} }
public void Property_NoConversion_DiscardFirst() public void Property_IntToLongConversion_Custom()
{
(Get(0).Int, Get(1).Long) = GetSource<int, int>();
}
public void Property_FloatToDoubleConversion_Custom()
{
(Get(0).Int, Get(1).Double) = GetSource<int, float>();
}
// dynamic conversion is not supported
//public void Property_ImplicitReferenceConversion_Custom()
//{
// (Get(0).Object, Get(1).Dynamic) = GetSource<string, string>();
//}
public void Property_NoConversion_Custom_DiscardFirst()
{ {
(_, Get(1).My) = GetSource<MyInt?, MyInt>(); (_, Get(1).My) = GetSource<MyInt?, MyInt>();
} }
public void Property_NoConversion_DiscardLast() public void Property_NoConversion_Custom_DiscardLast()
{ {
(Get(0).NMy, _) = GetSource<MyInt?, MyInt>(); (Get(0).NMy, _) = GetSource<MyInt?, MyInt>();
} }
public void Tuple_Property_NoConversion() public void Property_NoConversion_Tuple()
{ {
(Get(0).NMy, Get(1).My) = GetTuple<MyInt?, MyInt>(); (Get(0).NMy, Get(1).My) = GetTuple<MyInt?, MyInt>();
} }
public void Tuple_Property_NoConversion_DiscardLast() public void Property_NoConversion_Tuple_DiscardLast()
{ {
(Get(0).NMy, Get(1).My, _) = GetTuple<MyInt?, MyInt, int>(); (Get(0).NMy, Get(1).My, _) = GetTuple<MyInt?, MyInt, int>();
} }
public void RefLocal_FloatToDoubleConversion(out double a) // currently we detect deconstruction, iff the first element is not discarded
//public void Property_NoConversion_Tuple_DiscardFirst()
//{
// (_, Get(1).My, Get(2).Int) = GetTuple<MyInt?, MyInt, int>();
//}
public void Property_NoConversion_Custom_DiscardSecond()
{
(Get(0).NMy, _, Get(2).Int) = GetSource<MyInt?, MyInt, int>();
}
public void Property_NoConversion_Tuple_DiscardSecond()
{
(Get(0).NMy, _, Get(2).Int) = GetTuple<MyInt?, MyInt, int>();
}
public void Property_NoConversion_Custom_ReferenceTypes()
{
(Get(0).String, Get(1).String) = GetSource<string, string>();
}
public void Property_NoConversion_Tuple_ReferenceTypes()
{
(Get(0).String, Get(1).String) = GetTuple<string, string>();
}
public void Property_IntToLongConversion_Tuple()
{
(Get(0).Int, Get(1).Long) = GetTuple<int, int>();
}
public void Property_FloatToDoubleConversion_Tuple()
{
(Get(0).Int, Get(1).Double) = GetTuple<int, float>();
}
public void RefLocal_NoConversion_Custom(out double a)
{
(a, GetRef<float>()) = GetSource<double, float>();
}
public void RefLocal_NoConversion_Tuple(out double a)
{
(a, GetRef<float>()) = GetTuple<double, float>();
}
public void RefLocal_FloatToDoubleConversion_Custom(out double a)
{ {
(a, GetRef<double>()) = GetSource<double, float>(); (a, GetRef<double>()) = GetSource<double, float>();
} }
//public void ArrayAssign_FloatToDoubleConversion(double[] arr) public void RefLocal_FloatToDoubleConversion_Tuple(out double a)
{
(a, GetRef<double>()) = GetTuple<double, float>();
}
//public void ArrayAssign_FloatToDoubleConversion_Custom(double[] arr)
//{ //{
// (arr[0], arr[1], arr[2]) = GetSource<double, float, double>(); // (arr[0], arr[1], arr[2]) = GetSource<double, float, double>();
//} //}
public void Field_NoConversion() public void Field_NoConversion_Custom()
{ {
(Get(0).IntField, Get(1).IntField) = GetSource<int, int>(); (Get(0).IntField, Get(1).IntField) = GetSource<int, int>();
} }
public void Field_NoConversion_Tuple()
{
(Get(0).IntField, Get(1).IntField) = GetTuple<int, int>();
}
public void Field_IntToLongConversion_Custom()
{
(Get(0).IntField, Get(1).LongField) = GetSource<int, int>();
}
public void Field_IntToLongConversion_Tuple()
{
(Get(0).IntField, Get(1).LongField) = GetTuple<int, int>();
}
public void Field_FloatToDoubleConversion_Custom()
{
(Get(0).DoubleField, Get(1).DoubleField) = GetSource<double, float>();
}
public void Field_FloatToDoubleConversion_Tuple()
{
(Get(0).DoubleField, Get(1).DoubleField) = GetTuple<double, float>();
}
// dynamic conversion is not supported
//public void Field_ImplicitReferenceConversion_Custom()
//{
// (Get(0).ObjectField, Get(1).DynamicField) = GetSource<string, string>();
//}
public void Field_NoConversion_Custom_DiscardFirst()
{
(_, Get(1).MyField) = GetSource<MyInt?, MyInt>();
}
public void Field_NoConversion_Custom_DiscardLast()
{
(Get(0).NMyField, _) = GetSource<MyInt?, MyInt>();
}
public void Field_NoConversion_Tuple_DiscardLast()
{
(Get(0).NMyField, Get(1).MyField, _) = GetTuple<MyInt?, MyInt, int>();
}
// currently we detect deconstruction, iff the first element is not discarded
//public void Field_NoConversion_Tuple_DiscardFirst()
//{
// (_, Get(1).MyField, Get(2).IntField) = GetTuple<MyInt?, MyInt, int>();
//}
public void Field_NoConversion_Custom_DiscardSecond()
{
(Get(0).NMyField, _, Get(2).IntField) = GetSource<MyInt?, MyInt, int>();
}
public void Field_NoConversion_Tuple_DiscardSecond()
{
(Get(0).NMyField, _, Get(2).IntField) = GetTuple<MyInt?, MyInt, int>();
}
public void Field_NoConversion_Custom_ReferenceTypes()
{
(Get(0).StringField, Get(1).StringField) = GetSource<string, string>();
}
public void Field_NoConversion_Tuple_ReferenceTypes()
{
(Get(0).StringField, Get(1).StringField) = GetTuple<string, string>();
}
public void DeconstructDictionaryForEach(Dictionary<string, int> dictionary) public void DeconstructDictionaryForEach(Dictionary<string, int> dictionary)
{ {
foreach (var (str, num2) in dictionary) { foreach (var (str, num2) in dictionary) {

Loading…
Cancel
Save