Verifies: SYS-REQ-110 [boundary] SYS-REQ-110:boundary:negative SYS-REQ-110:element_type_partition:nominal Positive/nominal witness for the element_type_partition obligation: Set with a beyond-length array index on a non-empty nested array of SCALAR elements must append at end and preserve all existi
(t *testing.T)
| 2491 | // strings, bools, nulls, nested arrays) were silently replaced with |
| 2492 | // [value], destroying all data. |
| 2493 | func TestSetBeyondLengthScalarArrayPreservesElements_SYS110(t *testing.T) { |
| 2494 | cases := []struct { |
| 2495 | name string |
| 2496 | data string |
| 2497 | keys []string |
| 2498 | setValue string |
| 2499 | want string |
| 2500 | }{ |
| 2501 | {"number_array", `{"a":[1,2,3]}`, []string{"a", "[9]"}, `99`, `{"a":[1,2,3,99]}`}, |
| 2502 | {"string_array", `{"a":["x","y"]}`, []string{"a", "[9]"}, `"z"`, `{"a":["x","y","z"]}`}, |
| 2503 | {"bool_array", `{"a":[true,false]}`, []string{"a", "[9]"}, `true`, `{"a":[true,false,true]}`}, |
| 2504 | {"null_array", `{"a":[null,null]}`, []string{"a", "[9]"}, `null`, `{"a":[null,null,null]}`}, |
| 2505 | {"nested_number_array", `{"a":[[1,2]]}`, []string{"a", "[9]"}, `99`, `{"a":[[1,2],99]}`}, |
| 2506 | {"mixed_first_number", `{"a":[1,{"x":2}]}`, []string{"a", "[9]"}, `99`, `{"a":[1,{"x":2},99]}`}, |
| 2507 | {"index_equals_len", `{"a":[1,2,3]}`, []string{"a", "[3]"}, `99`, `{"a":[1,2,3,99]}`}, |
| 2508 | {"index_len_plus_one", `{"a":[1,2,3]}`, []string{"a", "[4]"}, `99`, `{"a":[1,2,3,99]}`}, |
| 2509 | } |
| 2510 | for _, c := range cases { |
| 2511 | t.Run(c.name, func(t *testing.T) { |
| 2512 | got, err := Set([]byte(c.data), []byte(c.setValue), c.keys...) |
| 2513 | if err != nil { |
| 2514 | t.Fatalf("Set(%s,%v) returned error: %v", c.data, c.keys, err) |
| 2515 | } |
| 2516 | if string(got) != c.want { |
| 2517 | t.Fatalf("Set(%s,%v) = %s; want %s (scalar array elements must be preserved on beyond-length append)", c.data, c.keys, string(got), c.want) |
| 2518 | } |
| 2519 | }) |
| 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | // Verifies: SYS-REQ-029 [malformed_input] |
| 2524 | // SYS-REQ-029:malformed_input:negative |