MCPcopy Create free account
hub / github.com/buger/jsonparser / TestSetTopLevelArrayAppend_KI4

Function TestSetTopLevelArrayAppend_KI4

parser_test.go:2455–2481  ·  view source on GitHub ↗

Verifies: SYS-REQ-110

(t *testing.T)

Source from the content-addressed store, hash-verified

2453
2454// Verifies: SYS-REQ-110
2455func TestSetTopLevelArrayAppend_KI4(t *testing.T) {
2456 tests := []struct {
2457 name string
2458 data string
2459 setValue string
2460 key string
2461 want string
2462 }{
2463 {name: "append beyond length", data: `[1,2,3]`, setValue: `4`, key: "[5]", want: `[1,2,3,4]`},
2464 {name: "append to empty", data: `[]`, setValue: `1`, key: "[0]", want: `[1]`},
2465 {name: "replace index zero", data: `[1,2]`, setValue: `9`, key: "[0]", want: `[9,2]`},
2466 {name: "replace index one", data: `[1,2]`, setValue: `3`, key: "[1]", want: `[1,3]`},
2467 {name: "append cleans trailing comma", data: `[1,2,]`, setValue: `3`, key: "[5]", want: `[1,2,3]`},
2468 }
2469
2470 for _, test := range tests {
2471 t.Run(test.name, func(t *testing.T) {
2472 got, err := Set([]byte(test.data), []byte(test.setValue), test.key)
2473 if err != nil {
2474 t.Fatalf("Set(%s, %s, %q) returned error: %v", test.data, test.setValue, test.key, err)
2475 }
2476 if string(got) != test.want {
2477 t.Fatalf("Set(%s, %s, %q) = %s, want %s", test.data, test.setValue, test.key, got, test.want)
2478 }
2479 })
2480 }
2481}
2482
2483// Verifies: SYS-REQ-110 [boundary]
2484// SYS-REQ-110:boundary:negative

Callers

nothing calls this directly

Calls 1

SetFunction · 0.85

Tested by

no test coverage detected