Skip to content

Commit

Permalink
Fix tests and add more
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzngard committed Nov 2, 2021
1 parent 9eaa65e commit 7dec0eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ public void TestGenericMethod()
[InlineData("")] // character and modifier character
[InlineData("a\u00AD")] // Soft hyphen formatting character
[InlineData("a‿")] // Connecting punctuation (combining character)

[InlineData("at")]
[InlineData("line")]
[InlineData("in")]
public void TestIdentifierNames(string identifierName)
=> Verify(
@$"at {identifierName}.{identifierName}[{identifierName}]({identifierName} {identifierName})",
Expand All @@ -248,6 +250,26 @@ public void TestIdentifierNames(string identifierName)
)
);

[Fact]
public void TestInvalidSpacingBeforeQualifiedName()
=> Verify(
@"at MyNamespace. MyClass.MyMethod()", expectFailure: true);

[Fact]
public void TestInvalidSpacingAfterQualifiedName2()
=> Verify(
@"at MyNamespace.MyClass .MyMethod()", expectFailure: true);

[Fact]
public void TestWhitespaceAroundBrackets()
=> Verify(
@"at MyNamespace.MyClass.MyMethod[ T ]()",
methodDeclaration: MethodDeclaration(
QualifiedName("MyNamespace.MyClass.MyMethod", leadingTrivia: AtTrivia),
typeArguments: TypeArgumentList(
TypeArgument(IdentifierToken("T", leadingTrivia: SpaceTrivia(), trailingTrivia: SpaceTrivia()))))
);

[Fact]
public void TestAnonymousMethod()
=> Verify(
Expand Down Expand Up @@ -346,6 +368,7 @@ public void TestFileInformation_InvalidDirectory()
[InlineData("M.N(X.Y. x)")] // Trailing . in argument type
[InlineData("M.N[T.Y]()")] // Generic type arguments should not be qualified types
[InlineData("M.N(X.Y x.y)")] // argument names should not be qualified
[InlineData("M.N(params)")] // argument with type but no name
public void TestInvalidInputs(string input)
=> Verify(input, expectFailure: true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private ParseResult<StackFrameNameNode> TryParseNameNode(bool scanAtTrivia)
return ParseResult<StackFrameNameNode>.Empty;
}

var identifierParseResult = TryScanGenericTypeIdentifier(_lexer, currentIdentifer.Value);
var identifierParseResult = TryScanGenericTypeIdentifier(ref _lexer, currentIdentifer.Value);
if (!identifierParseResult.Success)
{
return ParseResult<StackFrameNameNode>.Abort;
Expand All @@ -157,7 +157,7 @@ private ParseResult<StackFrameNameNode> TryParseNameNode(bool scanAtTrivia)
RoslynDebug.AssertNotNull(identifierParseResult.Value);
var lhs = identifierParseResult.Value;

var parseResult = TryParseQualifiedName(_lexer, lhs);
var parseResult = TryParseQualifiedName(ref _lexer, lhs);
if (!parseResult.Success)
{
return ParseResult<StackFrameNameNode>.Abort;
Expand All @@ -172,7 +172,7 @@ private ParseResult<StackFrameNameNode> TryParseNameNode(bool scanAtTrivia)

while (true)
{
parseResult = TryParseQualifiedName(_lexer, memberAccess);
parseResult = TryParseQualifiedName(ref _lexer, memberAccess);
if (!parseResult.Success)
{
return ParseResult<StackFrameNameNode>.Abort;
Expand All @@ -192,7 +192,7 @@ private ParseResult<StackFrameNameNode> TryParseNameNode(bool scanAtTrivia)
// Given an existing left hand side node or token, which can either be
// an <see cref="StackFrameKind.IdentifierToken"/> or <see cref="StackFrameQualifiedNameNode"/>
//
static ParseResult<StackFrameQualifiedNameNode> TryParseQualifiedName(StackFrameLexer lexer, StackFrameNameNode lhs)
static ParseResult<StackFrameQualifiedNameNode> TryParseQualifiedName(ref StackFrameLexer lexer, StackFrameNameNode lhs)
{
if (!lexer.ScanCurrentCharAsTokenIfMatch(StackFrameKind.DotToken, out var dotToken))
{
Expand All @@ -205,7 +205,7 @@ static ParseResult<StackFrameQualifiedNameNode> TryParseQualifiedName(StackFrame
return ParseResult<StackFrameQualifiedNameNode>.Abort;
}

var (success, rhs) = TryScanGenericTypeIdentifier(lexer, identifier.Value);
var (success, rhs) = TryScanGenericTypeIdentifier(ref lexer, identifier.Value);
if (!success)
{
return ParseResult<StackFrameQualifiedNameNode>.Abort;
Expand All @@ -223,7 +223,7 @@ static ParseResult<StackFrameQualifiedNameNode> TryParseQualifiedName(StackFrame
// ^-------------- Grave token
// ^------------- Arity token of "1"
//
static ParseResult<StackFrameSimpleNameNode> TryScanGenericTypeIdentifier(StackFrameLexer lexer, StackFrameToken identifierToken)
static ParseResult<StackFrameSimpleNameNode> TryScanGenericTypeIdentifier(ref StackFrameLexer lexer, StackFrameToken identifierToken)

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Nov 2, 2021

Member

does this need to be static?

{
if (!lexer.ScanCurrentCharAsTokenIfMatch(StackFrameKind.GraveAccentToken, out var graveAccentToken))
{
Expand Down

0 comments on commit 7dec0eb

Please sign in to comment.