-
Notifications
You must be signed in to change notification settings - Fork 144
Fix custom doc link title issue #376
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
Merged
Kyle-Ye
merged 3 commits into
swiftlang:main
from
Kyle-Ye:bugfix/kyle/custom-link-titles
Mar 15, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
134 changes: 134 additions & 0 deletions
134
Tests/SwiftDocCTests/Rendering/RenderContentCompilerTests.swift
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 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 | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
import Markdown | ||
@testable import SwiftDocC | ||
import XCTest | ||
|
||
class RenderContentCompilerTests: XCTestCase { | ||
func testLinkOverrideTitle() throws { | ||
let (bundle, context) = try testBundleAndContext(named: "TestBundle") | ||
var compiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/path", fragment: nil, sourceLanguage: .swift)) | ||
|
||
let source = """ | ||
[Example](http://example.com) | ||
|
||
[Custom Title](doc:UNRESOVLED) | ||
|
||
[Custom Title](doc:article) | ||
|
||
[Custom Image Content ](doc:article2) | ||
|
||
<doc:UNRESOVLED> | ||
|
||
<doc:article3> | ||
""" | ||
let document = Document(parsing: source) | ||
let expectedDump = """ | ||
Document | ||
├─ Paragraph | ||
│ └─ Link destination: "http://example.com" | ||
│ └─ Text "Example" | ||
├─ Paragraph | ||
│ └─ Link destination: "doc:UNRESOVLED" | ||
│ └─ Text "Custom Title" | ||
├─ Paragraph | ||
│ └─ Link destination: "doc:article" | ||
│ └─ Text "Custom Title" | ||
├─ Paragraph | ||
│ └─ Link destination: "doc:article2" | ||
│ ├─ Text "Custom Image Content " | ||
│ └─ Image source: "https://example.com/test.png" title: "" | ||
│ └─ Text "random image" | ||
├─ Paragraph | ||
│ └─ Link destination: "doc:UNRESOVLED" | ||
│ └─ Text "doc:UNRESOVLED" | ||
└─ Paragraph | ||
└─ Link destination: "doc:article3" | ||
└─ Text "doc:article3" | ||
""" | ||
XCTAssertEqual(document.debugDescription(), expectedDump) | ||
|
||
let result = document.children.flatMap { compiler.visit($0) } | ||
XCTAssertEqual(result.count, 6) | ||
|
||
do { | ||
guard case let .paragraph(paragraph) = result[0] as? RenderBlockContent else { | ||
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)") | ||
return | ||
} | ||
let link = RenderInlineContent.reference( | ||
identifier: .init(forExternalLink: "http://example.com"), | ||
isActive: true, | ||
overridingTitle: nil, | ||
overridingTitleInlineContent: nil | ||
) | ||
XCTAssertEqual(paragraph, RenderBlockContent.Paragraph(inlineContent: [link])) | ||
} | ||
do { | ||
guard case let .paragraph(paragraph) = result[1] as? RenderBlockContent else { | ||
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)") | ||
return | ||
} | ||
let text = RenderInlineContent.text("Custom Title") | ||
XCTAssertEqual(paragraph, RenderBlockContent.Paragraph(inlineContent: [text])) | ||
} | ||
do { | ||
guard case let .paragraph(paragraph) = result[2] as? RenderBlockContent else { | ||
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)") | ||
return | ||
} | ||
let link = RenderInlineContent.reference( | ||
identifier: .init("doc://org.swift.docc.example/documentation/Test-Bundle/article"), | ||
isActive: true, | ||
overridingTitle: "Custom Title", | ||
overridingTitleInlineContent: [.text("Custom Title")]) | ||
XCTAssertEqual(paragraph, RenderBlockContent.Paragraph(inlineContent: [link])) | ||
} | ||
do { | ||
guard case let .paragraph(paragraph) = result[3] as? RenderBlockContent else { | ||
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)") | ||
return | ||
} | ||
let link = RenderInlineContent.reference( | ||
identifier: .init("doc://org.swift.docc.example/documentation/Test-Bundle/article2"), | ||
isActive: true, | ||
overridingTitle: "Custom Image Content ", | ||
overridingTitleInlineContent: [ | ||
RenderInlineContent.text("Custom Image Content "), | ||
RenderInlineContent.image(identifier: .init(forExternalLink: "https://example.com/test.png"), metadata: nil) | ||
] | ||
) | ||
XCTAssertEqual(paragraph, RenderBlockContent.Paragraph(inlineContent: [link])) | ||
} | ||
do { | ||
guard case let .paragraph(paragraph) = result[4] as? RenderBlockContent else { | ||
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)") | ||
return | ||
} | ||
let text = RenderInlineContent.text("doc:UNRESOVLED") | ||
XCTAssertEqual(paragraph, RenderBlockContent.Paragraph(inlineContent: [text])) | ||
} | ||
do { | ||
guard case let .paragraph(paragraph) = result[5] as? RenderBlockContent else { | ||
XCTFail("RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph)") | ||
return | ||
} | ||
let link = RenderInlineContent.reference( | ||
identifier: .init("doc://org.swift.docc.example/documentation/Test-Bundle/article3"), | ||
isActive: true, | ||
overridingTitle: nil, | ||
overridingTitleInlineContent: nil | ||
) | ||
XCTAssertEqual(paragraph, RenderBlockContent.Paragraph(inlineContent: [link])) | ||
} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.