Browse Source

[using] Add more test cases.

pull/877/head
Daniel Grunwald 8 years ago
parent
commit
666ff3b5f3
  1. 65
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs
  2. 14
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs

65
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Using.cs

@ -40,9 +40,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -40,9 +40,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
static void Main()
{
SimpleUsingNullStatement();
NoUsing();
NoUsing2();
ThisIsNotAUsingBlock();
NoUsingDueToAssignment();
NoUsingDueToAssignment2();
NoUsingDueToByRefCall();
NoUsingDueToContinuedDisposableUse();
ContinuedObjectUse();
UsingObject();
}
@ -58,7 +60,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -58,7 +60,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine("after using");
}
public static void NoUsing()
public static void NoUsingDueToAssignment()
{
PrintOnDispose printOnDispose = new PrintOnDispose("Wrong");
try {
@ -68,7 +70,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -68,7 +70,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
}
public static void NoUsing2()
public static void NoUsingDueToAssignment2()
{
PrintOnDispose printOnDispose = new PrintOnDispose("NoUsing(): Wrong");
try {
@ -81,12 +83,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -81,12 +83,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
}
public static void ThisIsNotAUsingBlock()
static void Clear<T>(ref T t)
{
t = default(T);
}
public static void NoUsingDueToByRefCall()
{
PrintOnDispose printOnDispose = new PrintOnDispose("NoUsingDueToByRefCall(): Wrong");
try {
Console.WriteLine("NoUsingDueToByRefCall");
Clear(ref printOnDispose);
} finally {
IDisposable disposable = (object)printOnDispose as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
}
public static void NoUsingDueToContinuedDisposableUse()
{
var obj = new System.IO.StringWriter();
IDisposable disposable;
try {
obj.WriteLine("ThisIsNotAUsingBlock");
obj.WriteLine("NoUsingDueToContinuedDisposableUse");
} finally {
disposable = (object)obj as IDisposable;
if (disposable != null) {
@ -96,6 +117,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -96,6 +117,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine(disposable);
}
public static void ContinuedObjectUse()
{
var obj = new System.IO.StringWriter();
try {
obj.WriteLine("ContinuedObjectUse");
} finally {
IDisposable disposable = (object)obj as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
Console.WriteLine(obj);
}
public static void VariableAlreadyUsedBefore()
{
System.IO.StringWriter obj = new System.IO.StringWriter();
obj.Write("VariableAlreadyUsedBefore - 1");
Console.WriteLine(obj);
obj = new System.IO.StringWriter();
try {
obj.WriteLine("VariableAlreadyUsedBefore - 2");
} finally {
IDisposable disposable = (object)obj as IDisposable;
if (disposable != null) {
disposable.Dispose();
}
}
}
public static void UsingObject()
{
object obj = new object();

14
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Using.cs

@ -86,6 +86,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -86,6 +86,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
private void UsingStatementOnNullableStruct(UsingStruct? us)
{
using (us) {
Console.WriteLine("using-body: " + us);
}
}
public void GenericUsing<T>(T t) where T : IDisposable
{
using (t) {
@ -106,5 +113,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -106,5 +113,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine(t);
}
}
public void GenericNullableUsing<T>(T? t) where T : struct, IDisposable
{
using (t) {
Console.WriteLine(t);
}
}
}
}

Loading…
Cancel
Save