Added the Utility package (#29)

This PR contains the work done to create the new **Utility** package within the project, and also included in it the `NormalizeEmail` method, as it's not something that belongs to the **Infrastructure** package.

Reviewed-on: rock-n-code/loud-amsterdam#29
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
2026-08-01 11:15:27 +00:00
committed by javier
parent efc933d5d0
commit 5f4316b85b
8 changed files with 193 additions and 6 deletions
@@ -0,0 +1,57 @@
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)
}
}