import Testing @testable import Utility @Suite( "NormalizeEmail method", .tags(.method) ) struct NormalizeEmailTests { // MARK: Properties private let normalize = NormalizeEmail() // MARK: Functional tests @Test(arguments: [ ("fan@loudmail.nl", "fan@loudmail.nl"), ("Fan@LoudMail.NL", "fan@loudmail.nl"), (" fan@loudmail.nl\n", "fan@loudmail.nl"), ("fan+gigs@loudmail.nl", "fan+gigs@loudmail.nl"), // Exactly 254 bytes: the longest address the validator accepts. (String(repeating: "a", count: 242) + "@loudmail.nl", String(repeating: "a", count: 242) + "@loudmail.nl"), ]) func `normalizes a valid address`( submitted: String, expected: String ) { #expect(normalize(submitted) == expected) } @Test(arguments: [ nil, "", " ", "not-an-email", "missing@dot", "@loudmail.nl", "fan@", "fan@.nl", "spaced out@loudmail.nl", "fan@loud mail.nl", // One byte over the 254-byte limit. String(repeating: "a", count: 243) + "@loudmail.nl", // Few enough characters, but multibyte ones put it over the byte limit. String(repeating: "é", count: 130) + "@loudmail.nl", // Control characters are not whitespace, so only the dedicated check catches them. "fan\u{00}@loudmail.nl", "fan@loudmail.nl\u{7F}", ] as [String?]) func `rejects a missing or invalid address`( submitted: String? ) { #expect(normalize(submitted) == nil) } }