1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
package common
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSimpleUTF8DecimalConversion(t *testing.T) {
slice := []uint8{49, 48, 49}
res := UnsafeUTF8DecimalCodePointsToInt(slice)
assert.Equal(t, 101, res)
}
func TestNumberStartingWithZero(t *testing.T) {
slice := []uint8{48, 48, 50}
res := UnsafeUTF8DecimalCodePointsToInt(slice)
assert.Equal(t, 2, res)
}
func TestCharsNotInRange(t *testing.T) {
point := 10
slice := []uint8{uint8(point)} // Line Feed (LF)
res := UnsafeUTF8DecimalCodePointsToInt(slice)
assert.Equal(t, res, -(48 - point))
}
func TestAllDigits(t *testing.T) {
slice := []uint8{49, 50, 51, 52, 53, 54, 55, 56, 57, 48}
res := UnsafeUTF8DecimalCodePointsToInt(slice)
assert.Equal(t, 1234567890, res)
}
|