mirror of
https://github.com/jimeh/rands.git
synced 2026-02-19 11:26:38 +00:00
fix(strings): add missing benchmark for DNSLabel
This commit is contained in:
105
strings_test.go
105
strings_test.go
@@ -497,54 +497,55 @@ func BenchmarkUnicodeString(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dnsLabelTestCases = []struct {
|
||||||
|
name string
|
||||||
|
n int
|
||||||
|
errIs error
|
||||||
|
errStr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "n=-128",
|
||||||
|
n: -128,
|
||||||
|
errIs: errDNSLabelLength,
|
||||||
|
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
||||||
|
"in length",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "n=0",
|
||||||
|
n: 0,
|
||||||
|
errIs: errDNSLabelLength,
|
||||||
|
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
||||||
|
"in length",
|
||||||
|
},
|
||||||
|
{name: "n=1", n: 1},
|
||||||
|
{name: "n=2", n: 2},
|
||||||
|
{name: "n=3", n: 3},
|
||||||
|
{name: "n=4", n: 4},
|
||||||
|
{name: "n=5", n: 5},
|
||||||
|
{name: "n=6", n: 6},
|
||||||
|
{name: "n=7", n: 7},
|
||||||
|
{name: "n=8", n: 8},
|
||||||
|
{name: "n=16", n: 16},
|
||||||
|
{name: "n=32", n: 32},
|
||||||
|
{name: "n=63", n: 63},
|
||||||
|
{
|
||||||
|
name: "n=64",
|
||||||
|
n: 64,
|
||||||
|
errIs: errDNSLabelLength,
|
||||||
|
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
||||||
|
"in length",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "n=128",
|
||||||
|
n: 128,
|
||||||
|
errIs: errDNSLabelLength,
|
||||||
|
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
||||||
|
"in length",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func TestDNSLabel(t *testing.T) {
|
func TestDNSLabel(t *testing.T) {
|
||||||
tests := []struct {
|
for _, tt := range dnsLabelTestCases {
|
||||||
name string
|
|
||||||
n int
|
|
||||||
errIs error
|
|
||||||
errStr string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "n=-128",
|
|
||||||
n: -128,
|
|
||||||
errIs: errDNSLabelLength,
|
|
||||||
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
|
||||||
"in length",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "n=0",
|
|
||||||
n: 0,
|
|
||||||
errIs: errDNSLabelLength,
|
|
||||||
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
|
||||||
"in length",
|
|
||||||
},
|
|
||||||
{name: "n=1", n: 1},
|
|
||||||
{name: "n=2", n: 2},
|
|
||||||
{name: "n=3", n: 3},
|
|
||||||
{name: "n=4", n: 4},
|
|
||||||
{name: "n=5", n: 5},
|
|
||||||
{name: "n=6", n: 6},
|
|
||||||
{name: "n=7", n: 7},
|
|
||||||
{name: "n=8", n: 8},
|
|
||||||
{name: "n=16", n: 16},
|
|
||||||
{name: "n=32", n: 32},
|
|
||||||
{name: "n=63", n: 63},
|
|
||||||
{
|
|
||||||
name: "n=64",
|
|
||||||
n: 64,
|
|
||||||
errIs: errDNSLabelLength,
|
|
||||||
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
|
||||||
"in length",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "n=128",
|
|
||||||
n: 128,
|
|
||||||
errIs: errDNSLabelLength,
|
|
||||||
errStr: "rands: DNS labels must be between 1 and 63 characters " +
|
|
||||||
"in length",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
// generate lots of labels to increase the chances of catching any
|
// generate lots of labels to increase the chances of catching any
|
||||||
// obscure bugs
|
// obscure bugs
|
||||||
@@ -568,6 +569,16 @@ func TestDNSLabel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkDNSLabel(b *testing.B) {
|
||||||
|
for _, tt := range dnsLabelTestCases {
|
||||||
|
b.Run(tt.name, func(b *testing.B) {
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
_, _ = DNSLabel(tt.n)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Helpers
|
// Helpers
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user