diff options
Diffstat (limited to 'SoraTests/ViewDerivedDataTests.swift')
| -rw-r--r-- | SoraTests/ViewDerivedDataTests.swift | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift index d8760e7..bc3a998 100644 --- a/SoraTests/ViewDerivedDataTests.swift +++ b/SoraTests/ViewDerivedDataTests.swift @@ -267,28 +267,32 @@ final class ViewDerivedDataTests: XCTestCase { ) } - private func referenceCount(for symbol: String, in source: String) -> Int { - let totalMatches = tokenCount( - matching: #"\b\#(symbol)\b"#, - in: source + func testThumbnailGridViewAvoidsDirectColumnArrayIndexing() throws { + let source = try loadSource(at: "Sora/Views/Shared/ThumbnailGridView.swift") + let normalizedSource = strippingCommentsAndStrings(from: source) + let directColumnIndexingCount = tokenCount( + matching: #"\bcolumnsData\s*\[\s*columnIndex\s*\]"#, + in: normalizedSource ) - let declarationMatches = tokenCount( - matching: #"\b(?:var|let)\s+\#(symbol)\b"#, - in: source + + // swiftlint:disable:next prefer_nimble + XCTAssertEqual( + directColumnIndexingCount, + 0, + "Thumbnail grid should avoid direct column indexing that can crash when column and data counts drift." ) + } + + private func referenceCount(for symbol: String, in source: String) -> Int { + let totalMatches = tokenCount(matching: #"\b\#(symbol)\b"#, in: source) + let declarationMatches = tokenCount(matching: #"\b(?:var|let)\s+\#(symbol)\b"#, in: source) return max(0, totalMatches - declarationMatches) } private func invocationCount(forFunction name: String, in source: String) -> Int { - let totalMatches = tokenCount( - matching: #"\b\#(name)\s*\("#, - in: source - ) - let declarationMatches = tokenCount( - matching: #"\bfunc\s+\#(name)\s*\("#, - in: source - ) + let totalMatches = tokenCount(matching: #"\b\#(name)\s*\("#, in: source) + let declarationMatches = tokenCount(matching: #"\bfunc\s+\#(name)\s*\("#, in: source) return max(0, totalMatches - declarationMatches) } |