Skip to content

Commit

Permalink
Merge pull request #754 from Bartleby2718/713-NUnit2049-indentation
Browse files Browse the repository at this point in the history
Make best attempt at fixing trivia
  • Loading branch information
mikkelbu authored Aug 7, 2024
2 parents 48bf08f + 9d005d8 commit ab3d365
Show file tree
Hide file tree
Showing 37 changed files with 2,298 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,58 @@ 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 ? "\r\n " : 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,60 @@ 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 ? "\r\n " : 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,92 @@ 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 ? "\r\n " : 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,91 @@ 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 ? "\r\n " : 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});
}}");

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

0 comments on commit ab3d365

Please sign in to comment.