File: preview_test.go

package info (click to toggle)
golang-github-wader-gojq 0.0~git20231105.2b6d9e2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 960 kB
  • sloc: yacc: 642; makefile: 84
file content (114 lines) | stat: -rw-r--r-- 2,144 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package gojq_test

import (
	"fmt"
	"math"
	"math/big"
	"testing"

	"github.com/wader/gojq"
)

func TestPreview(t *testing.T) {
	testCases := []struct {
		value    any
		expected string
	}{
		{
			nil,
			"null",
		},
		{
			false,
			"false",
		},
		{
			true,
			"true",
		},
		{
			0,
			"0",
		},
		{
			3.14,
			"3.14",
		},
		{
			math.NaN(),
			"null",
		},
		{
			math.Inf(1),
			"1.7976931348623157e+308",
		},
		{
			math.Inf(-1),
			"-1.7976931348623157e+308",
		},
		{
			big.NewInt(9223372036854775807),
			"9223372036854775807",
		},
		{
			new(big.Int).SetBytes([]byte("\x0c\x9f\x2c\x9c\xd0\x46\x74\xed\xea\x3f\xff\xff\xff")),
			"999999999999999999999999999999",
		},
		{
			new(big.Int).SetBytes([]byte("\x0c\x9f\x2c\x9c\xd0\x46\x74\xed\xea\x40\x00\x00\x00")),
			"10000000000000000000000000 ...",
		},
		{
			"0 1 2 3 4 5 6 7 8 9 10 11 12",
			`"0 1 2 3 4 5 6 7 8 9 10 11 12"`,
		},
		{
			"0 1 2 3 4 5 6 7 8 9 10 11 12 13",
			`"0 1 2 3 4 5 6 7 8 9 10 1 ..."`,
		},
		{
			"0123456789",
			`"01234567 ..."`,
		},
		{
			[]any{},
			"[]",
		},
		{
			[]any{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
			"[0,1,2,3,4,5,6,7,8,9,10,11,12]",
		},
		{
			[]any{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
			"[0,1,2,3,4,5,6,7,8,9,10,1 ...]",
		},
		{
			[]any{[]any{[]any{[]any{[]any{[]any{[]any{[]any{nil, nil, nil}}}}}}}},
			"[[[[[[[[null,null,null]]]]]]]]",
		},
		{
			[]any{[]any{[]any{[]any{[]any{[]any{[]any{[]any{nil, nil, nil, nil}}}}}}}},
			"[[[[[[[[null,null,null,nu ...]",
		},
		{
			map[string]any{},
			"{}",
		},
		{
			map[string]any{"0": map[string]any{"1": map[string]any{"2": map[string]any{"3": []any{nil}}}}},
			`{"0":{"1":{"2":{"3":[null]}}}}`,
		},
		{
			map[string]any{"0": map[string]any{"1": map[string]any{"2": map[string]any{"3": map[string]any{"4": map[string]any{}}}}}},
			`{"0":{"1":{"2":{"3":{"4": ...}`,
		},
	}
	for _, tc := range testCases {
		t.Run(fmt.Sprintf("%v", tc.value), func(t *testing.T) {
			got := gojq.Preview(tc.value)
			if got != tc.expected {
				t.Errorf("Preview(%v): got %s, expected %s", tc.value, got, tc.expected)
			}
		})
	}
}