summaryrefslogtreecommitdiff
path: root/SoraTests/SettingsManagerSyncTests.swift
diff options
context:
space:
mode:
Diffstat (limited to 'SoraTests/SettingsManagerSyncTests.swift')
-rw-r--r--SoraTests/SettingsManagerSyncTests.swift77
1 files changed, 77 insertions, 0 deletions
diff --git a/SoraTests/SettingsManagerSyncTests.swift b/SoraTests/SettingsManagerSyncTests.swift
index 50106dc..8ed9d83 100644
--- a/SoraTests/SettingsManagerSyncTests.swift
+++ b/SoraTests/SettingsManagerSyncTests.swift
@@ -91,6 +91,83 @@ final class SettingsManagerSyncTests: XCTestCase {
)
}
+ func testSearchHistoryMutationPathReusesSortedPayloadAndAvoidsInlineResort() throws {
+ let source = try loadSource(at: "Sora/Data/Settings/SettingsManager.swift")
+ let searchHistorySetterSection = try extractFunction(
+ named: "var searchHistory: [BooruSearchQuery]",
+ from: source
+ )
+ let updateSearchHistorySection = try extractFunction(
+ named: "func updateSearchHistory(",
+ from: source
+ )
+ let normalizedSetterSection = strippingCommentsAndStrings(from: searchHistorySetterSection)
+ let normalizedUpdateSection = strippingCommentsAndStrings(from: updateSearchHistorySection)
+ let setterSortedHistoryDeclarationCount = tokenCount(
+ matching: #"\blet\s+sortedSearchHistory\s*="#,
+ in: normalizedSetterSection
+ )
+ let setterInlineSortClosureCount = tokenCount(
+ matching: #"syncableData\s*\([\s\S]*?\)\s*\{\s*\$0\s*\.\s*sorted"#,
+ in: normalizedSetterSection
+ )
+ let setterPreEncodedForwardCount = tokenCount(
+ matching: #"syncableData\s*\([\s\S]*?\bencodedData\s*:"#,
+ in: normalizedSetterSection
+ )
+
+ let updateSortedHistoryDeclarationCount = tokenCount(
+ matching: #"\blet\s+sortedSearchHistory\s*="#,
+ in: normalizedUpdateSection
+ )
+ let updateInlineSortClosureCount = tokenCount(
+ matching: #"syncableData\s*\([\s\S]*?\)\s*\{\s*\$0\s*\.\s*sorted"#,
+ in: normalizedUpdateSection
+ )
+ let updatePreEncodedForwardCount = tokenCount(
+ matching: #"syncableData\s*\([\s\S]*?\bencodedData\s*:"#,
+ in: normalizedUpdateSection
+ )
+
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ setterSortedHistoryDeclarationCount,
+ 0,
+ "searchHistory setter should precompute sorted values once."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ setterInlineSortClosureCount,
+ 0,
+ "searchHistory setter should avoid inline resorting inside syncableData."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ setterPreEncodedForwardCount,
+ 0,
+ "searchHistory setter should forward a pre-encoded payload to syncableData."
+ )
+
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ updateSortedHistoryDeclarationCount,
+ 0,
+ "updateSearchHistory should precompute sorted values once."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertEqual(
+ updateInlineSortClosureCount,
+ 0,
+ "updateSearchHistory should avoid inline resorting inside syncableData."
+ )
+ // swiftlint:disable:next prefer_nimble
+ XCTAssertGreaterThan(
+ updatePreEncodedForwardCount,
+ 0,
+ "updateSearchHistory should forward a pre-encoded payload to syncableData."
+ )
+ }
+
func testBatchedSyncPathGuardsUnchangedPayloadWrites() throws {
let source = try loadSource(at: "Sora/Data/Settings/SettingsManager.swift")
let triggerSyncSection = try extractFunction(