Skip to content

Commit 6134634

Browse files
committed
Extract mixed-language context tests
Extract `DocumentationContext` tests relating to multi-language support to a separate file.
1 parent bc97f95 commit 6134634

File tree

3 files changed

+93
-79
lines changed

3 files changed

+93
-79
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import XCTest
12+
@testable import SwiftDocC
13+
14+
class DocumentationContext_MixedLanguageSourceLanguagesTests: XCTestCase {
15+
func testArticleAvailableSourceLanguagesIsSwiftInSwiftModule() throws {
16+
try assertArticleAvailableSourceLanguages(
17+
moduleAvailableLanguages: [.swift],
18+
expectedArticleDefaultLanguage: .swift
19+
)
20+
}
21+
22+
func testArticleAvailableSourceLanguagesIsMixedLanguageInMixedLanguageModule() throws {
23+
try assertArticleAvailableSourceLanguages(
24+
moduleAvailableLanguages: [.swift, .objectiveC],
25+
expectedArticleDefaultLanguage: .swift
26+
)
27+
}
28+
29+
func testArticleAvailableSourceLanguagesIsObjectiveCInObjectiveCModule() throws {
30+
try assertArticleAvailableSourceLanguages(
31+
moduleAvailableLanguages: [.objectiveC],
32+
expectedArticleDefaultLanguage: .objectiveC
33+
)
34+
}
35+
36+
func assertArticleAvailableSourceLanguages(
37+
moduleAvailableLanguages: Set<SourceLanguage>,
38+
expectedArticleDefaultLanguage: SourceLanguage,
39+
file: StaticString = #file,
40+
line: UInt = #line
41+
) throws {
42+
precondition(
43+
moduleAvailableLanguages.allSatisfy { [.swift, .objectiveC].contains($0) },
44+
"moduleAvailableLanguages can only contain Swift and Objective-C as languages."
45+
)
46+
47+
let (_, _, context) = try testBundleAndContext(copying: "MixedLanguageFramework") { url in
48+
try """
49+
# MyArticle
50+
51+
The framework this article is documenting is available in the following languages: \
52+
\(moduleAvailableLanguages.map(\.name).joined(separator: ",")).
53+
""".write(to: url.appendingPathComponent("myarticle.md"), atomically: true, encoding: .utf8)
54+
55+
func removeSymbolGraph(compiler: String) throws {
56+
try FileManager.default.removeItem(
57+
at: url.appendingPathComponent("symbol-graphs").appendingPathComponent(compiler)
58+
)
59+
}
60+
61+
if !moduleAvailableLanguages.contains(.swift) {
62+
try removeSymbolGraph(compiler: "swift")
63+
}
64+
65+
if !moduleAvailableLanguages.contains(.objectiveC) {
66+
try removeSymbolGraph(compiler: "clang")
67+
}
68+
}
69+
70+
let articleNode = try XCTUnwrap(
71+
context.documentationCache.first {
72+
$0.key.path == "/documentation/MixedLanguageFramework/myarticle"
73+
}?.value,
74+
file: file,
75+
line: line
76+
)
77+
78+
XCTAssertEqual(
79+
articleNode.availableSourceLanguages,
80+
moduleAvailableLanguages,
81+
"Expected the article's source languages to have inherited from the module's available source languages.",
82+
file: file,
83+
line: line
84+
)
85+
86+
XCTAssertEqual(
87+
articleNode.sourceLanguage,
88+
expectedArticleDefaultLanguage,
89+
file: file,
90+
line: line
91+
)
92+
}
93+
}

Tests/SwiftDocCTests/Infrastructure/DocumentationContextTests.swift renamed to Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,85 +3097,6 @@ let expected = """
30973097
)
30983098
}
30993099

3100-
func assertArticleAvailableSourceLanguages(
3101-
moduleAvailableLanguages: Set<SourceLanguage>,
3102-
expectedArticleDefaultLanguage: SourceLanguage,
3103-
file: StaticString = #file,
3104-
line: UInt = #line
3105-
) throws {
3106-
precondition(
3107-
moduleAvailableLanguages.allSatisfy { [.swift, .objectiveC].contains($0) },
3108-
"moduleAvailableLanguages can only contain Swift and Objective-C as languages."
3109-
)
3110-
3111-
let (_, _, context) = try testBundleAndContext(copying: "MixedLanguageFramework") { url in
3112-
try """
3113-
# MyArticle
3114-
3115-
The framework this article is documenting is available in the following languages: \
3116-
\(moduleAvailableLanguages.map(\.name).joined(separator: ",")).
3117-
""".write(to: url.appendingPathComponent("myarticle.md"), atomically: true, encoding: .utf8)
3118-
3119-
func removeSymbolGraph(compiler: String) throws {
3120-
try FileManager.default.removeItem(
3121-
at: url.appendingPathComponent("symbol-graphs").appendingPathComponent(compiler)
3122-
)
3123-
}
3124-
3125-
if !moduleAvailableLanguages.contains(.swift) {
3126-
try removeSymbolGraph(compiler: "swift")
3127-
}
3128-
3129-
if !moduleAvailableLanguages.contains(.objectiveC) {
3130-
try removeSymbolGraph(compiler: "clang")
3131-
}
3132-
}
3133-
3134-
let articleNode = try XCTUnwrap(
3135-
context.documentationCache.first {
3136-
$0.key.path == "/documentation/MixedLanguageFramework/myarticle"
3137-
}?.value,
3138-
file: file,
3139-
line: line
3140-
)
3141-
3142-
XCTAssertEqual(
3143-
articleNode.availableSourceLanguages,
3144-
moduleAvailableLanguages,
3145-
"Expected the article's source languages to have inherited from the module's available source languages.",
3146-
file: file,
3147-
line: line
3148-
)
3149-
3150-
XCTAssertEqual(
3151-
articleNode.sourceLanguage,
3152-
expectedArticleDefaultLanguage,
3153-
file: file,
3154-
line: line
3155-
)
3156-
}
3157-
3158-
func testArticleAvailableSourceLanguagesIsSwiftInSwiftModule() throws {
3159-
try assertArticleAvailableSourceLanguages(
3160-
moduleAvailableLanguages: [.swift],
3161-
expectedArticleDefaultLanguage: .swift
3162-
)
3163-
}
3164-
3165-
func testArticleAvailableSourceLanguagesIsMixedLanguageInMixedLanguageModule() throws {
3166-
try assertArticleAvailableSourceLanguages(
3167-
moduleAvailableLanguages: [.swift, .objectiveC],
3168-
expectedArticleDefaultLanguage: .swift
3169-
)
3170-
}
3171-
3172-
func testArticleAvailableSourceLanguagesIsObjectiveCInObjectiveCModule() throws {
3173-
try assertArticleAvailableSourceLanguages(
3174-
moduleAvailableLanguages: [.objectiveC],
3175-
expectedArticleDefaultLanguage: .objectiveC
3176-
)
3177-
}
3178-
31793100
func testDocumentationExtensionURLForReferenceReturnsURLForSymbolReference() throws {
31803101
let (bundleURL, _, context) = try testBundleAndContext(copying: "TestBundle")
31813102

0 commit comments

Comments
 (0)