diff --git a/Sources/SwiftDocC/Utility/MarkupExtensions/ListItemExtractor.swift b/Sources/SwiftDocC/Utility/MarkupExtensions/ListItemExtractor.swift index 6d5de831ba..d2df9986a1 100644 --- a/Sources/SwiftDocC/Utility/MarkupExtensions/ListItemExtractor.swift +++ b/Sources/SwiftDocC/Utility/MarkupExtensions/ListItemExtractor.swift @@ -284,37 +284,38 @@ private struct ExtractedTag { case httpBodyParameters init?(_ string: String) { - let components = string.components(separatedBy: .whitespaces).filter { !$0.isEmpty } + let separatorIndex = string.firstIndex(where: \.isWhitespace) ?? string.endIndex + let secondComponent = String(string[separatorIndex...].drop(while: \.isWhitespace)) - switch components.first?.lowercased() { + switch string[.. TaggedListItemExtractor { + let document = Document(parsing: markup, source: testSource, options: .parseSymbolLinks) + + var extractor = TaggedListItemExtractor() + _ = extractor.visit(document) + return extractor + } + + for whitespace in [" ", " ", "\t"] { + let parameters = extractedTags(""" + - Parameter\(whitespace)some parameter with spaces: Some description of this parameter. + """).parameters + XCTAssertEqual(parameters.count, 1) + let parameter = try XCTUnwrap(parameters.first) + XCTAssertEqual(parameter.name, "some parameter with spaces") + XCTAssertEqual(parameter.contents.map { $0.format() }, ["Some description of this parameter."]) + XCTAssertEqual(parameter.nameRange?.source?.path, testSource.path) + XCTAssertEqual(parameter.range?.source?.path, testSource.path) + } + + let parameters = extractedTags(""" + - Parameters: + - some parameter with spaces: Some description of this parameter. + """).parameters + XCTAssertEqual(parameters.count, 1) + let parameter = try XCTUnwrap(parameters.first) + XCTAssertEqual(parameter.name, "some parameter with spaces") + XCTAssertEqual(parameter.contents.map { $0.format() }, ["Some description of this parameter."]) + XCTAssertEqual(parameter.nameRange?.source?.path, testSource.path) + XCTAssertEqual(parameter.range?.source?.path, testSource.path) + + let dictionaryKeys = extractedTags(""" + - DictionaryKeys: + - some key with spaces: Some description of this key. + """).dictionaryKeys + XCTAssertEqual(dictionaryKeys.count, 1) + let dictionaryKey = try XCTUnwrap(dictionaryKeys.first) + XCTAssertEqual(dictionaryKey.name, "some key with spaces") + XCTAssertEqual(dictionaryKey.contents.map { $0.format() }, ["Some description of this key."]) + + let possibleValues = extractedTags(""" + - PossibleValue some value with spaces: Some description of this value. + """).possiblePropertyListValues + XCTAssertEqual(possibleValues.count, 1) + let possibleValue = try XCTUnwrap(possibleValues.first) + XCTAssertEqual(possibleValue.value, "some value with spaces") + XCTAssertEqual(possibleValue.contents.map { $0.format() }, ["Some description of this value."]) + XCTAssertEqual(possibleValue.nameRange?.source?.path, testSource.path) + XCTAssertEqual(possibleValue.range?.source?.path, testSource.path) + + XCTAssert(extractedTags("- Parameter: Missing parameter name.").parameters.isEmpty) + XCTAssert(extractedTags("- Parameter : Missing parameter name.").parameters.isEmpty) + + XCTAssert(extractedTags("- DictionaryKey: Missing key name.").dictionaryKeys.isEmpty) + XCTAssert(extractedTags("- PossibleValue: Missing value name.").possiblePropertyListValues.isEmpty) + } + func testExtractingTags() throws { try assertExtractsRichContentFor( tagName: "Returns",