summaryrefslogtreecommitdiff
path: root/SoraTests
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-18 12:45:11 -0800
committerFuwn <[email protected]>2026-02-18 12:45:19 -0800
commit2aaf7665047f61e72495b99b6caaef54d19332fe (patch)
treec82cbc7a8b99bdc2eb59e75748c2c18bb9d39713 /SoraTests
parentperf: memoize post grid derived collections and remove columns cache (diff)
downloadsora-testing-2aaf7665047f61e72495b99b6caaef54d19332fe.tar.xz
sora-testing-2aaf7665047f61e72495b99b6caaef54d19332fe.zip
chore: finalise performance optimisation batch and metrics
Diffstat (limited to 'SoraTests')
-rw-r--r--SoraTests/ViewDerivedDataTests.swift76
1 files changed, 76 insertions, 0 deletions
diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift
index a97465d..d8760e7 100644
--- a/SoraTests/ViewDerivedDataTests.swift
+++ b/SoraTests/ViewDerivedDataTests.swift
@@ -191,6 +191,82 @@ final class ViewDerivedDataTests: XCTestCase {
)
}
+ func testListViewsAvoidComparatorRandomShuffleSorting() throws {
+ let listViewSource = try loadSource(at: "Sora/Views/Generic/GenericListView.swift")
+ let favoritesViewSource = try loadSource(at: "Sora/Views/FavoritesView.swift")
+ let normalizedListViewSource = strippingCommentsAndStrings(from: listViewSource)
+ let normalizedFavoritesViewSource = strippingCommentsAndStrings(from: favoritesViewSource)
+
+ let listViewComparatorRandomCount = tokenCount(
+ matching: #"\bBool\s*\.\s*random\s*\("#,
+ in: normalizedListViewSource
+ )
+ let favoritesViewComparatorRandomCount = tokenCount(
+ matching: #"\bBool\s*\.\s*random\s*\("#,
+ in: normalizedFavoritesViewSource
+ )
+
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ listViewComparatorRandomCount,
+ 0,
+ "Generic list sorting should not use comparator-based random ordering."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ favoritesViewComparatorRandomCount,
+ 0,
+ "Favorites sorting should not use comparator-based random ordering."
+ )
+ }
+
+ func testBooruManagerRemovesUnusedXMLParserPoolPaths() throws {
+ let source = try loadSource(at: "Sora/Data/Booru/BooruManager.swift")
+ let normalizedSource = strippingCommentsAndStrings(from: source)
+
+ let poolStorageCount = tokenCount(
+ matching: #"\bxmlParserPool\b"#,
+ in: normalizedSource
+ )
+ let lockStorageCount = tokenCount(
+ matching: #"\bparserPoolLock\b"#,
+ in: normalizedSource
+ )
+ let parserFactoryCount = invocationCount(
+ forFunction: "xmlParser",
+ in: normalizedSource
+ )
+ let parserReturnCount = invocationCount(
+ forFunction: "returnXMLParser",
+ in: normalizedSource
+ )
+
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ poolStorageCount,
+ 0,
+ "BooruManager should not keep an unused XML parser pool."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ lockStorageCount,
+ 0,
+ "BooruManager should not keep an unused parser pool lock."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ parserFactoryCount,
+ 0,
+ "BooruManager should not expose unused xml parser factory paths."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ parserReturnCount,
+ 0,
+ "BooruManager should not expose unused xml parser return paths."
+ )
+ }
+
private func referenceCount(for symbol: String, in source: String) -> Int {
let totalMatches = tokenCount(
matching: #"\b\#(symbol)\b"#,