import SprachmittlerCore import SprachmittlerText import Testing @Suite("Capture policy") struct CapturePolicyTests { @Test func emptyAndWhitespaceTextAreRejected() { #expect(CapturePolicy.validate("") == .empty) #expect(CapturePolicy.validate(" \n\t") == .empty) } @Test func latinLimitIs4000() { #expect(CapturePolicy.validate(String(repeating: "a", count: 4000)) == .valid) #expect( CapturePolicy.validate(String(repeating: "a", count: 4001)) == .textTooLong(characters: 4001, limit: 4000) ) } @Test func denseScriptLimitIs2000() { let valid = String(repeating: "你", count: 2000) let tooLong = String(repeating: "你", count: 2001) #expect(CapturePolicy.validate(valid) == .valid) #expect( CapturePolicy.validate(tooLong) == .textTooLong(characters: 2001, limit: 2000) ) } @Test func partsRaiseTheCaptureLimit() { let limits = CaptureLimits(maximumParts: 3) #expect(CapturePolicy.validate(String(repeating: "a", count: 12000), limits: limits) == .valid) #expect( CapturePolicy.validate(String(repeating: "a", count: 12001), limits: limits) == .textTooLong(characters: 12001, limit: 12000) ) #expect(CapturePolicy.validate(String(repeating: "你", count: 6000), limits: limits) == .valid) #expect( CapturePolicy.validate(String(repeating: "你", count: 6001), limits: limits) == .textTooLong(characters: 6001, limit: 6000) ) } @Test func maximumPartsIsAtLeastOne() { #expect(CaptureLimits(maximumParts: 0).maximumParts == 1) #expect(CaptureLimits(maximumParts: 0).captureLimit(for: "a") == 4000) } @Test func chunkerStillSplitsTheAcceptedText() { let limits = CaptureLimits(maximumParts: 3) let text = String(repeating: "a", count: 12000) #expect(limits.chunker.chunks(for: text).count == 3) } }