forked from riverqueue/riverui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
int64_string_test.go
38 lines (28 loc) · 890 Bytes
/
int64_string_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
package riverui
import (
"encoding/json"
"math"
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
func TestInt64String(t *testing.T) {
t.Parallel()
t.Run("MarshalJSON", func(t *testing.T) {
t.Parallel()
require.Equal(t, `"123"`, string(mustMarshalJSON(t, int64String(123))))
})
t.Run("UnmarshalJSON", func(t *testing.T) {
t.Parallel()
var myLargeInt int64String
// With quotes.
require.NoError(t, json.Unmarshal([]byte(`"123"`), &myLargeInt))
require.Equal(t, int64String(123), myLargeInt)
// Without quotes.
require.NoError(t, json.Unmarshal([]byte(`123`), &myLargeInt))
require.Equal(t, int64String(123), myLargeInt)
// Integer larger than JSON's maximum number size.
require.NoError(t, json.Unmarshal([]byte(`"`+strconv.FormatInt(math.MaxInt64, 10)+`"`), &myLargeInt))
require.Equal(t, int64String(math.MaxInt64), myLargeInt)
})
}