Skip to content

Commit 6a1fbbd

Browse files
curate type-subscript symbols in automatic curation
rdar://99921042
1 parent cf573ed commit 6a1fbbd

File tree

3 files changed

+237
-0
lines changed

3 files changed

+237
-0
lines changed

Sources/SwiftDocC/Infrastructure/Topic Graph/AutomaticCuration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ extension AutomaticCuration {
247247
.`typeProperty`,
248248
.`typeMethod`,
249249
.`enum`,
250+
.`typeSubscript`,
250251

251252
.extendedModule,
252253
.extendedClass,

Tests/SwiftDocCTests/Infrastructure/AutomaticCurationTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,4 +502,39 @@ class AutomaticCurationTests: XCTestCase {
502502
]
503503
)
504504
}
505+
506+
func testTypeSubscriptsAreCuratedProperly() throws {
507+
let symbolURL = Bundle.module.url(
508+
forResource: "TypeSubscript.symbols", withExtension: "json", subdirectory: "Test Resources")!
509+
510+
let (bundleURL, bundle, context) = try testBundleAndContext(copying: "TestBundle") { url in
511+
try? FileManager.default.copyItem(at: symbolURL, to: url.appendingPathComponent("TypeSubscript.symbols.json"))
512+
}
513+
defer {
514+
try? FileManager.default.removeItem(at: bundleURL)
515+
}
516+
517+
let containerDocumentationNode = try context.entity(
518+
with: ResolvedTopicReference(
519+
bundleIdentifier: bundle.identifier,
520+
path: "/documentation/ThirdOrder/SomeStruct",
521+
sourceLanguages: [.swift]
522+
)
523+
)
524+
let topics = try AutomaticCuration.topics(
525+
for: containerDocumentationNode,
526+
withTrait: DocumentationDataVariantsTrait(interfaceLanguage: "swift"),
527+
context: context
528+
)
529+
530+
XCTAssertEqual(
531+
topics.flatMap { taskGroup in
532+
[taskGroup.title] + taskGroup.references.map(\.path)
533+
},
534+
[
535+
"Type Subscripts",
536+
"/documentation/ThirdOrder/SomeStruct/subscript(_:)",
537+
]
538+
)
539+
}
505540
}
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
{
2+
"metadata": {
3+
"formatVersion": {
4+
"major": 0,
5+
"minor": 5,
6+
"patch": 3
7+
},
8+
"generator": "x"
9+
},
10+
"module": {
11+
"name": "ThirdOrder",
12+
"platform": {
13+
"architecture": "x86_64",
14+
"vendor": "apple",
15+
"operatingSystem": {
16+
"name": "macosx",
17+
"minimumVersion": {
18+
"major": 12,
19+
"minor": 4,
20+
"patch": 0
21+
}
22+
}
23+
}
24+
},
25+
"symbols": [
26+
{
27+
"kind": {
28+
"identifier": "swift.type.subscript",
29+
"displayName": "Type Subscript"
30+
},
31+
"identifier": {
32+
"precise": "s:10ThirdOrder10SomeStructVyS2icipZ",
33+
"interfaceLanguage": "swift"
34+
},
35+
"pathComponents": [
36+
"SomeStruct",
37+
"subscript(_:)"
38+
],
39+
"names": {
40+
"title": "subscript(_:)",
41+
"subHeading": [
42+
{
43+
"kind": "keyword",
44+
"spelling": "static"
45+
},
46+
{
47+
"kind": "text",
48+
"spelling": " "
49+
},
50+
{
51+
"kind": "keyword",
52+
"spelling": "subscript"
53+
},
54+
{
55+
"kind": "text",
56+
"spelling": "("
57+
},
58+
{
59+
"kind": "typeIdentifier",
60+
"spelling": "Int",
61+
"preciseIdentifier": "s:Si"
62+
},
63+
{
64+
"kind": "text",
65+
"spelling": ") -> "
66+
},
67+
{
68+
"kind": "typeIdentifier",
69+
"spelling": "Int",
70+
"preciseIdentifier": "s:Si"
71+
}
72+
]
73+
},
74+
"declarationFragments": [
75+
{
76+
"kind": "keyword",
77+
"spelling": "static"
78+
},
79+
{
80+
"kind": "text",
81+
"spelling": " "
82+
},
83+
{
84+
"kind": "keyword",
85+
"spelling": "subscript"
86+
},
87+
{
88+
"kind": "text",
89+
"spelling": "("
90+
},
91+
{
92+
"kind": "internalParam",
93+
"spelling": "idx"
94+
},
95+
{
96+
"kind": "text",
97+
"spelling": ": "
98+
},
99+
{
100+
"kind": "typeIdentifier",
101+
"spelling": "Int",
102+
"preciseIdentifier": "s:Si"
103+
},
104+
{
105+
"kind": "text",
106+
"spelling": ") -> "
107+
},
108+
{
109+
"kind": "typeIdentifier",
110+
"spelling": "Int",
111+
"preciseIdentifier": "s:Si"
112+
},
113+
{
114+
"kind": "text",
115+
"spelling": " { "
116+
},
117+
{
118+
"kind": "keyword",
119+
"spelling": "get"
120+
},
121+
{
122+
"kind": "text",
123+
"spelling": " }"
124+
}
125+
],
126+
"accessLevel": "public",
127+
"location": {
128+
"uri": "file:///path/to/ThirdOrder.swift",
129+
"position": {
130+
"line": 14,
131+
"character": 18
132+
}
133+
}
134+
},
135+
{
136+
"kind": {
137+
"identifier": "swift.struct",
138+
"displayName": "Structure"
139+
},
140+
"identifier": {
141+
"precise": "s:10ThirdOrder10SomeStructV",
142+
"interfaceLanguage": "swift"
143+
},
144+
"pathComponents": [
145+
"SomeStruct"
146+
],
147+
"names": {
148+
"title": "SomeStruct",
149+
"navigator": [
150+
{
151+
"kind": "identifier",
152+
"spelling": "SomeStruct"
153+
}
154+
],
155+
"subHeading": [
156+
{
157+
"kind": "keyword",
158+
"spelling": "struct"
159+
},
160+
{
161+
"kind": "text",
162+
"spelling": " "
163+
},
164+
{
165+
"kind": "identifier",
166+
"spelling": "SomeStruct"
167+
}
168+
]
169+
},
170+
"declarationFragments": [
171+
{
172+
"kind": "keyword",
173+
"spelling": "struct"
174+
},
175+
{
176+
"kind": "text",
177+
"spelling": " "
178+
},
179+
{
180+
"kind": "identifier",
181+
"spelling": "SomeStruct"
182+
}
183+
],
184+
"accessLevel": "public",
185+
"location": {
186+
"uri": "file:///path/to/ThirdOrder.swift",
187+
"position": {
188+
"line": 13,
189+
"character": 14
190+
}
191+
}
192+
}
193+
],
194+
"relationships": [
195+
{
196+
"kind": "memberOf",
197+
"source": "s:10ThirdOrder10SomeStructVyS2icipZ",
198+
"target": "s:10ThirdOrder10SomeStructV"
199+
}
200+
]
201+
}

0 commit comments

Comments
 (0)