@@ -1265,4 +1265,110 @@ class AutomaticCurationTests: XCTestCase {
1265
1265
XCTAssertFalse ( renderNode. topicSections. first? . generated ?? false )
1266
1266
}
1267
1267
}
1268
+
1269
+ func testAutomaticallyCuratedArticlesAreSortedByTitle( ) throws {
1270
+ // Test bundle with articles where file names and titles are in different orders
1271
+ let catalog = Folder ( name: " TestBundle.docc " , content: [
1272
+ JSONFile ( name: " TestModule.symbols.json " , content: makeSymbolGraph ( moduleName: " TestModule " ) ) ,
1273
+
1274
+ TextFile ( name: " C-Article.md " , utf8Content: """
1275
+ # A Article
1276
+ """ ) ,
1277
+
1278
+ TextFile ( name: " B-Article.md " , utf8Content: """
1279
+ # B Article
1280
+ """ ) ,
1281
+
1282
+ TextFile ( name: " A-Article.md " , utf8Content: """
1283
+ # C Article
1284
+ """ ) ,
1285
+ ] )
1286
+
1287
+ // Load the bundle
1288
+ let ( _, context) = try loadBundle ( catalog: catalog)
1289
+ XCTAssert ( context. problems. isEmpty, " Unexpected problems: \( context. problems. map ( \. diagnostic. summary) ) " )
1290
+
1291
+ // Get the module and its automatic curation groups
1292
+ let moduleReference = try XCTUnwrap ( context. soleRootModuleReference)
1293
+ let moduleNode = try XCTUnwrap ( context. entity ( with: moduleReference) )
1294
+ let symbol = try XCTUnwrap ( moduleNode. semantic as? Symbol )
1295
+ let articlesGroup = try XCTUnwrap (
1296
+ symbol. automaticTaskGroups. first ( where: { $0. title == " Articles " } ) ,
1297
+ " Expected 'Articles' automatic task group "
1298
+ )
1299
+
1300
+ // Get the titles of the articles in the order they appear in the automatic curation
1301
+ let titles = articlesGroup. references. compactMap {
1302
+ context. topicGraph. nodes [ $0] ? . title
1303
+ }
1304
+
1305
+ // Verify we have 3 articles in title order (A, B, C)—file order does not matter
1306
+ XCTAssertEqual ( titles, [ " A Article " , " B Article " , " C Article " ] ,
1307
+ " Articles should be sorted by title, not by file name " )
1308
+ }
1309
+
1310
+ // autoCuratedArticles are sorted by title in a case-insensitive manner
1311
+ // this test verifies that the sorting is correct even when the file names have different cases
1312
+ func testAutomaticallyCuratedArticlesAreSortedByTitleDifferentCases( ) throws {
1313
+
1314
+ // In the catalog, the articles are named with the same letter, different cases,
1315
+ // and other articles are added as well
1316
+ let catalog = Folder ( name: " TestBundle.docc " , content: [
1317
+ JSONFile ( name: " TestModule.symbols.json " , content: makeSymbolGraph ( moduleName: " TestModule " ) ) ,
1318
+
1319
+ TextFile ( name: " C-article.md " , utf8Content: """
1320
+ # C Article
1321
+ """ ) ,
1322
+
1323
+ TextFile ( name: " c-article.md " , utf8Content: """
1324
+ # c Article2
1325
+ """ ) ,
1326
+
1327
+ TextFile ( name: " A-article.md " , utf8Content: """
1328
+ # A Article
1329
+ """ ) ,
1330
+
1331
+ TextFile ( name: " a-article.md " , utf8Content: """
1332
+ # a Article2
1333
+ """ ) ,
1334
+
1335
+ TextFile ( name: " B-article.md " , utf8Content: """
1336
+ # B Article
1337
+ """ ) ,
1338
+
1339
+ TextFile ( name: " b-article.md " , utf8Content: """
1340
+ # b Article2
1341
+ """ ) ,
1342
+
1343
+ TextFile ( name: " k-article.md " , utf8Content: """
1344
+ # k Article
1345
+ """ ) ,
1346
+
1347
+
1348
+ TextFile ( name: " random-article.md " , utf8Content: """
1349
+ # Z Article
1350
+ """ ) ,
1351
+ ] )
1352
+
1353
+ // Load the bundle
1354
+ let ( _, context) = try loadBundle ( catalog: catalog)
1355
+ XCTAssert ( context. problems. isEmpty, " Unexpected problems: \( context. problems. map ( \. diagnostic. summary) ) " )
1356
+
1357
+ // Get the module and its automatic curation groups
1358
+ let moduleReference = try XCTUnwrap ( context. soleRootModuleReference)
1359
+ let moduleNode = try XCTUnwrap ( context. entity ( with: moduleReference) )
1360
+ let symbol = try XCTUnwrap ( moduleNode. semantic as? Symbol )
1361
+ let articlesGroup = try XCTUnwrap (
1362
+ symbol. automaticTaskGroups. first ( where: { $0. title == " Articles " } ) ,
1363
+ " Expected 'Articles' automatic task group "
1364
+ )
1365
+
1366
+ let titles = articlesGroup. references. compactMap {
1367
+ context. topicGraph. nodes [ $0] ? . title
1368
+ }
1369
+
1370
+ // Verify that the articles are sorted by title, not by file name
1371
+ XCTAssertEqual ( titles, [ " A Article " , " a Article2 " , " B Article " , " b Article2 " , " C Article " , " c Article2 " , " k Article " , " Z Article " ] ,
1372
+ " Articles should be sorted by title, not by file name " )
1373
+ }
1268
1374
}
0 commit comments