From 7dec0eb3e3353e71844c557568087d08d91de796 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Tue, 2 Nov 2021 15:56:01 -0700 Subject: [PATCH] Fix tests and add more --- .../StackFrame/StackFrameParserTests.cs | 25 ++++++++++++++++++- .../StackFrame/StackFrameParser.cs | 12 ++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/EditorFeatures/Test/EmbeddedLanguages/StackFrame/StackFrameParserTests.cs b/src/EditorFeatures/Test/EmbeddedLanguages/StackFrame/StackFrameParserTests.cs index efa589fe847cc..fc7387da54ee2 100644 --- a/src/EditorFeatures/Test/EmbeddedLanguages/StackFrame/StackFrameParserTests.cs +++ b/src/EditorFeatures/Test/EmbeddedLanguages/StackFrame/StackFrameParserTests.cs @@ -234,7 +234,9 @@ public void TestGenericMethod() [InlineData("uʶ")] // 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})", @@ -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( @@ -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); diff --git a/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameParser.cs b/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameParser.cs index 23be728b5a6aa..6217dce1afd94 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameParser.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/StackFrame/StackFrameParser.cs @@ -148,7 +148,7 @@ private ParseResult TryParseNameNode(bool scanAtTrivia) return ParseResult.Empty; } - var identifierParseResult = TryScanGenericTypeIdentifier(_lexer, currentIdentifer.Value); + var identifierParseResult = TryScanGenericTypeIdentifier(ref _lexer, currentIdentifer.Value); if (!identifierParseResult.Success) { return ParseResult.Abort; @@ -157,7 +157,7 @@ private ParseResult 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.Abort; @@ -172,7 +172,7 @@ private ParseResult TryParseNameNode(bool scanAtTrivia) while (true) { - parseResult = TryParseQualifiedName(_lexer, memberAccess); + parseResult = TryParseQualifiedName(ref _lexer, memberAccess); if (!parseResult.Success) { return ParseResult.Abort; @@ -192,7 +192,7 @@ private ParseResult TryParseNameNode(bool scanAtTrivia) // Given an existing left hand side node or token, which can either be // an or // - static ParseResult TryParseQualifiedName(StackFrameLexer lexer, StackFrameNameNode lhs) + static ParseResult TryParseQualifiedName(ref StackFrameLexer lexer, StackFrameNameNode lhs) { if (!lexer.ScanCurrentCharAsTokenIfMatch(StackFrameKind.DotToken, out var dotToken)) { @@ -205,7 +205,7 @@ static ParseResult TryParseQualifiedName(StackFrame return ParseResult.Abort; } - var (success, rhs) = TryScanGenericTypeIdentifier(lexer, identifier.Value); + var (success, rhs) = TryScanGenericTypeIdentifier(ref lexer, identifier.Value); if (!success) { return ParseResult.Abort; @@ -223,7 +223,7 @@ static ParseResult TryParseQualifiedName(StackFrame // ^-------------- Grave token // ^------------- Arity token of "1" // - static ParseResult TryScanGenericTypeIdentifier(StackFrameLexer lexer, StackFrameToken identifierToken) + static ParseResult TryScanGenericTypeIdentifier(ref StackFrameLexer lexer, StackFrameToken identifierToken) { if (!lexer.ScanCurrentCharAsTokenIfMatch(StackFrameKind.GraveAccentToken, out var graveAccentToken)) {