Skip to content

Commit 859c2f8

Browse files
verdie-gmanfred-brands
authored andcommitted
Fix trivia for NUnit2046
1 parent 8b2e749 commit 859c2f8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/nunit.analyzers.tests/UseCollectionConstraint/UseCollectionConstraintCodeFixTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ public void TestMethod()
5151
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode);
5252
}
5353

54+
[TestCaseSource(nameof(NumericContraints))]
55+
public void VerifyLengthWithNewLine(string constraint)
56+
{
57+
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
58+
public void TestMethod()
59+
{{
60+
var array = new int[] {{ 1 }};
61+
Assert.That(↓array.Length,
62+
Is.{constraint});
63+
}}");
64+
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
65+
public void TestMethod()
66+
{{
67+
var array = new int[] {{ 1 }};
68+
Assert.That(array,
69+
Has.Length.{constraint});
70+
}}");
71+
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode);
72+
}
73+
5474
[TestCaseSource(nameof(NumericContraints))]
5575
public void VerifyCount(string constraint)
5676
{

src/nunit.analyzers/UseCollectionConstraint/UseCollectionConstraintCodeFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ await IsCollectionType(context, actualExpression.Expression).ConfigureAwait(fals
8585
var hasPropertyExpression = SyntaxFactory.MemberAccessExpression(
8686
SyntaxKind.SimpleMemberAccessExpression,
8787
SyntaxFactory.IdentifierName(NUnitFrameworkConstants.NameOfHas),
88-
propertyName);
88+
propertyName).WithTriviaFrom(innerConstraintExpression);
8989

9090
nodesToReplace.Add(innerConstraintExpression, hasPropertyExpression);
9191

0 commit comments

Comments
 (0)