|
| 1 | +// |
| 2 | +// PunyCodeTests.swift |
| 3 | +// ATSyntaxTools |
| 4 | +// |
| 5 | +// Created by Christopher Jr Riley on 2025-05-18. |
| 6 | +// |
| 7 | + |
| 8 | +import Foundation |
| 9 | +import Testing |
| 10 | +@testable import ATSyntaxTools |
| 11 | + |
| 12 | +@Suite("Punycode Tests") struct PunyCodeTests { |
| 13 | + |
| 14 | + @Test("Get valid punycode.", arguments: PunycodeStrings.validStrings) |
| 15 | + func getValidPunycode(input: String, output: String) async throws { |
| 16 | + let encoded = try Punycode.encodeDomain(input) |
| 17 | + |
| 18 | + try #require(encoded == output, "Encoded string should match expected output.") |
| 19 | + |
| 20 | + let decoded = try Punycode.decodeDomain(encoded) |
| 21 | + |
| 22 | + #expect(decoded == input, "Decoded string should match original input.") |
| 23 | + } |
| 24 | + |
| 25 | + public enum PunycodeStrings { |
| 26 | + public static let validStrings: [(input: String, output: String)] = { |
| 27 | + return [ |
| 28 | + (input: "hello", output: "hello"), |
| 29 | + (input: "1234567890", output: "1234567890"), |
| 30 | + (input: "user-name", output: "user-name"), |
| 31 | + (input: "my.domain", output: "my.domain"), |
| 32 | + (input: "bücher", output: "xn--bcher-kva"), |
| 33 | + (input: "mañana", output: "xn--maana-pta"), |
| 34 | + (input: "façade", output: "xn--faade-zra"), |
| 35 | + (input: "smörgåsbord", output: "xn--smrgsbord-82a8p"), |
| 36 | + (input: "δοκιμή", output: "xn--jxalpdlp"), |
| 37 | + (input: "пример", output: "xn--e1afmkfd"), |
| 38 | + (input: "مثال", output: "xn--mgbh0fb"), |
| 39 | + (input: "דוגמה", output: "xn--6dbbec0c"), |
| 40 | + (input: "テスト", output: "xn--zckzah"), |
| 41 | + (input: "🫂", output: "xn--619h"), |
| 42 | + (input: "🍕.com", output: "xn--vi8h.com"), |
| 43 | + (input: "🫠sss🍿.com", output: "xn--sss-ke13b05r.com") |
| 44 | + ] |
| 45 | + }() |
| 46 | + } |
| 47 | +} |
0 commit comments