Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs (C#)

Code before:
                        N(SyntaxKind.IdentifierName);
                        {
                            N(SyntaxKind.IdentifierToken, "T");
                        }
                        N(SyntaxKind.ColonToken);
                        N(SyntaxKind.ClassConstraint);
                        {
                            N(SyntaxKind.ClassKeyword);
                        }
                    }
                    N(SyntaxKind.SemicolonToken);
                }
                N(SyntaxKind.EndOfFileToken);
            }
            EOF();
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23877")]
        public void TestParseAttributeArgumentListWithInvalidString()
        {
            // Regression test for issue where ParseAttributeArgumentList would throw NullReferenceException
            // when given an invalid string without parentheses
            var result = SyntaxFactory.ParseAttributeArgumentList("somethingWithoutBrackets");

            Assert.NotNull(result);
            Assert.True(result.GetDiagnostics().Any(), "Expected diagnostics for invalid input");

            // Verify the structure is as expected - should have missing open/close parens and errors
            Assert.True(result.OpenParenToken.IsMissing);
            Assert.True(result.CloseParenToken.IsMissing);

            UsingNode(result);

            M(SyntaxKind.AttributeArgumentList);
            {
                M(SyntaxKind.OpenParenToken);
                M(SyntaxKind.CloseParenToken);
            }
            EOF();
        }
    }
}


Review comment (suggestion):
Please assert specific diagnostics. Likely this top part can entirely be removed in favor of a standard `UsingTree(string, diagnostics)` or `UsingNode(string, diagnostics)` call.

Code after:
                        N(SyntaxKind.IdentifierName);
                        {
                            N(SyntaxKind.IdentifierToken, "T");
                        }
                        N(SyntaxKind.ColonToken);
                        N(SyntaxKind.ClassConstraint);
                        {
                            N(SyntaxKind.ClassKeyword);
                        }
                    }
                    N(SyntaxKind.SemicolonToken);
                }
                N(SyntaxKind.EndOfFileToken);
            }
            EOF();
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23877")]
        public void TestParseAttributeArgumentListWithInvalidString()
        {
            // Regression test for issue where ParseAttributeArgumentList would throw NullReferenceException
            // when given an invalid string without parentheses
            var result = SyntaxFactory.ParseAttributeArgumentList("somethingWithoutBrackets");

            Assert.NotNull(result);
            result.GetDiagnostics().Verify(
                // (1,1): error CS1073: Unexpected token 'somethingWithoutBrackets'
                // somethingWithoutBrackets
                Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("somethingWithoutBrackets").WithLocation(1, 1));

            UsingNode(result);

            M(SyntaxKind.AttributeArgumentList);
            {
                M(SyntaxKind.OpenParenToken);
                M(SyntaxKind.CloseParenToken);
            }
            EOF();
        }
    }
}