// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.EditAndContinue.UnitTests;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.EditAndContinue.UnitTests
{
public class ActiveStatementTests : RudeEditTestBase
{
#region Update
[Fact]
public void Update_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
while (true)
{
Foo(2);
}
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Foo(2);"));
}
[Fact]
public void Update_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
while (true)
{
Foo(1);
}
}
static void Foo(int a)
{
Console.WriteLine(a + 1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Update_Leaf_NewCommentAtEndOfActiveStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);//
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Update_Inner_NewCommentAtEndOfActiveStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo(1);//
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(846588)]
[Fact]
public void Update_Leaf_Block()
{
string src1 = @"
class C : System.IDisposable
{
public void Dispose() {}
static void Main(string[] args)
{
using (C x = null) {}
}
}";
string src2 = @"
class C : System.IDisposable
{
public void Dispose() {}
static void Main(string[] args)
{
using (C x) {}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "using (C x)", CSharpFeaturesResources.UsingStatement));
}
#endregion
#region Delete in Method Body
[Fact]
public void Delete_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
while (true)
{
}
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"));
}
// TODO (tomat): considering a change
[Fact]
public void Delete_Inner_MultipleParents()
{
string src1 = @"
class C : IDisposable
{
unsafe static void Main(string[] args)
{
{
Foo(1);
}
if (true)
{
Foo(2);
}
else
{
Foo(3);
}
int x = 1;
switch (x)
{
case 1:
case 2:
Foo(4);
break;
default:
Foo(5);
break;
}
checked
{
Foo(4);
}
unchecked
{
Foo(7);
}
while (true) Foo(8);
do Foo(9); while (true);
for (int i = 0; i < 10; i++) Foo(10);
foreach (var i in new[] { 1, 2}) Foo(11);
using (var z = new C()) Foo(12);
fixed (char* p = ""s"") Foo(13);
label: Foo(14);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C : IDisposable
{
unsafe static void Main(string[] args)
{
{
}
if (true)
{ }
else
{ }
int x = 1;
switch (x)
{
case 1:
case 2:
break;
default:
break;
}
checked
{
}
unchecked
{
}
while (true) { }
do { } while (true);
for (int i = 0; i < 10; i++) { }
foreach (var i in new[] { 1, 2 }) { }
using (var z = new C()) { }
fixed (char* p = ""s"") { }
label: { }
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "case 2:"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "default:"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "while (true)"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "do"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "for (int i = 0; i < 10; i++ )"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "foreach (var i in new[] { 1, 2 })"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "using ( var z = new C() )"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "fixed ( char* p = \"s\" )"),
Diagnostic(RudeEditKind.DeleteActiveStatement, "label"));
}
[Fact]
public void Delete_Leaf1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Delete_Leaf2()
{
string src1 = @"
class C
{
static void Foo(int a)
{
Console.WriteLine(1);
Console.WriteLine(2);
Console.WriteLine(3);
Console.WriteLine(4);
}
}";
string src2 = @"
class C
{
static void Foo(int a)
{
Console.WriteLine(1);
Console.WriteLine(2);
Console.WriteLine(4);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Delete_Leaf_InTry()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
try
{
Console.WriteLine(a);
}
catch
{
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
try
{
}
catch
{
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Delete_Leaf_InTry2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
try
{
try
{
Console.WriteLine(a);
}
catch
{
}
}
catch
{
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
try
{
try
{
}
catch
{
}
}
catch
{
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Delete_Inner_CommentActiveStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
//Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"));
}
[WorkItem(755959)]
[Fact]
public void Delete_Leaf_CommentActiveStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
//Console.WriteLine(a);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Constructors
[WorkItem(740949)]
[Fact]
public void Updated_Inner_Constructor()
{
string src1 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5);
}
}
class Foo
{
int value;
public Foo(int a)
{
this.value = a;
}
}";
string src2 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5*2);
}
}
class Foo
{
int value;
public Foo(int a)
{
this.value = a;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Foo f = new Foo(5*2);"));
}
[WorkItem(741249)]
[Fact]
public void Updated_Leaf_Constructor()
{
string src1 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5);
}
}
class Foo
{
int value;
public Foo(int a)
{
this.value = a;
}
}";
string src2 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5);
}
}
class Foo
{
int value;
public Foo(int a)
{
this.value = a*2;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(742334)]
[Fact]
public void Updated_Leaf_Constructor_Parameter()
{
string src1 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5);
}
}
class Foo
{
int value;
public Foo(int a)
{
this.value = a;
}
}";
string src2 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5);
}
}
class Foo
{
int value;
public Foo(int b)
{
this.value = b;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Renamed, "int b", FeaturesResources.Parameter));
}
[WorkItem(742334)]
[Fact]
public void Updated_Leaf_Constructor_Parameter_DefaultValue()
{
string src1 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5);
}
}
class Foo
{
int value;
public Foo(int a = 5)
{
this.value = a;
}
}";
string src2 = @"
using System;
class Program
{
static void Main(string[] args)
{
Foo f = new Foo(5);
}
}
class Foo
{
int value;
public Foo(int a = 42)
{
this.value = a;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InitializerUpdate, "int a = 42", FeaturesResources.Parameter));
}
[WorkItem(742334)]
[Fact]
public void Updated_Leaf_ConstructorChaining1()
{
string src1 = @"
using System;
class Test
{
static void Main(string[] args)
{
B b = new B(2, 3);
}
}
class B : A
{
public B(int x, int y) : base(x + y, x - y) { }
}
class A
{
public A(int x, int y) : this(5 + x, y, 0) { }
public A(int x, int y, int z) { }
}";
string src2 = @"
using System;
class Test
{
static void Main(string[] args)
{
B b = new B(2, 3);
}
}
class B : A
{
public B(int x, int y) : base(x + y + 5, x - y) { }
}
class A
{
public A(int x, int y) : this(x, y, 0) { }
public A(int x, int y, int z) { }
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(742334)]
[Fact]
public void Updated_Leaf_ConstructorChaining2()
{
string src1 = @"
using System;
class Test
{
static void Main(string[] args)
{
B b = new B(2, 3);
}
}
class B : A
{
public B(int x, int y) : base(x + y, x - y) { }
}
class A
{
public A(int x, int y) : this(x, y, 0) { }
public A(int x, int y, int z) { }
}";
string src2 = @"
using System;
class Test
{
static void Main(string[] args)
{
B b = new B(2, 3);
}
}
class B : A
{
public B(int x, int y) : base(x + y, x - y) { }
}
class A
{
public A(int x, int y) : this(5 + x, y, 0) { }
public A(int x, int y, int z) { }
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(742334)]
[Fact]
public void InstanceConstructorWithoutInitializer()
{
string src1 = @"
class C
{
int a = 5;
public C(int a) { }
static void Main(string[] args)
{
C c = new C(3);
}
}";
string src2 = @"
class C
{
int a = 42;
public C(int a) { }
static void Main(string[] args)
{
C c = new C(3);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceConstructorWithInitializer_Internal_Update1()
{
string src1 = @"
class D
{
public D(int d) {}
}
class C : D
{
int a = 5;
public C(int a) : this(true) { }
public C(bool b) : base(F()) {}
static int F()
{
return 1;
}
static void Main(string[] args)
{
C c = new C(3);
}
}";
string src2 = @"
class D
{
public D(int d) {}
}
class C : D
{
int a = 5;
public C(int a) : this(false) { }
public C(bool b) : base(F()) {}
static int F()
{
return 1;
}
static void Main(string[] args)
{
C c = new C(3);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "this(false)"));
}
[Fact]
public void InstanceConstructorWithInitializer_Internal_Update2()
{
string src1 = @"
class D
{
public D(int d) {}
}
class C : D
{
public C() : base(F()) {}
static int F()
{
return 1;
}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class D
{
public D(int d) {}
}
class C : D
{
public C() {}
static int F()
{
return 1;
}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "public C()"));
}
[Fact]
public void InstanceConstructorWithInitializer_Internal_Update3()
{
string src1 = @"
class D
{
public D(int d) { }
}
class C : D
{
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class D
{
public D(int d) { }
}
class C : D
{
public C() : base(1) {}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "base(1)"));
}
[Fact]
public void InstanceConstructorWithInitializer_Leaf_Update1()
{
string src1 = @"
class D
{
public D(int d) { }
}
class C : D
{
public C() : base(1) {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class D
{
public D(int d) { }
}
class C : D
{
public C() : base(2) {}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceConstructorWithInitializer_Leaf_Update2()
{
string src1 = @"
class D
{
public D() { }
public D(int d) { }
}
class C : D
{
public C() : base(2) {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class D
{
public D() { }
public D(int d) { }
}
class C : D
{
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceConstructorWithInitializer_Leaf_Update3()
{
string src1 = @"
class D
{
public D() { }
public D(int d) { }
}
class C : D
{
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class D
{
public D() { }
public D(int d) { }
}
class C : D
{
public C() : base(2) {}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceConstructorWithInitializerWithLambda_Update1()
{
string src1 = @"
class C
{
public C() : this((a, b) => { Console.WriteLine(a + b); }) { }
}";
string src2 = @"
class C
{
public C() : base((a, b) => { Console.WriteLine(a - b); }) { }
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceConstructorWithInitializerWithLambda_Update2()
{
string src1 = @"
class C
{
public C() : this((a, b) => { Console.WriteLine(a + b); }) { Console.WriteLine(1); }
}";
string src2 = @"
class C
{
public C() : this((a, b) => { Console.WriteLine(a + b); }) { Console.WriteLine(2); }
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceConstructorWithInitializerWithLambda_Update3()
{
string src1 = @"
class C
{
public C() : this((a, b) => { Console.WriteLine(a + b); }) { Console.WriteLine(1); }
}";
string src2 = @"
class C
{
public C() : this((a, b) => { Console.WriteLine(a - b); }) { Console.WriteLine(1); }
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Field and Property Initializers
[Fact]
public void InstancePropertyInitializer_Leaf_Update()
{
string src1 = @"
class C
{
int a { get; } = 1;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a { get; } = 2;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(742334)]
[Fact]
public void InstanceFieldInitializer_Leaf_Update1()
{
string src1 = @"
class C
{
int a = 1, b = 2;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a = 2, b = 2;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceFieldInitializer_Internal_Update1()
{
string src1 = @"
class C
{
int a = F(1), b = F(2);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a = F(2), b = F(2);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "int a = F(2)"));
}
[Fact]
public void InstanceFieldInitializer_Internal_Update2()
{
string src1 = @"
class C
{
int a = F(1), b = F(2);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a = F(1), b = F(3);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "b = F(3)"));
}
[Fact]
public void InstancePropertyInitializer_Internal_Delete1()
{
string src1 = @"
class C
{
int a { get; } = 1;
int b { get; } = 2;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a { get { return 1; } }
int b { get; } = 2;
public C() { }
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.MethodBodyAdd, "get", CSharpFeaturesResources.PropertyGetter));
}
[Fact]
public void InstancePropertyInitializer_Internal_Delete2()
{
string src1 = @"
class C
{
int a { get; } = 1;
static int s { get; } = 2;
int b { get; } = 2;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a { get; }
static int s { get; } = 2;
int b { get; } = 3;
public C() { }
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceFieldInitializer_Internal_Delete1()
{
string src1 = @"
class C
{
int a = F(1), b = F(2);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a, b = F(2);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceFieldInitializer_Internal_Delete2()
{
string src1 = @"
class C
{
int a = F(1), b = F(2);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a, b;
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstancePropertyAndFieldInitializers_Delete1()
{
string src1 = @"
class C
{
int a { get; } = 1;
static int s { get; } = 2;
int b = 2;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a { get; }
static int s { get; } = 2;
int b = 3;
public C() { }
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstancePropertyAndFieldInitializers_Delete2()
{
string src1 = @"
class C
{
int a = 1;
static int s { get; } = 2;
int b { get; } = 2;
public C() {}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
int a;
static int s { get; } = 2;
int b { get; } = 3;
public C() { }
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void InstanceFieldInitializer_SingleDeclarator()
{
string src1 = @"
class C
{
public static readonly int a = F(1);
public C() {}
public static int F(int a)
{
return a;
}
static void Main(string[] args)
{
C c = new C();
}
}";
string src2 = @"
class C
{
public static readonly int a = F(1);
public C() {}
public static int F(int a)
{
return a + 1;
}
static void Main(string[] args)
{
C c = new C();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_Lambda1()
{
string src1 = @"
class C
{
Func a = z => z + 1;
static void Main(string[] args)
{
new C().a(1);
}
}";
string src2 = @"
class C
{
Func a = F(z => z + 1);
static void Main(string[] args)
{
new C().a(1);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void PropertyInitializer_Lambda1()
{
string src1 = @"
class C
{
Func a { get; } = z => z + 1;
static void Main(string[] args)
{
new C().a(1);
}
}";
string src2 = @"
class C
{
Func a { get; } = F(z => z + 1);
static void Main(string[] args)
{
new C().a(1);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_Lambda2()
{
string src1 = @"
class C
{
Func> a = z => () => z + 1;
static void Main(string[] args)
{
new C().a(1)();
}
}";
string src2 = @"
class C
{
Func> a = z => () => z + 2;
static void Main(string[] args)
{
new C().a(1)();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void PropertyInitializer_Lambda2()
{
string src1 = @"
class C
{
Func> a { get; } = z => () => z + 1;
static void Main(string[] args)
{
new C().a(1)();
}
}";
string src2 = @"
class C
{
Func> a { get; } = z => () => z + 2;
static void Main(string[] args)
{
new C().a(1)();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_InsertConst1()
{
string src1 = @"
class C
{
int a = 1;
public C() {}
}";
string src2 = @"
class C
{
const int a = 1;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
edits.VerifyEdits(
"Update [int a = 1 ;]@24 -> [const int a = 1;]@24");
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ModifiersUpdate, "const int a = 1", FeaturesResources.ConstField));
}
[Fact]
public void LocalInitializer_InsertConst1()
{
string src1 = @"
class C
{
public void M()
{
int a = 1;
}
}";
string src2 = @"
class C
{
public void M()
{
const int a = 1;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_InsertConst2()
{
string src1 = @"
class C
{
int a = 1, b = 2;
public C() {}
}";
string src2 = @"
class C
{
const int a = 1, b = 2;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ModifiersUpdate, "const int a = 1, b = 2", FeaturesResources.ConstField));
}
[Fact]
public void LocalInitializer_InsertConst2()
{
string src1 = @"
class C
{
public void M()
{
int a = 1, b = 2;
}
}";
string src2 = @"
class C
{
public void M()
{
const int a = 1, b = 2;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_Delete1()
{
string src1 = @"
class C
{
int a = 1;
int b = 1;
public C() {}
}";
string src2 = @"
class C
{
int a;
int b = 1;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void LocalInitializer_Delete1()
{
string src1 = @"
class C
{
public void M() { int a = 1; }
}";
string src2 = @"
class C
{
public void M() { int a; }
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_Delete2()
{
string src1 = @"
class C
{
int b = 1;
int c;
int a = 1;
public C() {}
}";
string src2 = @"
class C
{
int b = 1;
int c;
int a;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void LocalInitializer_Delete2()
{
string src1 = @"
class C
{
public void M()
{
int b = 1;
int c;
int a = 1;
}
}";
string src2 = @"
class C
{
public void M()
{
int b = 1;
int c;
int a;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_Delete3()
{
string src1 = @"
class C
{
int b = 1;
int c;
int a = 1;
public C() {}
}";
string src2 = @"
class C
{
int b = 1;
int c;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "class C", FeaturesResources.Field));
}
[Fact]
public void LocalInitializer_Delete3()
{
string src1 = @"
class C
{
public void M()
{
int b = 1;
int c;
int a = 1;
}
}";
string src2 = @"
class C
{
public void M()
{
int b = 1;
int c;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_DeleteStaticInstance1()
{
string src1 = @"
class C
{
int a = 1;
static int b = 1;
int c = 1;
public C() {}
}";
string src2 = @"
class C
{
int a;
static int b = 1;
int c = 1;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_DeleteStaticInstance2()
{
string src1 = @"
class C
{
static int c = 1;
static int a = 1;
int b = 1;
public C() {}
}";
string src2 = @"
class C
{
static int c = 1;
static int a;
int b = 1;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_DeleteStaticInstance3()
{
string src1 = @"
class C
{
static int a = 1;
int b = 1;
public C() {}
}";
string src2 = @"
class C
{
static int a;
int b = 1;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldInitializer_DeleteMove1()
{
string src1 = @"
class C
{
int b = 1;
int c;
int a = 1;
public C() {}
}";
string src2 = @"
class C
{
int c;
int b = 1;
public C() {}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Move, "int c", FeaturesResources.Field),
Diagnostic(RudeEditKind.Delete, "class C", FeaturesResources.Field));
}
[Fact]
public void LocalInitializer_DeleteReorder1()
{
string src1 = @"
class C
{
public void M()
{
int b = 1;
int a = 1;
int c;
}
}";
string src2 = @"
class C
{
public void M()
{
int c;
int b = 1;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void FieldToProperty1()
{
string src1 = @"
class C
{
int a = 1;
}";
// The placement of the active statement is not ideal, but acceptable.
string src2 = @"
class C
{
int a { get; } = 1;
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "class C", FeaturesResources.Field));
}
[Fact]
public void PropertyToField1()
{
string src1 = @"
class C
{
int a { get; } = 1;
}";
// The placement of the active statement is not ideal, but acceptable.
string src2 = @"
class C
{
int a = 1;
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "class C", FeaturesResources.AutoProperty));
}
#endregion
#region Lock Statement
[Fact]
public void LockBody_Update()
{
string src1 = @"
class Test
{
private static object F() { return new object(); }
static void Main(string[] args)
{
lock (F())
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static object F() { return new object(); }
static void Main(string[] args)
{
lock (F())
{
System.Console.Write(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(755749)]
[Fact]
public void Lock_Insert_Leaf()
{
string src1 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
System.Console.Write(5);
}
}";
string src2 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (lockThis)
{
System.Console.Write(5);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "lock (lockThis)", CSharpFeaturesResources.LockStatement));
}
[WorkItem(755749)]
[Fact]
public void Lock_Insert_Leaf2()
{
string src1 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
{
System.Console.Write(5);
}
}
}";
string src2 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (lockThis)
{
System.Console.Write(5);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "lock (lockThis)", CSharpFeaturesResources.LockStatement));
}
[Fact]
public void Lock_Insert_Leaf3()
{
string src1 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
{
System.Console.Write(5);
}
System.Console.Write(10);
}
}";
string src2 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (lockThis)
{
System.Console.Write(5);
}
System.Console.Write(5);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lock_Insert_Leaf4()
{
string src1 = @"
class Test
{
public static object a = new object();
public static object b = new object();
public static object c = new object();
public static object d = new object();
public static object e = new object();
static void Main(string[] args)
{
lock (a)
{
lock (b)
{
lock (c)
{
System.Console.Write();
}
}
}
}
}";
string src2 = @"
class Test
{
public static object a = new object();
public static object b = new object();
public static object c = new object();
public static object d = new object();
public static object e = new object();
static void Main(string[] args)
{
lock (b)
{
lock (d)
{
lock (a)
{
lock (e)
{
System.Console.Write();
}
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "lock (d)", CSharpFeaturesResources.LockStatement),
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "lock (e)", CSharpFeaturesResources.LockStatement));
}
[Fact]
public void Lock_Insert_Leaf5()
{
string src1 = @"
class Test
{
public static object a = new object();
public static object b = new object();
public static object c = new object();
public static object d = new object();
public static object e = new object();
static void Main(string[] args)
{
lock (a)
{
lock (c)
{
lock (b)
{
lock (e)
{
System.Console.Write();
}
}
}
}
}
}";
string src2 = @"
class Test
{
public static object a = new object();
public static object b = new object();
public static object c = new object();
public static object d = new object();
public static object e = new object();
static void Main(string[] args)
{
lock (b)
{
lock (d)
{
lock (a)
{
System.Console.Write();
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "lock (d)", CSharpFeaturesResources.LockStatement));
}
[WorkItem(755752)]
[Fact]
public void Lock_Update_Leaf()
{
string src1 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (lockThis)
{
System.Console.Write(5);
}
}
}";
string src2 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (""test"")
{
System.Console.Write(5);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "lock (\"test\")", CSharpFeaturesResources.LockStatement));
}
[Fact]
public void Lock_Update_Leaf2()
{
string src1 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (lockThis)
{
System.Console.Write(5);
}
System.Console.Write(5);
}
}";
string src2 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (""test"")
{
System.Console.Write(5);
}
System.Console.Write(5);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lock_Delete_Leaf()
{
string src1 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
lock (lockThis)
{
System.Console.Write(5);
}
}
}";
string src2 = @"
class Test
{
private static object lockThis = new object();
static void Main(string[] args)
{
System.Console.Write(5);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lock_Update_Lambda1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
lock (F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
lock (F(a => a + 1))
{
Console.WriteLine(2);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lock_Update_Lambda2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
lock (F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
lock (G(a => a))
{
Console.WriteLine(1);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "lock (G(a => a))", CSharpFeaturesResources.LockStatement));
}
#endregion
#region Fixed Statement
[Fact]
public void FixedBody_Update()
{
string src1 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
unsafe
{
char* px2;
fixed (char* pj = &F())
{
System.Console.WriteLine(0);
}
}
}
}";
string src2 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
unsafe
{
char* px2;
fixed (char* pj = &F())
{
System.Console.WriteLine(1);
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(755742)]
[Fact]
public void Fixed_Insert_Leaf()
{
string src1 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
px2 = null;
}
}
}";
string src2 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* pj = &value)
{
px2 = null;
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "fixed (int* pj = &value)", CSharpFeaturesResources.FixedStatement));
}
[Fact]
public void Fixed_Insert_Leaf2()
{
string src1 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
}
}
}";
string src2 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* pj = &value)
{
px2 = null;
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(755742)]
[Fact]
public void Fixed_Insert_Leaf3()
{
string src1 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
px2 = null;
fixed (int* pj = &value)
{
}
}
}
}";
string src2 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* pj = &value)
{
px2 = null;
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "fixed (int* pj = &value)", CSharpFeaturesResources.FixedStatement));
}
[WorkItem(755742)]
[Fact]
public void Fixed_Reorder_Leaf1()
{
string src1 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* a = &value)
{
fixed (int* b = &value)
{
px2 = null;
}
}
}
}
}";
string src2 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* b = &value)
{
fixed (int* a = &value)
{
px2 = null;
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[WorkItem(755746)]
[Fact]
public void Fixed_Update_Leaf1()
{
string src1 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* pj = &value)
{
px2 = null;
}
}
}
}";
string src2 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* p = &value)
{
px2 = null;
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "fixed (int* p = &value)", CSharpFeaturesResources.FixedStatement));
}
[WorkItem(755746)]
[Fact]
public void Fixed_Update_Leaf2()
{
string src1 = @"
class Test
{
public static int value1 = 10;
public static int value2 = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* a = &value1)
{
fixed (int* b = &value1)
{
fixed (int* c = &value1)
{
px2 = null;
}
}
}
}
}
}";
string src2 = @"
class Test
{
public static int value1 = 10;
public static int value2 = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* c = &value1)
{
fixed (int* d = &value1)
{
fixed (int* a = &value2)
{
fixed (int* e = &value1)
{
px2 = null;
}
}
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "fixed (int* a = &value2)", CSharpFeaturesResources.FixedStatement),
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "fixed (int* d = &value1)", CSharpFeaturesResources.FixedStatement),
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "fixed (int* e = &value1)", CSharpFeaturesResources.FixedStatement));
}
[Fact]
public void Fixed_Delete_Leaf()
{
string src1 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
fixed (int* pj = &value)
{
px2 = null;
}
}
}
}";
string src2 = @"
class Test
{
static int value = 20;
static void Main(string[] args)
{
unsafe
{
int* px2;
px2 = null;
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Fixed_Update_Lambda1()
{
string src1 = @"
class C
{
static unsafe void Main(string[] args)
{
fixed (byte* p = &F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static unsafe void Main(string[] args)
{
fixed (byte* p = &F(a => a + 1))
{
Console.WriteLine(2);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Fixed_Update_Lambda2()
{
string src1 = @"
class C
{
static unsafe void Main(string[] args)
{
fixed (byte* p = &F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static unsafe void Main(string[] args)
{
fixed (byte* p = &G(a => a))
{
Console.WriteLine(1);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "fixed (byte* p = &G(a => a))", CSharpFeaturesResources.FixedStatement));
}
#endregion
#region ForEach Statement
[Fact]
public void ForEachBody_Update_ExpressionActive()
{
string src1 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
foreach (char c in F())
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
foreach (char c in F())
{
System.Console.Write(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEachBody_Update_InKeywordActive()
{
string src1 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
foreach (char c in F())
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
foreach (char c in F())
{
System.Console.Write(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEachBody_Update_VariableActive()
{
string src1 = @"
class Test
{
private static string[] F() { return null; }
static void Main(string[] args)
{
foreach (string c in F())
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static string[] F() { return null; }
static void Main(string[] args)
{
foreach (string c in F())
{
System.Console.Write(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEachBody_Update_ForeachKeywordActive()
{
string src1 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
foreach (char c in F())
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static string F() { return null; }
static void Main(string[] args)
{
foreach (char c in F())
{
System.Console.Write(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEachVariable_Update()
{
string src1 = @"
class Test
{
private static string[] F() { return null; }
static void Main(string[] args)
{
foreach (string c in F())
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static string[] F() { return null; }
static void Main(string[] args)
{
foreach (object c in F())
{
System.Console.Write(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
// not ideal, but good enough:
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "object c"),
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "foreach ( object c in F())", CSharpFeaturesResources.ForEachStatement));
}
[Fact]
public void ForEach_Reorder_Leaf1()
{
string src1 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var a in e1)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
System.Console.Write();
}
}
}
}
}";
string src2 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
foreach (var a in e1)
{
System.Console.Write();
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEach_Update_Leaf1()
{
string src1 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var a in e1)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
System.Console.Write();
}
}
}
}
}";
string src2 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
foreach (var a in e1)
{
System.Console.Write();
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEach_Update_Leaf2()
{
string src1 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
System.Console.Write();
}
}";
string src2 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
foreach (var a in e1)
{
System.Console.Write();
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "foreach (var b in e1)", CSharpFeaturesResources.ForEachStatement),
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "foreach (var c in e1)", CSharpFeaturesResources.ForEachStatement),
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "foreach (var a in e1)", CSharpFeaturesResources.ForEachStatement));
}
[Fact]
public void ForEach_Delete_Leaf1()
{
string src1 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var a in e1)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
System.Console.Write();
}
}
}
}
}";
string src2 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var a in e1)
{
foreach (var b in e1)
{
System.Console.Write();
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEach_Delete_Leaf2()
{
string src1 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var a in e1)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
System.Console.Write();
}
}
}
}
}";
string src2 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
System.Console.Write();
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEach_Delete_Leaf3()
{
string src1 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var a in e1)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
System.Console.Write();
}
}
}
}
}";
string src2 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var a in e1)
{
foreach (var c in e1)
{
System.Console.Write();
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEach_Lambda1()
{
string src1 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
Action a = () =>
{
System.Console.Write();
};
a();
}
}";
string src2 = @"
class Test
{
public static int[] e1 = new int[1];
public static int[] e2 = new int[1];
static void Main(string[] args)
{
foreach (var b in e1)
{
foreach (var c in e1)
{
Action a = () =>
{
foreach (var a in e1)
{
System.Console.Write();
}
};
}
a();
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "foreach (var a in e1)", CSharpFeaturesResources.ForEachStatement),
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "foreach (var b in e1)", CSharpFeaturesResources.ForEachStatement));
}
[Fact]
public void ForEach_Update_Lambda1()
{
string src1 = @"
class C
{
static unsafe void Main(string[] args)
{
foreach (var a in F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static unsafe void Main(string[] args)
{
foreach (var a in F(a => a + 1))
{
Console.WriteLine(2);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForEach_Update_Lambda2()
{
string src1 = @"
class C
{
static unsafe void Main(string[] args)
{
foreach (var a in F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static unsafe void Main(string[] args)
{
foreach (var a in G(a => a))
{
Console.WriteLine(1);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "foreach (var a in G(a => a))", CSharpFeaturesResources.ForEachStatement));
}
#endregion
#region For Statement
[Fact]
public void ForStatement_Initializer1()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
int i;
for (i = F(1); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
int i;
for (i = F(2); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "i = F(2)"));
}
[Fact]
public void ForStatement_Initializer2()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
int i;
for (i = F(1), F(1); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
int i;
for (i = F(1), F(2); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForStatement_Initializer_Delete()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
int i;
for (i = F(1); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
int i;
for (; i < 10; i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "for (; i < 10 ; i++)"));
}
[Fact]
public void ForStatement_Declarator1()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (var i = F(1); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (var i = F(2); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "var i = F(2)"));
}
[Fact]
public void ForStatement_Declarator2()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = F(1), j = F(1); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = F(1), j = F(2); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForStatement_Declarator3()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = F(1); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = F(1), j = F(2); i < 10; i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForStatement_Condition1()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(20); i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "i < F(20)"));
}
[Fact]
public void ForStatement_Condition_Delete()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; ; i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "for (int i = 1; ; i++ )"));
}
[Fact]
public void ForStatement_Incrementors1()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); F(1))
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(20); F(1))
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForStatement_Incrementors2()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); F(1))
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); F(2))
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "F(2)"));
}
[Fact]
public void ForStatement_Incrementors3()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); F(1))
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); F(1), i++)
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void ForStatement_Incrementors4()
{
string src1 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); F(1), i++)
{
System.Console.Write(0);
}
}
}";
string src2 = @"
class Test
{
private static int F(int a) { return a; }
static void Main(string[] args)
{
for (int i = 1; i < F(10); i++, F(1))
{
System.Console.Write(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Using Statement
[Fact]
public void Using_Update_Leaf1()
{
string src1 = @"
class Test
{
public static System.IDisposable a = null;
public static System.IDisposable b = null;
public static System.IDisposable c = null;
static void Main(string[] args)
{
using (a)
{
using (b)
{
System.Console.Write();
}
}
}
}";
string src2 = @"
class Test
{
public static System.IDisposable a = null;
public static System.IDisposable b = null;
public static System.IDisposable c = null;
static void Main(string[] args)
{
using (a)
{
using (c)
{
using (b)
{
System.Console.Write();
}
}
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "using (c)", CSharpFeaturesResources.UsingStatement));
}
[Fact]
public void Using_InLambdaBody1()
{
string src1 = @"
class Test
{
public static System.IDisposable a = null;
public static System.IDisposable b = null;
public static System.IDisposable c = null;
public static System.IDisposable d = null;
static void Main(string[] args)
{
using (a)
{
Action a = () =>
{
using (b)
{
System.Console.Write();
}
};
}
a();
}
}";
string src2 = @"
class Test
{
public static System.IDisposable a = null;
public static System.IDisposable b = null;
public static System.IDisposable c = null;
public static System.IDisposable d = null;
static void Main(string[] args)
{
using (d)
{
Action a = () =>
{
using (c)
{
using (b)
{
System.Console.Write();
}
}
};
}
a();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "using (c)", CSharpFeaturesResources.UsingStatement));
}
[Fact]
public void Using_Update_Lambda1()
{
string src1 = @"
class C
{
static unsafe void Main(string[] args)
{
using (F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static unsafe void Main(string[] args)
{
using (F(a => a + 1))
{
Console.WriteLine(2);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Using_Update_Lambda2()
{
string src1 = @"
class C
{
static unsafe void Main(string[] args)
{
using (F(a => a))
{
Console.WriteLine(1);
}
}
}
";
string src2 = @"
class C
{
static unsafe void Main(string[] args)
{
using (G(a => a))
{
Console.WriteLine(1);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "using (G(a => a))", CSharpFeaturesResources.UsingStatement));
}
#endregion
#region Conditional Block Statements (If, Switch, While, Do)
[Fact]
public void IfBody_Update1()
{
string src1 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
if (B())
{
System.Console.WriteLine(0);
}
}
}";
string src2 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
if (B())
{
System.Console.WriteLine(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void IfBody_Update2()
{
string src1 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
if (B())
{
System.Console.WriteLine(0);
}
}
}";
string src2 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
if (!B())
{
System.Console.WriteLine(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "if (!B())"));
}
[Fact]
public void IfBody_Update_Lambda()
{
string src1 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
if (B(() => 1))
{
System.Console.WriteLine(0);
}
}
}";
string src2 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
if (B(() => 2))
{
System.Console.WriteLine(0);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void WhileBody_Update1()
{
string src1 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
while (B())
{
System.Console.WriteLine(0);
}
}
}";
string src2 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
while (B())
{
System.Console.WriteLine(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void WhileBody_Update2()
{
string src1 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
while (B())
{
System.Console.WriteLine(0);
}
}
}";
string src2 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
while (!B())
{
System.Console.WriteLine(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "while (!B())"));
}
[Fact]
public void WhileBody_Update_Lambda()
{
string src1 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
while (B(() => 1))
{
System.Console.WriteLine(0);
}
}
}";
string src2 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
while (B(() => 2))
{
System.Console.WriteLine(1);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void DoWhileBody_Update1()
{
string src1 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
do
{
System.Console.WriteLine(0);
}
while (B());
}
}";
string src2 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
do
{
System.Console.WriteLine(1);
}
while (B());
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void DoWhileBody_Update2()
{
string src1 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
do
{
System.Console.WriteLine(0);
}
while (B());
}
}";
string src2 = @"
class C
{
public static bool B() { return false; }
public static void Main()
{
do
{
System.Console.WriteLine(1);
}
while (!B());
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "while (!B());"));
}
[Fact]
public void DoWhileBody_Update_Lambda()
{
string src1 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
do
{
System.Console.WriteLine(0);
}
while (B(() => 1));
}
}";
string src2 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
do
{
System.Console.WriteLine(1);
}
while (B(() => 2));
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void SwitchCase_Update1()
{
string src1 = @"
class C
{
public static string F() { return null; }
public static void Main()
{
switch (F())
{
case ""a"": System.Console.WriteLine(0); break;
case ""b"": System.Console.WriteLine(1); break;
}
}
}";
string src2 = @"
class C
{
public static string F() { return null; }
public static void Main()
{
switch (F())
{
case ""a"": System.Console.WriteLine(0); break;
case ""b"": System.Console.WriteLine(2); break;
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void SwitchCase_Update_Lambda()
{
string src1 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
switch (B(() => 1))
{
case ""a"": System.Console.WriteLine(0); break;
case ""b"": System.Console.WriteLine(1); break;
}
}
}";
string src2 = @"
class C
{
public static bool B(Func a) => false;
public static void Main()
{
switch (B(() => 2))
{
case ""a"": System.Console.WriteLine(0); break;
case ""b"": System.Console.WriteLine(2); break;
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Try
[Fact]
public void Try_Add_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
catch
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "try", CSharpFeaturesResources.TryBlock));
}
[Fact]
public void Try_Add_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
Console.WriteLine(1);
}
catch
{
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Try_Delete_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
catch
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "Foo();", CSharpFeaturesResources.TryBlock));
}
[Fact]
public void Try_Delete_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
Console.WriteLine(1);
}
catch
{
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Try_Update_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
catch
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
catch (IOException)
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "try", CSharpFeaturesResources.TryBlock));
}
[Fact]
public void Try_Update_Inner2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
catch
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
catch
{
}
Console.WriteLine(2);
}
static void Foo()
{
Console.WriteLine(1);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void TryFinally_Update_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
finally
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
Foo();
}
finally
{
}
Console.WriteLine(2);
}
static void Foo()
{
Console.WriteLine(1);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Try_Update_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
Console.WriteLine(1);
}
catch
{
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
Console.WriteLine(1);
}
catch (IOException)
{
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Catch
[Fact]
public void Catch_Add_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void Catch_Add_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
}
catch
{
Console.WriteLine(1);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void Catch_Delete_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "Foo();", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void Catch_Delete_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
}
catch
{
Console.WriteLine(1);
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "Console.WriteLine(1);", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void Catch_Update_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException)
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void Catch_Update_InFilter_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException) when (Foo(1))
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (Exception) when (Foo(1))
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void Catch_Update_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
}
catch
{
Console.WriteLine(1);
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
}
catch (IOException)
{
Console.WriteLine(1);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void CatchFilter_Update_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException) when (Foo(1))
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException) when (Foo(2))
{
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "when (Foo(2))"),
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void CatchFilter_Update_Leaf1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException) when (Foo(1))
{
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException) when (Foo(2))
{
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
[Fact]
public void CatchFilter_Update_Leaf2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException) when (Foo(1))
{
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (Exception) when (Foo(1))
{
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause));
}
#endregion
#region Finally
[Fact]
public void Finally_Add_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
finally
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "finally", CSharpFeaturesResources.FinallyClause));
}
[Fact]
public void Finally_Add_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
}
finally
{
Console.WriteLine(1);
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "finally", CSharpFeaturesResources.FinallyClause));
}
[Fact]
public void Finally_Delete_Inner()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
finally
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "Foo();", CSharpFeaturesResources.FinallyClause));
}
[Fact]
public void Finally_Delete_Leaf()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
try
{
}
finally
{
Console.WriteLine(1);
}
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "Console.WriteLine(1);", CSharpFeaturesResources.FinallyClause));
}
#endregion
#region Try-Catch-Finally
[Fact]
public void TryCatchFinally()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException)
{
try
{
try
{
try
{
Foo();
}
catch
{
}
}
catch (Exception)
{
}
}
finally
{
}
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (Exception)
{
try
{
try
{
}
finally
{
try
{
Foo();
}
catch
{
}
}
}
catch (Exception)
{
}
}
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "catch", CSharpFeaturesResources.CatchClause),
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "try", CSharpFeaturesResources.TryBlock),
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "Foo();", CSharpFeaturesResources.TryBlock),
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "finally", CSharpFeaturesResources.FinallyClause));
}
[Fact]
public void TryCatchFinally_Regions()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException)
{
try
{
try
{
try
{
Foo();
}
catch
{
}
}
catch (Exception)
{
}
}
finally
{
}
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException)
{
try { try { try { Foo(); } catch { } } catch (Exception) { } } finally { }
}
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void TryFilter_Regions1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException e) when (e == null)
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException e) when (e == null) { Foo(); }
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void TryFilter_Regions2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException e) when (e == null)
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException e) when (e == null) { Foo(); }
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Try_Lambda1()
{
string src1 = @"
using System;
using System.Linq;
class C
{
static int Foo(int x)
{
return 1;
}
static void Main()
{
Func f = null;
try
{
f = x => 1 + Foo(x);
}
catch
{
}
Console.Write(f(2));
}
}";
string src2 = @"
using System;
using System.Linq;
class C
{
static int Foo(int x)
{
return 1;
}
static void Main()
{
Func f = null;
f = x => 1 + Foo(x);
Console.Write(f(2));
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Try_Lambda2()
{
string src1 = @"
using System;
using System.Linq;
class C
{
static int Foo(int x)
{
return 1;
}
static void Main()
{
Func f = x =>
{
try
{
return 1 + Foo(x);
}
catch
{
}
};
Console.Write(f(2));
}
}";
string src2 = @"
using System;
using System.Linq;
class C
{
static int Foo(int x)
{
return 1;
}
static void Main()
{
Func f = x =>
{
return 1 + Foo(x);
};
Console.Write(f(2));
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "return 1 + Foo(x);", CSharpFeaturesResources.TryBlock));
}
[Fact]
public void Try_Query_Join1()
{
string src1 = @"
class C
{
static int Foo(int x)
{
return 1;
}
static void Main()
{
try
{
q = from x in xs
join y in ys on F() equals G()
select 1;
}
catch
{
}
q.ToArray();
}
}";
string src2 = @"
class C
{
static int Foo(int x)
{
return 1;
}
static void Main()
{
q = from x in xs
join y in ys on F() equals G()
select 1;
q.ToArray();
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Checked/Unchecked
[Fact]
public void CheckedUnchecked_Insert_Leaf()
{
string src1 = @"
class Test
{
static void Main(string[] args)
{
int a = 1, b = 2;
Console.WriteLine(a*b);
}
}";
string src2 = @"
class Test
{
static void Main(string[] args)
{
int a = 1, b = 2;
checked
{
Console.WriteLine(a*b);
}
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void CheckedUnchecked_Insert_Internal()
{
string src1 = @"
class Test
{
static void Main(string[] args)
{
System.Console.WriteLine(5 * M(1, 2));
}
private static int M(int a, int b)
{
return a * b;
}
}";
string src2 = @"
class Test
{
static void Main(string[] args)
{
checked
{
System.Console.WriteLine(5 * M(1, 2));
}
}
private static int M(int a, int b)
{
return a * b;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "checked", CSharpFeaturesResources.CheckedStatement));
}
[Fact]
public void CheckedUnchecked_Delete_Internal()
{
string src1 = @"
class Test
{
static void Main(string[] args)
{
checked
{
System.Console.WriteLine(5 * M(1, 2));
}
}
private static int M(int a, int b)
{
return a * b;
}
}";
string src2 = @"
class Test
{
static void Main(string[] args)
{
System.Console.WriteLine(5 * M(1, 2));
}
private static int M(int a, int b)
{
return a * b;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteAroundActiveStatement, "System.Console.WriteLine(5 * M(1, 2));", CSharpFeaturesResources.CheckedStatement));
}
[Fact]
public void CheckedUnchecked_Update_Internal()
{
string src1 = @"
class Test
{
static void Main(string[] args)
{
unchecked
{
System.Console.WriteLine(5 * M(1, 2));
}
}
private static int M(int a, int b)
{
return a * b;
}
}";
string src2 = @"
class Test
{
static void Main(string[] args)
{
checked
{
System.Console.WriteLine(5 * M(1, 2));
}
}
private static int M(int a, int b)
{
return a * b;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "checked", CSharpFeaturesResources.CheckedStatement));
}
[Fact]
public void CheckedUnchecked_Lambda1()
{
string src1 = @"
class Test
{
static void Main(string[] args)
{
unchecked
{
Action f = () => 5 * M(1, 2);
}
f();
}
private static int M(int a, int b)
{
return a * b;
}
}";
string src2 = @"
class Test
{
static void Main(string[] args)
{
checked
{
Action f = () => 5 * M(1, 2);
}
f();
}
private static int M(int a, int b)
{
return a * b;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "checked", CSharpFeaturesResources.CheckedStatement));
}
[Fact]
public void CheckedUnchecked_Query1()
{
string src1 = @"
using System.Collections.Generic;
using System.Linq;
class Test
{
static void Main()
{
IEnumerable f;
unchecked
{
f = from a in new[] { 5 } select M(a, int.MaxValue);
}
f.ToArray();
}
private static int M(int a, int b)
{
return a * b;
}
}";
string src2 = @"
using System.Collections.Generic;
using System.Linq;
class Test
{
static void Main()
{
IEnumerable f;
checked
{
f = from a in new[] { 5 } select M(a, int.MaxValue);
}
f.ToArray();
}
private static int M(int a, int b)
{
return a * b;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.UpdateAroundActiveStatement, "checked", CSharpFeaturesResources.CheckedStatement));
}
#endregion
#region Lambdas
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_GeneralStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
F(a => 1);
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
F(a => 2);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_Nested1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
F(b => F(a => 1));
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
F(b => F(a => 2));
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_Nested2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
F(b => F(a => 1));
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
F(b => G(a => 2));
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "G(a => 2 )"));
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_IfStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
if (F(a => 1)) { }
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
if (F(a => 2)) { }
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_WhileStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
while (F(a => 1)) { }
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
while (F(a => 2)) { }
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_DoStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
do {} while (F(a => 1));
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
do {} while (F(a => 2));
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_SwitchStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
switch (F(a => 1))
{
case 0: break;
case 1: break;
}
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
switch (F(a => 2))
{
case 0: break;
case 1: break;
}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_LockStatement()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
lock (F(a => 1)) {}
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
lock (F(a => 2)) {}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact, WorkItem(1359)]
public void Lambdas_LeafEdits_UsingStatement1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
using (F(a => 1)) {}
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
using (F(a => 2)) {}
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lambdas_ExpressionToStatements()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func f = a => 1;
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = a => { return 1; };
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lambdas_ExpressionToDelegate()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func f = a => 1;
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = delegate(int a) { return 1; };
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lambdas_StatementsToExpression()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func f = a => { return 1; };
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = a => 1;
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lambdas_DelegateToExpression()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func f = delegate(int a) { return 1; };
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = a => 1;
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lambdas_StatementsToDelegate()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func f = a => { return 1; };
}
}
";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = delegate(int a) { return 2; };
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Lambdas_ActiveStatementRemoved1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func> f = a =>
{
return b =>
{
return b;
};
};
var z = f(1);
z(2);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = b =>
{
return b;
};
var z = f;
z(2);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "return b;", CSharpFeaturesResources.Lambda));
}
[Fact]
public void Lambdas_ActiveStatementRemoved2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func> f = a => (b) => b;
var z = f(1);
z(2);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = (b) => b;
var z = f;
z(2);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "(b)", CSharpFeaturesResources.Lambda));
}
[Fact]
public void Lambdas_ActiveStatementRemoved3()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func> f = a =>
{
Func z;
F(b =>
{
return b;
}, out z);
return z;
};
var z = f(1);
z(2);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
Func f = b =>
{
F(b);
return 1;
};
var z = f;
z(2);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "F(b);", CSharpFeaturesResources.Lambda));
}
[Fact]
public void Lambdas_ActiveStatementRemoved4()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Func> f = a =>
{
z(2);
return b =>
{
return b;
};
};
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "{", CSharpFeaturesResources.Lambda),
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "{", CSharpFeaturesResources.Lambda));
}
[Fact]
public void Queries_ActiveStatementRemoved_WhereClause()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b where b.foo select b.bar;
s.ToArray();
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b select b.bar;
s.ToArray();
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "from", CSharpFeaturesResources.WhereClause));
}
[Fact]
public void Queries_ActiveStatementRemoved_LetClause()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b let x = b.foo select x;
s.ToArray();
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b select a.bar;
s.ToArray();
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "from", CSharpFeaturesResources.LetClause));
}
[Fact]
public void Queries_ActiveStatementRemoved_JoinClauseLeft()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b
join c in d on a.foo equals c.bar
select a.bar;
s.ToArray();
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b select a.bar;
s.ToArray();
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "from", CSharpFeaturesResources.JoinClause));
}
[Fact]
public void Queries_ActiveStatementRemoved_OrderBy1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b
orderby a.x, a.y descending, a.z ascending
select a;
s.ToArray();
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b select a.bar;
s.ToArray();
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "from", CSharpFeaturesResources.OrderByClause));
}
[Fact]
public void Queries_ActiveStatementRemoved_OrderBy2()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b
orderby a.x, a.y descending, a.z ascending
select a;
s.ToArray();
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b select a.bar;
s.ToArray();
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "from", CSharpFeaturesResources.OrderByClause));
}
[Fact]
public void Queries_ActiveStatementRemoved_OrderBy3()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b
orderby a.x, a.y descending, a.z ascending
select a;
s.ToArray();
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
var s = from a in b select a.bar;
s.ToArray();
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "from", CSharpFeaturesResources.OrderByClause));
}
[Fact]
public void Queries_Remove_JoinInto1()
{
string src1 = @"
class C
{
static void Main()
{
var q = from x in xs
join y in ys on F() equals G() into g
select 1;
}
}";
string src2 = @"
class C
{
static void Main()
{
var q = from x in xs
join y in ys on F() equals G()
select 1;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void Queries_Remove_QueryContinuation1()
{
string src1 = @"
class C
{
static void Main()
{
var q = from x in xs
group x by x.F() into g
where g.F()
select 1;
}
}";
string src2 = @"
class C
{
static void Main()
{
var q = from x in xs
group x by x.F() into g
select 1;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "into", CSharpFeaturesResources.WhereClause));
}
[Fact]
public void Queries_Remove_QueryContinuation2()
{
string src1 = @"
class C
{
static void Main()
{
var q = from x in xs
group x by x.F() into g
select 1;
}
}";
string src2 = @"
class C
{
static void Main()
{
var q = from x in xs
join y in ys on F() equals G() into g
select 1;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "join", CSharpFeaturesResources.SelectClause));
}
[Fact]
public void Queries_Select_Reduced1()
{
string src1 = @"
class C
{
static void Main()
{
var q = from a in array
where a > 0
select a + 1;
}
}";
string src2 = @"
class C
{
static void Main()
{
var q = from a in array
where a > 0
select a;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "select", CSharpFeaturesResources.SelectClause ));
}
[Fact]
public void Queries_Select_Reduced2()
{
string src1 = @"
class C
{
static int F(IEnumerbale e) => 1;
static void Main()
{
F(from a in array where a > 0 select a + 1);
}
}";
string src2 = @"
class C
{
static int F(IEnumerbale e) => 1;
static void Main()
{
F(from a in array where a > 0 select a);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "F(from a in array where a > 0 select a);"));
}
[Fact]
public void Queries_GroupBy_Reduced1()
{
string src1 = @"
class C
{
static void Main()
{
var q = from a in array
group a + 1 by a;
}
}";
string src2 = @"
class C
{
static void Main()
{
var q = from a in array
group a by a;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementLambdaRemoved, "group", CSharpFeaturesResources.GroupByClause));
}
[Fact]
public void Queries_GroupBy_Reduced2()
{
string src1 = @"
class C
{
static int F(IEnumerbale> e) => 1;
static void Main()
{
F(from a in array group a by a);
}
}";
string src2 = @"
class C
{
static int F(IEnumerbale> e) => 1;
static void Main()
{
F(from a in array group a + 1 by a);
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "F(from a in array group a + 1 by a);"));
}
#endregion
#region State Machines
[Fact]
public void MethodToIteratorMethod_WithActiveStatement()
{
string src1 = @"
class C
{
static IEnumerable F()
{
Console.WriteLine(1);
return new[] { 1, 2, 3 };
}
}
";
string src2 = @"
class C
{
static IEnumerable F()
{
Console.WriteLine(1);
yield return 1;
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "yield return 1;", CSharpFeaturesResources.YieldStatement));
}
[Fact]
public void MethodToIteratorMethod_WithActiveStatementInLambda()
{
string src1 = @"
class C
{
static IEnumerable F()
{
var f = new Action(() => { Console.WriteLine(1); });
return new[] { 1, 2, 3 };
}
}
";
string src2 = @"
class C
{
static IEnumerable F()
{
var f = new Action(() => { Console.WriteLine(1); });
yield return 1;
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
// should not contain RUDE_EDIT_INSERT_AROUND
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void MethodToIteratorMethod_WithoutActiveStatement()
{
string src1 = @"
class C
{
static IEnumerable F()
{
Console.WriteLine(1);
return new[] { 1, 2, 3 };
}
}
";
string src2 = @"
class C
{
static IEnumerable F()
{
Console.WriteLine(1);
yield return 1;
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void MethodToAsyncMethod_WithActiveStatement()
{
string src1 = @"
class C
{
static Task F()
{
Console.WriteLine(1);
return Task.FromResult(1);
}
}
";
string src2 = @"
class C
{
static async Task F()
{
Console.WriteLine(1);
return await Task.FromResult(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.InsertAroundActiveStatement, "await", CSharpFeaturesResources.AwaitExpression));
}
[Fact]
public void MethodToAsyncMethod_WithActiveStatementInLambda()
{
string src1 = @"
class C
{
static Task F()
{
var f = new Action(() => { Console.WriteLine(1); });
return Task.FromResult(1);
}
}
";
string src2 = @"
class C
{
static async Task F()
{
var f = new Action(() => { Console.WriteLine(1); });
return await Task.FromResult(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
// should not contain RUDE_EDIT_INSERT_AROUND
edits.VerifyRudeDiagnostics(active);
}
[Fact]
public void MethodToAsyncMethod_WithoutActiveStatement()
{
string src1 = @"
class C
{
static Task F()
{
Console.WriteLine(1);
return Task.FromResult(1);
}
}
";
string src2 = @"
class C
{
static async Task F()
{
Console.WriteLine(1);
return await Task.FromResult(1);
}
}
";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Misplaced AS
[Fact]
public void MisplacedActiveStatement1()
{
string src1 = @"
class C
{
public static int F(int a)
{
return a;
return a;
}
}";
string src2 = @"
class C
{
public static int F(int a)
{
return a;
return a;
}
}";
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);
edits.VerifyRudeDiagnostics(active);
}
#endregion
#region Unmodified Documents
[Fact]
public void UnmodifiedDocument1()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException e) if (e == null)
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
string src2 = @"
class C
{
static void Main(string[] args)
{
try
{
}
catch (IOException e) when (e == null)
{
Foo();
}
}
static void Foo()
{
Console.WriteLine(1);
}
}";
var active = GetActiveStatements(src1, src2);
Extensions.VerifyUnchangedDocument(src2, active);
}
[Fact]
public void UnmodifiedDocument_BadSpans1()
{
string src1 = @"
class C
{
const int a = 1;
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}
";
string src2 = @"
class C
{
const int a = 1;
static void Main(string[] args)
{
Foo();
}
static void Foo()
{
Console.WriteLine(1);
}
}";
var active = GetActiveStatements(src1, src2);
Extensions.VerifyUnchangedDocument(src2, active);
}
#endregion
#region Misc
[Fact]
public void Delete_All_SourceText()
{
string src1 = @"
class C
{
static void Main(string[] args)
{
Foo(1);
}
static void Foo(int a)
{
Console.WriteLine(a);
}
}";
string src2 = @"";
var edits = GetTopEdits(src1, src2);
edits.VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Delete, null, FeaturesResources.Class));
}
#endregion
}
}