-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathint64_string_test.go
More file actions
40 lines (29 loc) · 952 Bytes
/
int64_string_test.go
File metadata and controls
40 lines (29 loc) · 952 Bytes
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
package riverui
import (
"encoding/json"
"math"
"strconv"
"testing"
"github.com/stretchr/testify/require"
"riverqueue.com/riverui/internal/uicommontest"
)
func TestInt64String(t *testing.T) {
t.Parallel()
t.Run("MarshalJSON", func(t *testing.T) {
t.Parallel()
require.Equal(t, `"123"`, string(uicommontest.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)
})
}