miller/pkg/scan/digits_test.go
Stephen Kitt f0a7c5832f
Performance and style fixes (#1981)
* Switch to integer ranges in for loops

Signed-off-by: Stephen Kitt <steve@sk2.org>

* Switch to slices functions where appropriate

A number of utility functions can be replaced outright; since Miller
can technically be used as a library, these are deprecated rather than
removed. go:fix directives ensure that they can be replaced
automatically.

Signed-off-by: Stephen Kitt <steve@sk2.org>

* Switch to reflect.TypeFor

This is slightly more efficient than TypeOf when the type is known at
compile time.

Signed-off-by: Stephen Kitt <steve@sk2.org>

* Switch to strings.SplitSeq instead of strings.Split

SplitSeq results in fewer allocations.

Signed-off-by: Stephen Kitt <steve@sk2.org>

* Drop obsolete build directives

Signed-off-by: Stephen Kitt <steve@sk2.org>

* Use min/max instead of explicit comparisons

Signed-off-by: Stephen Kitt <steve@sk2.org>

* Append slices instead of looping

Signed-off-by: Stephen Kitt <steve@sk2.org>

---------

Signed-off-by: Stephen Kitt <steve@sk2.org>
2026-02-18 09:19:31 -05:00

57 lines
1.1 KiB
Go

package scan
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsDecimalDigit(t *testing.T) {
var c byte
for c = range byte(0xff) {
if c >= '0' && c <= '9' {
assert.True(t, isDecimalDigit(c))
} else {
assert.False(t, isDecimalDigit(c))
}
}
}
func TestIsOctalDigit(t *testing.T) {
var c byte
for c = range byte(0xff) {
if c >= '0' && c <= '7' {
assert.True(t, isOctalDigit(c))
} else {
assert.False(t, isOctalDigit(c))
}
}
}
func TestIsHexDigit(t *testing.T) {
var c byte
for c = range byte(0xff) {
if c >= '0' && c <= '9' {
assert.True(t, isHexDigit(c))
} else if c >= 'a' && c <= 'f' {
assert.True(t, isHexDigit(c))
} else if c >= 'A' && c <= 'F' {
assert.True(t, isHexDigit(c))
} else {
assert.False(t, isHexDigit(c))
}
}
}
func TestIsFloatDigit(t *testing.T) {
var c byte
for c = range byte(0xff) {
if c >= '0' && c <= '9' {
assert.True(t, isFloatDigit(c))
} else if c == '.' || c == '-' || c == '+' || c == 'e' || c == 'E' {
assert.True(t, isFloatDigit(c))
} else {
assert.False(t, isFloatDigit(c))
}
}
}