-
Notifications
You must be signed in to change notification settings - Fork 5
/
set_test.go
63 lines (44 loc) · 2.26 KB
/
set_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
package lenspath
import "testing"
func TestMapSet_toplevel(t *testing.T) {
data := map[string]string{
"name": "chacha",
"region": "himalayas",
}
checkSetWithLensPath(t, data, []string{"name"}, "chacha_new", false)
}
func TestMapSet_internal(t *testing.T) {
data := getTestMap()
checkSetWithLensPath(t, data, []string{"name"}, "chacha_new", false)
checkSetWithLensPath(t, data, []string{"additional", "birthmark"}, "2.cut on the right hand", false)
checkSetWithLensPath(t, data, []string{"additional", "addi", "code"}, "334532_new", false)
checkSetWithLensPath(t, data, []string{"additional", "tagsList", "*", "tag_h"}, []any{"too heavy", "too light"}, false)
// // tag_w is empty for some entries
checkSetWithLensPath(t, data, []string{"additional", "tagsList", "*", "tag_w"}, []any{"tag_w_new", "tag_w_new2"}, false)
checkSetWithLensPath(t, data, []string{"additional", "tagsList2", "*", "tag_n", "tag_n_1"}, []any{"tag_n_new", "tag_n_new2"}, false)
}
func TestMapSet_complex(t *testing.T) {
data := getTestMap()
// setting to array
checkSetWithLensPath(t, data, []string{"additional", "tagsList3"}, []string{"too heavy", "too light"}, false)
// []any
checkSetWithLensPath(t, data, []string{"additional", "tagsList3"}, []any{nil, "too light"}, false)
// setting to map
checkSetWithLensPath(t, data, []string{"additional", "tagsList3"}, map[string]string{"tag_h": "too heavy", "tag_w": "too light"}, false)
// setting to struct
checkSetWithLensPath(t, data, []string{"additional", "tagsList3"}, struct {
Tag_h string
}{Tag_h: "too heavy"}, false)
// set to nil
checkSetWithLensPath(t, data, []string{"additional", "tagsList3"}, nil, false)
}
func TestMapSet_array(t *testing.T) {
data := getTestMap()
// set array to array of diff size
checkSetWithLensPath(t, data, []string{"additional", "tagsList4"}, []string{"a", "b", "c", "d"}, false)
checkSetWithLensPath(t, data, []string{"additional", "tagsList4", "*"}, []string{"a", "b", "c", "d"}, false)
// // // correct size
checkSetWithLensPath(t, data, []string{"additional", "tagsList2", "*", "tag_h"}, []string{"tag_h1", "tag_h2"}, false)
// // // setting with flattening array
checkSetWithLensPath(t, data, []string{"additional", "tagsList5", "*", "tag_n", "tag_n", "*", "tag_n_1"}, []int{3, 4}, false)
}