Skip to content

Commit

Permalink
Fix #713: Make best attempt at fixing trivia
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartleby2718 committed Jun 5, 2024
1 parent 88fcd73 commit 6d23f74
Show file tree
Hide file tree
Showing 53 changed files with 1,715 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,45 @@ public void Test(object actual, object expected)
}

[Test]
public void CodeFixPreservesLineBreakBeforeMessage()
{
var code = TestUtility.WrapInTestMethod(@"
ClassicAssert.AreEqual(2d, 3d, 0.0000001d,
""message"");");
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapInTestMethod($@"
↓ClassicAssert.AreEqual(
2d,
3d,
0.0000001d{commaAndMessage});");

var fixedCode = TestUtility.WrapInTestMethod($@"
Assert.That(
3d,
Is.EqualTo(2d).Within(0.0000001d){commaAndMessage});");

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithNewLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapInTestMethod($@"
↓ClassicAssert.AreEqual(
2d,
3d,
0.0000001d{commaAndMessage}
);");

var fixedCode = TestUtility.WrapInTestMethod(@"
Assert.That(3d, Is.EqualTo(2d).Within(0.0000001d),
""message"");");
var fixedCode = TestUtility.WrapInTestMethod($@"
Assert.That(
3d,
Is.EqualTo(2d).Within(0.0000001d){commaAndMessage}
);");

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,47 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapInTestMethod($@"
↓ClassicAssert.AreNotEqual(
2d,
3d{commaAndMessage});");

var fixedCode = TestUtility.WrapInTestMethod($@"
Assert.That(
3d,
Is.Not.EqualTo(2d){commaAndMessage});");

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithNewLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapInTestMethod($@"
↓ClassicAssert.AreNotEqual(
2d,
3d{commaAndMessage}
);");

var fixedCode = TestUtility.WrapInTestMethod($@"
Assert.That(
3d,
Is.Not.EqualTo(2d){commaAndMessage}
);");

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,67 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
↓ClassicAssert.AreNotSame(
expected,
actual{commaAndMessage});
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
Assert.That(
actual,
Is.Not.SameAs(expected){commaAndMessage});
}}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithNewLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
↓ClassicAssert.AreNotSame(
expected,
actual{commaAndMessage}
);
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
Assert.That(
actual,
Is.Not.SameAs(expected){commaAndMessage}
);
}}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,69 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
↓ClassicAssert.AreSame(
expected,
actual{commaAndMessage});
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
Assert.That(
actual,
Is.SameAs(expected){commaAndMessage});
}}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithNewLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
↓ClassicAssert.AreSame(
expected,
actual,
""message""
);
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();
Assert.That(
actual,
Is.SameAs(expected),
""message""
);
}}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,67 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, instanceDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var instance = new object();
var collection = Array.Empty<object>();
↓ClassicAssert.Contains(
instance,
collection{commaAndMessage});
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var instance = new object();
var collection = Array.Empty<object>();
Assert.That(
collection,
Does.Contain(instance){commaAndMessage});
}}");
RoslynAssert.CodeFix(analyzer, fix, instanceDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithNewLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var instance = new object();
var collection = Array.Empty<object>();
↓ClassicAssert.Contains(
instance,
collection{commaAndMessage}
);
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var instance = new object();
var collection = Array.Empty<object>();
Assert.That(
collection,
Does.Contain(instance){commaAndMessage}
);
}}");
RoslynAssert.CodeFix(analyzer, fix, instanceDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,55 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
↓ClassicAssert.Greater(
2d,
3d{commaAndMessage});
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
Assert.That(
2d,
Is.GreaterThan(3d){commaAndMessage});
}}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithNewLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? @",
""message"""
: string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
↓ClassicAssert.Greater(
2d,
3d{commaAndMessage}
);
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
Assert.That(
2d,
Is.GreaterThan(3d){commaAndMessage}
);
}}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}
}
}
Loading

0 comments on commit 6d23f74

Please sign in to comment.