Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,17 @@ private struct Renderer {
let children = directLists(in: item)
if children.contains(where: { $0.head == "content-seed" }) {
guard let content = children.first(where: { ContentKind(head: $0.head) != nil }) else {
if let unsupportedHead = children.first(where: {
$0.head != "frame" && $0.head != "content-seed"
})?.head {
var message = "Item identity \(identity) contains unsupported DisplayList content “\(unsupportedHead)”."
if let suggestion = ContentKind.suggestedHead(for: unsupportedHead) {
message += " Did you mean “\(suggestion)”?"
}
throw DisplayListDescriptionError.unsupported(message: message)
}
throw DisplayListDescriptionError.unsupported(
message: "This item contains content-seed but no supported content value."
message: "Item identity \(identity) contains content-seed but no content value."
)
}
rendered.include(try renderContent(content))
Expand Down Expand Up @@ -647,6 +656,15 @@ private enum ContentKind {
case view
case placeholder

static func suggestedHead(for head: String) -> String? {
switch head {
case "chameleonColor": "chameleon-color"
case "platformView": "platform-view"
case "platformLayer": "platform-layer"
default: nil
}
}

init?(head: String?) {
switch head {
case "backdrop": self = .backdrop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,25 @@ final class DisplayListDescriptionConverterTests: XCTestCase {
}
}

func testReportsUnsupportedContentNameAndSuggestedSpelling() {
let description = """
(display-list
(item #:identity 4 #:version 2
(frame {{12, 8.3333333333333339}, {164, 40}})
(content-seed 5)
(platformView DemoPlatformViewFactory())))
"""

XCTAssertThrowsError(try DisplayListDescriptionConverter.convert(description)) { error in
XCTAssertEqual(
error as? DisplayListDescriptionError,
.unsupported(
message: "Item identity 4 contains unsupported DisplayList content “platformView”. Did you mean “platform-view”?"
)
)
}
}

private func utf16Slice(_ text: String, _ start: Int, _ end: Int) -> String {
let codeUnits = Array(text.utf16)
return String(decoding: codeUnits[start..<end], as: UTF16.self)
Expand Down
Loading