Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make best attempt at fixing trivia #754

Merged
merged 12 commits into from
Aug 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,59 @@ public void Test(object actual, object expected)
}

[Test]
public void CodeFixPreservesLineBreakBeforeMessage()
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? ",\r\n \"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
? ",\r\n \"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 CodeFixMaintainsReasonableTriviaWithAllArgumentsOnSameLine([Values] bool newlineBeforeClosingParen)
{
var code = TestUtility.WrapInTestMethod(@"
ClassicAssert.AreEqual(2d, 3d, 0.0000001d,
""message"");");
var optionalNewline = newlineBeforeClosingParen ? @"
" : string.Empty;
var code = TestUtility.WrapInTestMethod($@"
↓ClassicAssert.AreEqual(
2d, 3d, 0.0000001d{optionalNewline});");

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){optionalNewline});");

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,61 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? ",\r\n \"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
? ",\r\n \"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 CodeFixMaintainsReasonableTriviaWithAllArgumentsOnSameLine([Values] bool newlineBeforeClosingParen)
{
var optionalNewline = newlineBeforeClosingParen ? @"
" : string.Empty;
var code = TestUtility.WrapInTestMethod($@"
↓ClassicAssert.AreNotEqual(
2d, 3d{optionalNewline});");

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

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,93 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? ",\r\n \"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
? ",\r\n \"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 CodeFixMaintainsReasonableTriviaWithAllArgumentsOnSameLine([Values] bool newlineBeforeClosingParen)
{
var optionalNewline = newlineBeforeClosingParen ? @"
" : string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();

↓ClassicAssert.AreNotSame(
expected, actual{optionalNewline});
}}");

var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();

Assert.That(
actual, Is.Not.SameAs(expected){optionalNewline});
}}");

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,94 @@ public void TestMethod()
}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode, fixTitle: ClassicModelAssertUsageCodeFix.TransformToConstraintModelDescription);
}

[Test]
public void CodeFixMaintainsReasonableTriviaWithEndOfLineClosingParen([Values] bool hasMessage)
{
var commaAndMessage = hasMessage
? ",\r\n \"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
? ",\r\n \"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 CodeFixMaintainsReasonableTriviaWithAllArgumentsOnSameLine([Values] bool newlineBeforeClosingParen)
{
var optionalNewline = newlineBeforeClosingParen ? @"
" : string.Empty;
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();

↓ClassicAssert.AreSame(
expected,
actual{optionalNewline});
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void TestMethod()
{{
var expected = new object();
var actual = new object();

Assert.That(
actual,
Is.SameAs(expected){optionalNewline});
}}");
Bartleby2718 marked this conversation as resolved.
Show resolved Hide resolved

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