go-rfc2234/hexdig_test.go

76 lines
1.2 KiB
Go
Raw Normal View History

2023-10-04 08:37:18 +00:00
package rfc2234_test
import (
"testing"
2024-08-24 13:46:08 +00:00
"github.com/reiver/go-rfc2234"
2023-10-04 08:37:18 +00:00
)
2023-10-04 09:01:51 +00:00
func TestIsHexDig(t *testing.T) {
2023-10-04 08:37:18 +00:00
tests := []struct{
Rune rune
Expected bool
}{
}
for r:=rune(0); r < '0'; r++ {
tests = append(tests, struct{
Rune rune
Expected bool
}{
Rune: r,
Expected: false,
})
}
for r:='0'; r <= '9'; r++ {
tests = append(tests, struct{
Rune rune
Expected bool
}{
Rune: r,
Expected: true,
})
}
for r:='9'+1; r < 'A'; r++ {
tests = append(tests, struct{
Rune rune
Expected bool
}{
Rune: r,
Expected: false,
})
}
for r:='A'; r <= 'F'; r++ {
tests = append(tests, struct{
Rune rune
Expected bool
}{
Rune: r,
Expected: true,
})
}
2023-10-04 09:01:51 +00:00
for r:='F'+1; r < rune(1024); r++ {
2023-10-04 08:37:18 +00:00
tests = append(tests, struct{
Rune rune
Expected bool
}{
Rune: r,
Expected: false,
})
}
for testNumber, test := range tests {
2023-10-04 09:01:51 +00:00
actual := rfc2234.IsHexDig(test.Rune)
2023-10-04 08:37:18 +00:00
expected := test.Expected
if expected != actual {
2023-10-04 09:01:51 +00:00
t.Errorf("For test #%d, the actual value for rfc2234.IsHexDig() is not what was expected.", testNumber)
2023-10-04 08:37:18 +00:00
t.Logf("EXPECTED: %t", expected)
t.Logf("ACTUAL: %t", actual)
t.Logf("RUNE: (%U) %q", test.Rune, string(test.Rune))
continue
}
}
}