|
1 | 1 | /*
|
2 | 2 | This source file is part of the Swift.org open source project
|
3 | 3 |
|
4 |
| - Copyright (c) 2021-2022 Apple Inc. and the Swift project authors |
| 4 | + Copyright (c) 2021-2024 Apple Inc. and the Swift project authors |
5 | 5 | Licensed under Apache License v2.0 with Runtime Library Exception
|
6 | 6 |
|
7 | 7 | See https://swift.org/LICENSE.txt for license information
|
@@ -96,4 +96,104 @@ class DocumentationContext_RootPageTests: XCTestCase {
|
96 | 96 | XCTAssertEqual(solution.replacements.first?.range.upperBound.line, 3)
|
97 | 97 | }
|
98 | 98 |
|
| 99 | + func testSingleArticleWithoutTechnologyRootDirective() throws { |
| 100 | + let tempFolderURL = try createTempFolder(content: [ |
| 101 | + Folder(name: "Something.docc", content: [ |
| 102 | + TextFile(name: "Article.md", utf8Content: """ |
| 103 | + # My article |
| 104 | + |
| 105 | + A regular article without an explicit `@TechnologyRoot` directive. |
| 106 | + """) |
| 107 | + ]), |
| 108 | + ]) |
| 109 | + |
| 110 | + let workspace = DocumentationWorkspace() |
| 111 | + let context = try DocumentationContext(dataProvider: workspace) |
| 112 | + let dataProvider = try LocalFileSystemDataProvider(rootURL: tempFolderURL) |
| 113 | + try workspace.registerProvider(dataProvider) |
| 114 | + |
| 115 | + XCTAssertEqual(context.knownPages.map(\.absoluteString), ["doc://Something/documentation/Article"]) |
| 116 | + XCTAssertEqual(context.rootModules.map(\.absoluteString), ["doc://Something/documentation/Article"]) |
| 117 | + |
| 118 | + XCTAssertEqual(context.problems.count, 0) |
| 119 | + } |
| 120 | + |
| 121 | + func testMultipleArticlesWithoutTechnologyRootDirective() throws { |
| 122 | + let tempFolderURL = try createTempFolder(content: [ |
| 123 | + Folder(name: "Something.docc", content: [ |
| 124 | + TextFile(name: "First.md", utf8Content: """ |
| 125 | + # My first article |
| 126 | + |
| 127 | + A regular article without an explicit `@TechnologyRoot` directive. |
| 128 | + """), |
| 129 | + |
| 130 | + TextFile(name: "Second.md", utf8Content: """ |
| 131 | + # My second article |
| 132 | + |
| 133 | + Another regular article without an explicit `@TechnologyRoot` directive. |
| 134 | + """), |
| 135 | + |
| 136 | + TextFile(name: "Third.md", utf8Content: """ |
| 137 | + # My third article |
| 138 | + |
| 139 | + Yet another regular article without an explicit `@TechnologyRoot` directive. |
| 140 | + """), |
| 141 | + ]), |
| 142 | + ]) |
| 143 | + |
| 144 | + let workspace = DocumentationWorkspace() |
| 145 | + let context = try DocumentationContext(dataProvider: workspace) |
| 146 | + let dataProvider = try LocalFileSystemDataProvider(rootURL: tempFolderURL) |
| 147 | + try workspace.registerProvider(dataProvider) |
| 148 | + |
| 149 | + XCTAssertEqual(context.knownPages.map(\.absoluteString).sorted(), [ |
| 150 | + "doc://Something/documentation/Something", // A synthesized root |
| 151 | + "doc://Something/documentation/Something/First", |
| 152 | + "doc://Something/documentation/Something/Second", |
| 153 | + "doc://Something/documentation/Something/Third", |
| 154 | + ]) |
| 155 | + XCTAssertEqual(context.rootModules.map(\.absoluteString), ["doc://Something/documentation/Something"], "If no single article is a clear root, the root page is synthesized") |
| 156 | + |
| 157 | + XCTAssertEqual(context.problems.count, 0) |
| 158 | + } |
| 159 | + |
| 160 | + func testMultipleArticlesWithoutTechnologyRootDirectiveWithOneMatchingTheCatalogName() throws { |
| 161 | + let tempFolderURL = try createTempFolder(content: [ |
| 162 | + Folder(name: "Something.docc", content: [ |
| 163 | + TextFile(name: "Something.md", utf8Content: """ |
| 164 | + # Some article |
| 165 | + |
| 166 | + A regular article without an explicit `@TechnologyRoot` directive. |
| 167 | + |
| 168 | + The name of this article file matches the name of the catalog. |
| 169 | + """), |
| 170 | + |
| 171 | + TextFile(name: "Second.md", utf8Content: """ |
| 172 | + # My second article |
| 173 | + |
| 174 | + Another regular article without an explicit `@TechnologyRoot` directive. |
| 175 | + """), |
| 176 | + |
| 177 | + TextFile(name: "Third.md", utf8Content: """ |
| 178 | + # My third article |
| 179 | + |
| 180 | + Yet another regular article without an explicit `@TechnologyRoot` directive. |
| 181 | + """), |
| 182 | + ]), |
| 183 | + ]) |
| 184 | + |
| 185 | + let workspace = DocumentationWorkspace() |
| 186 | + let context = try DocumentationContext(dataProvider: workspace) |
| 187 | + let dataProvider = try LocalFileSystemDataProvider(rootURL: tempFolderURL) |
| 188 | + try workspace.registerProvider(dataProvider) |
| 189 | + |
| 190 | + XCTAssertEqual(context.knownPages.map(\.absoluteString).sorted(), [ |
| 191 | + "doc://Something/documentation/Something", // This article became the root |
| 192 | + "doc://Something/documentation/Something/Second", |
| 193 | + "doc://Something/documentation/Something/Third", |
| 194 | + ]) |
| 195 | + XCTAssertEqual(context.rootModules.map(\.absoluteString), ["doc://Something/documentation/Something"]) |
| 196 | + |
| 197 | + XCTAssertEqual(context.problems.count, 0) |
| 198 | + } |
99 | 199 | }
|
0 commit comments