-
Notifications
You must be signed in to change notification settings - Fork 120
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
Update LinkDestinationSummary to support multi-language content #54
Merged
d-ronnqvist
merged 12 commits into
swiftlang:main
from
d-ronnqvist:multi-languge-linkable-entities-spec
Dec 16, 2021
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0eafe44
Move content into a source language variant structure
d-ronnqvist 93dbb4d
Update LinkDestinationSummary to match spec changes
d-ronnqvist 76dd568
Merge branch 'main' into multi-languge-linkable-entities-spec
d-ronnqvist b729677
Merge branch 'main' into multi-languge-linkable-entities-spec
d-ronnqvist 145343f
Merge branch 'main' into multi-languge-linkable-entities-spec
d-ronnqvist e6196d9
Move `usr` out of variant substructure since it doesn't vary
d-ronnqvist 2cc7169
Update the spec to reduce the amount of duplicate data.
d-ronnqvist 347dd84
Merge branch 'multi-languge-linkable-entities-spec' of github.com:d-r…
d-ronnqvist c68d31a
Remove extra closing back-tick in documentation comments
d-ronnqvist afaa56e
Use an alias to make optionality of variant properties more explicit
d-ronnqvist 461d404
Remove trait from main summary element to avoid using it as a languag…
d-ronnqvist 3994142
Small documentation comment refinements
d-ronnqvist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,9 @@ class ExternalLinkableTests: XCTestCase { | |
|
||
let node = try context.entity(with: ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/tutorials/TestBundle/Tutorial", sourceLanguage: .swift)) | ||
let renderNode = try converter.convert(node, at: nil) | ||
let pageSummary = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode)[0] | ||
|
||
let summaries = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode) | ||
let pageSummary = summaries[0] | ||
XCTAssertEqual(pageSummary.title, "Basic Augmented Reality App") | ||
XCTAssertEqual(pageSummary.path, "/tutorials/testbundle/tutorial") | ||
XCTAssertEqual(pageSummary.referenceURL.absoluteString, "doc://com.test.example/tutorials/TestBundle/Tutorial") | ||
|
@@ -123,7 +125,7 @@ class ExternalLinkableTests: XCTestCase { | |
XCTAssertNil(pageSummary.declarationFragments, "Only symbols have declaration fragments") | ||
XCTAssertNil(pageSummary.abstract, "There is no text to use as an abstract for the tutorial page") | ||
|
||
let sectionSummary = node.externallyLinkableElementSummaries(context: context, renderNode: renderNode)[1] | ||
let sectionSummary = summaries[1] | ||
XCTAssertEqual(sectionSummary.title, "Create a New AR Project") | ||
XCTAssertEqual(sectionSummary.path, "/tutorials/testbundle/tutorial#Create-a-New-AR-Project") | ||
XCTAssertEqual(sectionSummary.referenceURL.absoluteString, "doc://com.test.example/tutorials/TestBundle/Tutorial#Create-a-New-AR-Project") | ||
|
@@ -142,6 +144,11 @@ class ExternalLinkableTests: XCTestCase { | |
.text(" "), | ||
.text("ut labore et dolore magna aliqua. Phasellus faucibus scelerisque eleifend donec pretium."), | ||
]) | ||
|
||
// Test that the summaries can be decoded from the encoded data | ||
let encoded = try JSONEncoder().encode(summaries) | ||
let decoded = try JSONDecoder().decode([LinkDestinationSummary].self, from: encoded) | ||
XCTAssertEqual(summaries, decoded) | ||
} | ||
|
||
func testSymbolSummaries() throws { | ||
|
@@ -270,6 +277,64 @@ class ExternalLinkableTests: XCTestCase { | |
]) | ||
} | ||
} | ||
func testDecodingLegacyData() throws { | ||
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. Nice! |
||
let legacyData = """ | ||
{ | ||
"title": "ClassName", | ||
"referenceURL": "doc://org.swift.docc.example/documentation/MyKit/ClassName", | ||
"language": "swift", | ||
"path": "documentation/MyKit/ClassName", | ||
"availableLanguages": [ | ||
"swift" | ||
], | ||
"kind": "org.swift.docc.kind.class", | ||
"abstract": [ | ||
{ | ||
"type": "text", | ||
"text": "A brief explanation of my class." | ||
} | ||
], | ||
"platforms": [ | ||
{ | ||
"name": "PlatformName", | ||
"introducedAt": "1.0" | ||
}, | ||
], | ||
"fragments": [ | ||
{ | ||
"kind": "keyword", | ||
"text": "class" | ||
}, | ||
{ | ||
"kind": "text", | ||
"text": " " | ||
}, | ||
{ | ||
"kind": "identifier", | ||
"text": "ClassName" | ||
} | ||
] | ||
} | ||
""".data(using: .utf8)! | ||
|
||
let decoded = try JSONDecoder().decode(LinkDestinationSummary.self, from: legacyData) | ||
|
||
XCTAssertEqual(decoded.referenceURL, ResolvedTopicReference(bundleIdentifier: "org.swift.docc.example", path: "/documentation/MyKit/ClassName", sourceLanguage: .swift).url) | ||
XCTAssertEqual(decoded.platforms?.count, 1) | ||
XCTAssertEqual(decoded.platforms?.first?.name, "PlatformName") | ||
XCTAssertEqual(decoded.platforms?.first?.introduced, "1.0") | ||
XCTAssertEqual(decoded.kind, .class) | ||
XCTAssertEqual(decoded.title, "ClassName") | ||
XCTAssertEqual(decoded.abstract?.plainText, "A brief explanation of my class.") | ||
XCTAssertEqual(decoded.path, "documentation/MyKit/ClassName") | ||
XCTAssertEqual(decoded.declarationFragments, [ | ||
.init(text: "class", kind: .keyword, identifier: nil), | ||
.init(text: " ", kind: .text, identifier: nil), | ||
.init(text: "ClassName", kind: .identifier, identifier: nil), | ||
]) | ||
|
||
XCTAssert(decoded.variants.isEmpty) | ||
} | ||
|
||
// Workaround that addTeardownBlock doesn't exist in swift-corelibs-xctest | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we use .none here maybe? To differentiate between the wrapper and the inner value a little more.