forked from itchyny/gojq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_test.go
47 lines (44 loc) · 960 Bytes
/
type_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
package gojq_test
import (
"fmt"
"math"
"math/big"
"testing"
"github.com/itchyny/gojq"
)
func TestTypeOf(t *testing.T) {
testCases := []struct {
value any
expected string
}{
{nil, "null"},
{false, "boolean"},
{true, "boolean"},
{0, "number"},
{3.14, "number"},
{math.NaN(), "number"},
{math.Inf(1), "number"},
{math.Inf(-1), "number"},
{big.NewInt(10), "number"},
{"string", "string"},
{[]any{}, "array"},
{map[string]any{}, "object"},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%v", tc.value), func(t *testing.T) {
got := gojq.TypeOf(tc.value)
if got != tc.expected {
t.Errorf("TypeOf(%v): got %s, expected %s", tc.value, got, tc.expected)
}
})
}
func() {
v := []int{0}
defer func() {
if got, expected := recover(), "invalid type: []int ([0])"; got != expected {
t.Errorf("TypeOf(%v) should panic: got %v, expected %v", v, got, expected)
}
}()
_ = gojq.TypeOf(v)
}()
}