Sort numeric labels by value
Records, zones and findings now order all-digit labels numerically, so reverse zones list 2 before 101. model.CanonicalLess is replaced by model.NameLess; other labels keep byte order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa8feb6bd9
commit
d18fe18ccd
8 files changed
+96
-15
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNameLess(t *testing.T) {
|
||||
want := []string{
|
||||
"10.0.10.in-addr.arpa.",
|
||||
"1.10.0.10.in-addr.arpa.",
|
||||
"02.10.0.10.in-addr.arpa.",
|
||||
"2.10.0.10.in-addr.arpa.",
|
||||
"10.10.0.10.in-addr.arpa.",
|
||||
"101.10.0.10.in-addr.arpa.",
|
||||
"x.101.10.0.10.in-addr.arpa.",
|
||||
"254.10.0.10.in-addr.arpa.",
|
||||
"a.10.0.10.in-addr.arpa.",
|
||||
}
|
||||
got := slices.Clone(want)
|
||||
slices.Reverse(got)
|
||||
slices.SortFunc(got, func(a, b string) int {
|
||||
if NameLess(a, b) {
|
||||
return -1
|
||||
}
|
||||
if NameLess(b, a) {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
})
|
||||
if !slices.Equal(got, want) {
|
||||
t.Fatalf("got %v\nwant %v", got, want)
|
||||
}
|
||||
|
||||
// Non-numeric labels keep canonical (byte) order.
|
||||
if !NameLess("host10.example.", "host2.example.") {
|
||||
t.Error("host10 should sort before host2")
|
||||
}
|
||||
if !NameLess("example.", "www.example.") {
|
||||
t.Error("parent should sort before child")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user