public static void WhenAdjacentWithEmptyLine() { var syntaxTree = CSharpSyntaxTree.ParseText(@" namespace N { public class C { public C() { } private int f1; public int P1 { get => this.f1; set => this.f1 = value; } } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree), out var newLineBetween)); Assert.AreEqual(true, newLineBetween); }
public static void TwoProperties() { var editor = CreateDocumentEditor(@" namespace N { public class C { private int f1; public int P1 { get => this.f1; set => this.f1 = value; } private int f2; public int P2 { get => this.f2; set => this.f2 = value; } } }"); Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(editor, out var newLineBetween)); Assert.AreEqual(true, newLineBetween); }
public static void WhenStyleCop() { var syntaxTree = CSharpSyntaxTree.ParseText(@" namespace N { public class C { private int f1; public C() { } public int P1 { get => this.f1; set => this.f1 = value; } } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); var semanticModel = compilation.GetSemanticModel(syntaxTree); Assert.AreEqual(CodeStyleResult.No, CodeStyle.BackingFieldsAdjacent(semanticModel, out _)); }
public static void FindsInOtherDocument() { var syntaxTree1 = CSharpSyntaxTree.ParseText(@" namespace N { public class C { } }"); var syntaxTree2 = CSharpSyntaxTree.ParseText(@" namespace N { public class C { private int f1; public C() { } public int P1 { get => this.f1; set => this.f1 = value; } } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree1, syntaxTree2 }); Assert.AreEqual(CodeStyleResult.No, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree1), out _)); Assert.AreEqual(CodeStyleResult.No, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree2), out _)); }
public static void FindsAdjacentInCompilation() { var syntaxTree1 = CSharpSyntaxTree.ParseText(@" namespace N { public class C { } }"); var syntaxTree2 = CSharpSyntaxTree.ParseText(@" namespace N { public class C { public C() { } private int f1; public int P1 { get => this.f1; set => this.f1 = value; } } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree1, syntaxTree2 }); var semanticModel = compilation.GetSemanticModel(syntaxTree1); Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(semanticModel, out var newLine)); Assert.AreEqual(true, newLine); }
public static void TwoProperties() { var syntaxTree = CSharpSyntaxTree.ParseText(@" namespace N { public class C { private int f1; public int P1 { get => this.f1; set => this.f1 = value; } private int f2; public int P2 { get => this.f2; set => this.f2 = value; } } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree), out _)); }
public static void WhenUnknown() { var editor = CreateDocumentEditor(@" namespace N { public class C { } }"); Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(editor, out _)); }
public static void WhenUnknown() { var syntaxTree = CSharpSyntaxTree.ParseText(@" namespace N { public class C { } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); var semanticModel = compilation.GetSemanticModel(syntaxTree); Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(semanticModel, out _)); }
public static void TwoExpressionBodyProperties() { var editor = CreateDocumentEditor(@" namespace N { public class C { private int f1; public int P1 => this.f1; private int f2; public int P2 => this.f2; } }"); Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(editor, out var newLineBetween)); Assert.AreEqual(false, newLineBetween); }
public static void WhenUnknownOneProperty() { var editor = CreateDocumentEditor(@" namespace N { public class C { private int f1; public int P1 { get => this.f1; set => this.f1 = value; } } }"); Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(editor, out _)); }
public static void TwoExpressionBodyProperties() { var syntaxTree = CSharpSyntaxTree.ParseText(@" namespace N { public class C { private int f1; public int P1 => this.f1; private int f2; public int P2 => this.f2; } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree), out var newLineBetween)); Assert.AreEqual(false, newLineBetween); }
public static void WhenUnknownTwoDocuments() { var syntaxTree1 = CSharpSyntaxTree.ParseText(@" namespace N { public class C1 { } }"); var syntaxTree2 = CSharpSyntaxTree.ParseText(@" namespace N { public class C2 { } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree1, syntaxTree2 }); Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree1), out _)); Assert.AreEqual(CodeStyleResult.NotFound, CodeStyle.BackingFieldsAdjacent(compilation.GetSemanticModel(syntaxTree2), out _)); }
public static void WhenAdjacentNoEmptyLine() { var editor = CreateDocumentEditor(@" namespace N { public class C { public C() { } private int f1; public int P1 { get => this.f1; set => this.f1 = value; } } }"); Assert.AreEqual(CodeStyleResult.Yes, CodeStyle.BackingFieldsAdjacent(editor, out var newLineBetween)); Assert.AreEqual(false, newLineBetween); }