summaryrefslogtreecommitdiff
path: root/SoraTests/ViewDerivedDataTests.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-24 06:35:45 +0000
committerFuwn <[email protected]>2026-03-24 06:35:45 +0000
commit7f488e11caaeb61c478dc39e2793d6ecafa0dfd2 (patch)
tree7e5c2bc3bee6c4d90a78d4e886c31f33b1cce9a1 /SoraTests/ViewDerivedDataTests.swift
parentfeat: add test helper just recipes (diff)
downloadsora-testing-7f488e11caaeb61c478dc39e2793d6ecafa0dfd2.tar.xz
sora-testing-7f488e11caaeb61c478dc39e2793d6ecafa0dfd2.zip
test: update source analysis assertions
Diffstat (limited to 'SoraTests/ViewDerivedDataTests.swift')
-rw-r--r--SoraTests/ViewDerivedDataTests.swift29
1 files changed, 19 insertions, 10 deletions
diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift
index 3270806..a3f2afe 100644
--- a/SoraTests/ViewDerivedDataTests.swift
+++ b/SoraTests/ViewDerivedDataTests.swift
@@ -132,14 +132,22 @@ final class ViewDerivedDataTests: XCTestCase { // swiftlint:disable:this type_b
func testSearchSuggestionsViewDerivesCachedTagsDirectlyFromItems() throws {
let source = try loadSource(at: "Sora/Views/SearchSuggestionsView.swift")
let normalizedSource = strippingCommentsAndStrings(from: source)
+ let cachedTagsSection = try extractFunction(
+ named: "private var cachedTags: [CachedTag]",
+ from: source
+ )
+ let filteredItemsSection = try extractFunction(
+ named: "private var filteredItems: [Either<BooruTag, BooruSearchQuery>]",
+ from: source
+ )
- let computedCacheCount = tokenCount(
- matching: #"\bprivate\s+var\s+cachedTags\s*:\s*\[CachedTag\]"#,
- in: normalizedSource
+ let cacheBuilderCount = tokenCount(
+ matching: #"\bitems\s*\.\s*map\s*\{\s*item\s+in"#,
+ in: cachedTagsSection
)
- let itemsMapCount = tokenCount(
- matching: #"\bitems\s*\.\s*map\s*\{"#,
- in: normalizedSource
+ let cachedTagReuseCount = tokenCount(
+ matching: #"\bfor\s+tag\s+in\s+cachedTags\b"#,
+ in: filteredItemsSection
)
let stateCacheCount = tokenCount(
matching: #"\@State\s+private\s+var\s+cachedTags"#,
@@ -152,15 +160,15 @@ final class ViewDerivedDataTests: XCTestCase { // swiftlint:disable:this type_b
// swiftlint:disable:next prefer_nimble
XCTAssertGreaterThan(
- computedCacheCount,
+ cacheBuilderCount,
0,
"Search suggestions should derive cached tags directly from current items."
)
// swiftlint:disable:next prefer_nimble
XCTAssertGreaterThan(
- itemsMapCount,
+ cachedTagReuseCount,
0,
- "Search suggestions should build cached tags directly from the current items."
+ "Search suggestions should reuse preprocessed cached tags when filtering popup content."
)
// swiftlint:disable:next prefer_nimble
XCTAssertEqual(
@@ -1174,7 +1182,8 @@ final class ViewDerivedDataTests: XCTestCase { // swiftlint:disable:this type_b
in: tagSearchSection
)
let danbooruParserSelectionCount = tokenCount(
- matching: #"flavor\s*==\s*\.danbooru\s*\?\s*DanbooruTagParser\(data:\s*data\)\.parse\(\)"#,
+ matching:
+ #"if\s+flavor\s*==\s*\.danbooru\s*\{\s*DanbooruTagParser\(data:\s*data\)\.parse\(\)"#,
in: searchTagsSection
)