-
Notifications
You must be signed in to change notification settings - Fork 140
Add solution to remove invalid metadata directives in documentation c… #1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,5 +433,32 @@ class MetadataTests: XCTestCase { | |
|
||
return (problemIDs, metadata) | ||
} | ||
|
||
func testInvalidMetadataDirectivesInDocumentationCommentHaveSolution() throws { | ||
let source = """ | ||
@Metadata { | ||
@DisplayName("Custom Name") | ||
@TechnologyRoot | ||
} | ||
""" | ||
let document = Document(parsing: source, options: .parseBlockDirectives) | ||
let directive = document.child(at: 0)! as! BlockDirective | ||
let (bundle, _) = try testBundleAndContext() | ||
var problems = [Problem]() | ||
let metadata = Metadata(from: directive, source: nil, for: bundle, problems: &problems) | ||
|
||
metadata?.validateForUseInDocumentationComment(symbolSource: nil, problems: &problems) | ||
|
||
XCTAssertEqual(problems.count, 2) | ||
|
||
// Verify that each problem has a solution to remove the directive | ||
for problem in problems { | ||
XCTAssertNotNil(problem.possibleSolutions) | ||
XCTAssertEqual(problem.possibleSolutions?.count, 1) | ||
XCTAssertEqual(problem.possibleSolutions?.first?.summary, "Remove this \(problem.diagnostic.identifier.split(separator: ".").last!) directive.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this test assertion will fail because the string it's expecting doesn't put single quotes around the directive name like the solution does. FYI: A completely different style that some will find more readable and some will find less readable could be to move the summary assertion out of the for-loop and assert on both messages together:
(I believe that the order of the problems will be stable based on the order that they appear in the test content. Otherwise you can unwrap the first solution and sort the mapped summaries.) |
||
XCTAssertEqual(problem.possibleSolutions?.first?.replacements.count, 1) | ||
XCTAssertEqual(problem.possibleSolutions?.first?.replacements.first?.replacement, "") | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibleSolutions
is non-optional so theXCTAssertNotNil
check isn't necessary and the optional chaining in the other assertions fail to compile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: since you're checking a few different values of the same first solution, you can require that the first solution exist once using
XCTUnwrap
and use the unwrapped value in the later test assertions.However, this is just a matter of style and preference. Not a requested change. I'm happy with both styles here, whichever you find more readable.