From 7f488e11caaeb61c478dc39e2793d6ecafa0dfd2 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 24 Mar 2026 06:35:45 +0000 Subject: test: update source analysis assertions --- SoraTests/ViewDerivedDataTests.swift | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'SoraTests/ViewDerivedDataTests.swift') 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]", + 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 ) -- cgit v1.2.3