-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalueNumbers_test.go
67 lines (51 loc) · 1.44 KB
/
valueNumbers_test.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package dataparse
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestValue_Int(t *testing.T) {
parsed, err := NewValue("123").Int()
require.Nil(t, err)
assert.Equal(t, 123, parsed)
parsed, err = NewValue("123.6").Int()
require.Nil(t, err)
assert.Equal(t, 123, parsed)
parsed, err = NewValue("123.0").Int()
require.Nil(t, err)
assert.Equal(t, 123, parsed)
parsed, err = NewValue(" 123.0").Int()
require.Nil(t, err)
assert.Equal(t, 123, parsed)
parsed, err = NewValue("123.0 ").Int()
require.Nil(t, err)
assert.Equal(t, 123, parsed)
parsed, err = NewValue(" 123.0 ").Int()
require.Nil(t, err)
assert.Equal(t, 123, parsed)
parsed, err = NewValue("").Int()
require.Nil(t, err)
assert.Equal(t, 0, parsed)
parsed, err = NewValue(0).Int()
require.Nil(t, err)
assert.Equal(t, 0, parsed)
parsed, err = NewValue(math.MaxInt64).Int()
require.Nil(t, err)
assert.Equal(t, math.MaxInt64, parsed)
parsed, err = NewValue(0x00).Int()
require.Nil(t, err)
assert.Equal(t, 0, parsed)
parsed, err = NewValue(0x08).Int()
require.Nil(t, err)
assert.Equal(t, 8, parsed)
parsed, err = NewValue([]byte{0x9c, 0x85, 0xe3, 0xb, 0x0, 0x0, 0x0, 0x0}).Int()
require.Nil(t, err)
assert.Equal(t, 12345678, parsed)
parsed, err = NewValue(true).Int()
require.Nil(t, err)
assert.Equal(t, 1, parsed)
parsed, err = NewValue(false).Int()
require.Nil(t, err)
assert.Equal(t, 0, parsed)
}