-
-
Notifications
You must be signed in to change notification settings - Fork 140
/
func_keys_test.go
67 lines (60 loc) · 1019 Bytes
/
func_keys_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 dasel
import (
"github.com/tomwright/dasel/v2/dencoding"
"testing"
)
func TestKeysFunc(t *testing.T) {
testdata := map[string]any{
"object": map[string]any{
"c": 3, "a": 1, "b": 2,
},
"list": []any{111, 222, 333},
"string": "something",
"dencodingMap": dencoding.NewMap().
Set("a", 1).
Set("b", 2).
Set("c", 3),
}
t.Run(
"root",
selectTest(
"keys()",
testdata,
[]any{[]any{"dencodingMap", "list", "object", "string"}},
),
)
t.Run(
"List",
selectTest(
"list.keys()",
testdata,
[]any{[]any{0, 1, 2}},
),
)
t.Run(
"Object",
selectTest(
"object.keys()",
testdata,
[]any{[]any{"a", "b", "c"}}, // sorted
),
)
t.Run(
"Dencoding Map",
selectTest(
"dencodingMap.keys()",
testdata,
[]any{[]any{"a", "b", "c"}}, // sorted
),
)
t.Run("InvalidType",
selectTestErr(
"string.keys()",
testdata,
&ErrInvalidType{
ExpectedTypes: []string{"slice", "array", "map"},
CurrentType: "string",
},
),
)
}