Skip to content

Commit 29153f7

Browse files
committed
Add unit test for Punycode
1 parent 22f9a34 commit 29153f7

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)