|
| 1 | +// |
| 2 | +// HandleValidation.swift |
| 3 | +// ATSyntaxTools |
| 4 | +// |
| 5 | +// Created by Christopher Jr Riley on 2026-07-03. |
| 6 | +// |
| 7 | + |
| 8 | +import Testing |
| 9 | +@testable import ATSyntaxTools |
| 10 | + |
| 11 | +@Suite("Handle validation", .tags(.handles)) |
| 12 | +public struct HandleValidationTests { |
| 13 | + |
| 14 | + @Test("Accepts valid handles", arguments: TestCases.validHandles) |
| 15 | + public func acceptsValidHandles(_ handle: String) throws { |
| 16 | + try HandleValidator.validate(handle) |
| 17 | + #expect(HandleValidator.isValid(handle)) |
| 18 | + } |
| 19 | + |
| 20 | + @Test("Rejects invalid handles", arguments: TestCases.invalidHandles) |
| 21 | + public func rejectsInvalidHandles(_ handle: String) { |
| 22 | + #expect(!HandleValidator.isValid(handle)) |
| 23 | + #expect(throws: InvalidHandleError.self) { |
| 24 | + try HandleValidator.validate(handle) |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + @Test("Normalizes handles to lowercase ASCII form") |
| 29 | + public func normalizesHandles() throws { |
| 30 | + let normalizedHandle = try HandleValidator.normalize("JoHn.TeST") |
| 31 | + #expect(normalizedHandle == "john.test") |
| 32 | + } |
| 33 | + |
| 34 | + @Test("Rejects handles that fail after normalization") |
| 35 | + public func rejectsInvalidNormalizedHandles() { |
| 36 | + #expect(throws: InvalidHandleError.self) { |
| 37 | + try HandleValidator.normalize("JoH!n.TeST") |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @Test("Reports disallowed TLDs") |
| 42 | + public func reportsDisallowedTLDs() { |
| 43 | + #expect(!HandleValidator.isTLDValid(handle: "laptop.local")) |
| 44 | + #expect(!HandleValidator.isTLDValid(handle: "name.onion")) |
| 45 | + #expect(HandleValidator.isTLDValid(handle: "alice.exampleapp")) |
| 46 | + } |
| 47 | +} |
0 commit comments