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)
| 2498 | // strings, bools, nulls, nested arrays) were silently replaced with |
| 2499 | // [value], destroying all data. |
| 2500 | func TestSetBeyondLengthScalarArrayPreservesElements_SYS110(t *testing.T) { |
| 2501 | cases := []struct { |
| 2502 | name string |
| 2503 | data string |
| 2504 | keys []string |
| 2505 | setValue string |
| 2506 | want string |
| 2507 | }{ |
| 2508 | {"number_array", `{"a":[1,2,3]}`, []string{"a", "[9]"}, `99`, `{"a":[1,2,3,99]}`}, |
| 2509 | {"string_array", `{"a":["x","y"]}`, []string{"a", "[9]"}, `"z"`, `{"a":["x","y","z"]}`}, |
| 2510 | {"bool_array", `{"a":[true,false]}`, []string{"a", "[9]"}, `true`, `{"a":[true,false,true]}`}, |
| 2511 | {"null_array", `{"a":[null,null]}`, []string{"a", "[9]"}, `null`, `{"a":[null,null,null]}`}, |
| 2512 | {"nested_number_array", `{"a":[[1,2]]}`, []string{"a", "[9]"}, `99`, `{"a":[[1,2],99]}`}, |
| 2513 | {"mixed_first_number", `{"a":[1,{"x":2}]}`, []string{"a", "[9]"}, `99`, `{"a":[1,{"x":2},99]}`}, |
| 2514 | {"index_equals_len", `{"a":[1,2,3]}`, []string{"a", "[3]"}, `99`, `{"a":[1,2,3,99]}`}, |
| 2515 | {"index_len_plus_one", `{"a":[1,2,3]}`, []string{"a", "[4]"}, `99`, `{"a":[1,2,3,99]}`}, |
| 2516 | } |
| 2517 | for _, c := range cases { |
| 2518 | t.Run(c.name, func(t *testing.T) { |
| 2519 | got, err := Set([]byte(c.data), []byte(c.setValue), c.keys...) |
| 2520 | if err != nil { |
| 2521 | t.Fatalf("Set(%s,%v) returned error: %v", c.data, c.keys, err) |
| 2522 | } |
| 2523 | if string(got) != c.want { |
| 2524 | 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) |
| 2525 | } |
| 2526 | }) |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | // Verifies: SYS-REQ-029 [malformed_input] |
| 2531 | // SYS-REQ-029:malformed_input:negative |