Read misc.tld from the IANA Root Zone Database #27

Merged
lilleman merged 5 commits from misc-tld into main 2026-09-20 18:23:33 +02:00
Showing only changes of commit 815a24c186 - Show all commits
+25
View File
@@ -9,6 +9,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"unicode"
) )
// writeFiles writes a data directory from a map of relative file name, extension // writeFiles writes a data directory from a map of relative file name, extension
@@ -837,6 +838,30 @@ func TestEveryTimezoneRowIsWellFormed(t *testing.T) {
} }
} }
// TestEveryTldRowSpellsItsKey scans the file rather than drawing: 100 draws leave
// most of 1438 rows unrendered, and the register wraps a right-to-left label in bidi
// marks that belong to its display, not to the label.
func TestEveryTldRowSpellsItsKey(t *testing.T) {
head, rows := shippedRows(t, "tld.tsv", "tld", "type", "unicode")
types := map[string]bool{"country-code": true, "generic": true, "generic-restricted": true, "infrastructure": true, "sponsored": true}
for i, r := range rows {
key, kind, shown := r[head["tld"]], r[head["type"]], r[head["unicode"]]
if !types[kind] {
t.Errorf("tld.tsv line %d: %s is typed %q, which the register assigns no TLD", i+2, key, kind)
}
for _, c := range shown {
if unicode.Is(unicode.Cf, c) {
t.Errorf("tld.tsv line %d: %s displays %q, carrying the format character %U", i+2, key, shown, c)
}
}
if idn := strings.HasPrefix(key, ".xn--"); idn && shown == key {
t.Errorf("tld.tsv line %d: the IDN %s displays its A-label, not a Unicode form", i+2, key)
} else if !idn && shown != key {
t.Errorf("tld.tsv line %d: the ASCII TLD %s displays %q", i+2, key, shown)
}
}
}
// shippedRows reads a shipped misc TSV as the loader does, proving it names the // shippedRows reads a shipped misc TSV as the loader does, proving it names the
// columns asked for and that every row fills them. // columns asked for and that every row fills them.
func shippedRows(t *testing.T, file string, want ...string) (map[string]int, [][]string) { func shippedRows(t *testing.T, file string, want ...string) (map[string]int, [][]string) {