MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / TestSetPath

Function TestSetPath

pkg/ijson/ijson_test.go:52–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestSetPath(t *testing.T) {
53 rtn, err := SetPath(makeValue(), []any{0}, "b", nil)
54 if err != nil {
55 t.Errorf("SetPath failed: %v", err)
56 }
57 if rtn.([]any)[0] != "b" {
58 t.Errorf("SetPath failed: %v", rtn)
59 }
60 rtn, err = SetPath(makeValue(), []any{10}, "b", nil)
61 if err != nil {
62 t.Errorf("SetPath failed: %v", err)
63 }
64 if len(rtn.([]any)) != 11 {
65 t.Errorf("SetPath failed: %v", rtn)
66 }
67 rtn, _ = GetPath(rtn, []any{10})
68 if rtn != "b" {
69 t.Errorf("SetPath failed: %v", rtn)
70 }
71 _, err = SetPath(makeValue(), []any{"a"}, "b", nil)
72 if err == nil {
73 t.Errorf("SetPath should have failed")
74 }
75 rtn, err = SetPath(makeValue(), []any{"a"}, "b", &SetPathOpts{Force: true})
76 if err != nil {
77 t.Errorf("SetPath failed: %v", err)
78 }
79 if !DeepEqual(rtn, map[string]any{"a": "b"}) {
80 t.Errorf("SetPath failed: %v", rtn)
81 }
82 rtn, err = SetPath(makeValue(), nil, "c", &SetPathOpts{CombineFn: CombineFn_ArrayAppend})
83 if err != nil {
84 t.Errorf("SetPath failed: %v", err)
85 }
86 if !DeepEqual(rtn, []any{"a", 2.8, true, map[string]any{"c": 1.1}, "c"}) {
87 t.Errorf("SetPath failed: %v", rtn)
88 }
89 _, err = SetPath(makeValue(), nil, "c", &SetPathOpts{CombineFn: CombineFn_ArrayAppend, Budget: -1})
90 if err == nil {
91 t.Errorf("SetPath should have failed")
92 }
93 rtn, err = SetPath(makeValue(), []any{5000}, "c", nil)
94 if err != nil {
95 t.Errorf("SetPath failed: %v", err)
96 }
97 if len(rtn.([]any)) != 5001 {
98 t.Errorf("SetPath failed: %v", rtn)
99 }
100 _, err = SetPath(makeValue(), []any{5000}, "c", &SetPathOpts{Budget: 1000})
101 if err == nil {
102 t.Errorf("SetPath should have failed")
103 }
104 rtn, err = SetPath(makeValue(), []any{3, "c"}, nil, &SetPathOpts{Remove: true})
105 if err != nil {
106 t.Errorf("SetPath failed: %v", err)
107 }
108 if !DeepEqual(rtn, []any{"a", 2.8, true}) {
109 t.Errorf("SetPath failed: %v", rtn)

Callers

nothing calls this directly

Calls 4

SetPathFunction · 0.85
makeValueFunction · 0.85
GetPathFunction · 0.85
DeepEqualFunction · 0.85

Tested by

no test coverage detected