提交 3fecfe7e 编写于 作者: J Jared Parsons

Merge pull request #2945 from jaredpar/fix-2630

Use correct count in ReplaceSeparator
......@@ -285,5 +285,28 @@ public void Extensions()
Assert.Equal(-1, list.IndexOf(SyntaxKind.WhereClause));
Assert.False(list.Any(SyntaxKind.WhereClause));
}
[Fact]
[WorkItem(2630, "https://github.com/dotnet/roslyn/issues/2630")]
public void ReplaceSeparator()
{
var list = SyntaxFactory.SeparatedList<SyntaxNode>(
new[] {
SyntaxFactory.IdentifierName("A"),
SyntaxFactory.IdentifierName("B"),
SyntaxFactory.IdentifierName("C"),
});
var newComma = SyntaxFactory.Token(
SyntaxFactory.TriviaList(SyntaxFactory.Space),
SyntaxKind.CommaToken,
SyntaxFactory.TriviaList());
var newList = list.ReplaceSeparator(
list.GetSeparator(1),
newComma);
Assert.Equal(3, newList.Count);
Assert.Equal(2, newList.SeparatorCount);
Assert.Equal(1, newList.GetSeparator(1).GetLeadingTrivia().Count);
}
}
}
......@@ -524,7 +524,7 @@ public SeparatedSyntaxList<TNode> ReplaceSeparator(SyntaxToken separatorToken, S
{
var nodesWithSeps = this.GetWithSeparators();
var index = nodesWithSeps.IndexOf(separatorToken);
if (index < 0 || index >= this.Count)
if (index < 0)
{
throw new ArgumentException("separatorToken");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册