Skip to content
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

[5.10] Fix multiline directive without content parsing range issue #157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/Markdown/Parser/BlockDirectiveParser.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -127,7 +127,7 @@ struct PendingBlockDirective {

if line.text.starts(with: ")") {
parseState = .argumentsEnd
parseArgumentsEnd(from: line)
accepted = parseArgumentsEnd(from: line)
}

return accepted
Expand All @@ -143,10 +143,10 @@ struct PendingBlockDirective {
parseState = .contentsStart
endLocation = line.location!
parseContentsStart(from: line)
return true
} else {
return false
}
return true
}

/// Continue parsing from the `contentsStart` state.
Expand Down
25 changes: 24 additions & 1 deletion Tests/MarkdownTests/Parsing/BlockDirectiveParserTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -1043,4 +1043,27 @@ class BlockDirectiveArgumentParserTests: XCTestCase {
"""
XCTAssertEqual(expected, documentation.debugDescription())
}

// FIXME: swift-testing macro for specifying the relationship between a bug and a test
// Uncomment the following code when we integrate swift-testing
// @Test("Directive MultiLine WithoutContent Parsing", .bug("#152", relationship: .verifiesFix))
func testDirectiveMultiLineWithoutContentParsing() throws {
let source = """
@Image(
source: "example.png",
alt: "Example image"
)
"""

let document = Document(parsing: source, options: .parseBlockDirectives)
_ = try XCTUnwrap(document.child(at: 0) as? BlockDirective)
let expected = #"""
Document @1:1-4:2
└─ BlockDirective @1:1-4:2 name: "Image"
├─ Argument text segments:
| @2:1-2:25: " source: \"example.png\","
| @3:1-3:23: " alt: \"Example image\""
"""#
XCTAssertEqual(expected, document.debugDescription(options: .printSourceLocations))
}
}