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

Function TestCodeMCDC_SearchKeysArrayKeyValidation

mcdc_supplement_test.go:524–546  ·  view source on GitHub ↗

Verifies: SYS-REQ-001 [boundary] Code MC/DC gap: parser.go:325 searchKeys Drive keyLen >= 3 so the second and third terms of the disjunction (keys[level][0] != '[' and keys[level][keyLen-1] != ']') are evaluated. A key like "abc" has keyLen=3, starts with 'a' != '[', so the second term is TRUE and s

(t *testing.T)

Source from the content-addressed store, hash-verified

522// term is TRUE and short-circuits. A key like "[ab" has keyLen=3, starts
523// with '[', but does not end with ']', so the third term is TRUE.
524func TestCodeMCDC_SearchKeysArrayKeyValidation(t *testing.T) {
525 // Key "abc" has keyLen=3, keys[level][0]='a' != '[' => TRUE (second term)
526 _, _, _, err := Get([]byte(`[1,2,3]`), "abc")
527 if err == nil {
528 t.Fatal("Get with non-bracket array key should return error")
529 }
530
531 // Key "[ab" has keyLen=3, starts with '[', ends with 'b' != ']' => third term TRUE
532 _, _, _, err = Get([]byte(`[1,2,3]`), "[ab")
533 if err == nil {
534 t.Fatal("Get with malformed bracket key should return error")
535 }
536
537 // Key "[0]" has keyLen=3, starts with '[', ends with ']' => all three terms FALSE
538 // This is the valid path.
539 val, _, _, err := Get([]byte(`[10,20,30]`), "[0]")
540 if err != nil {
541 t.Fatalf("Get with valid array index error: %v", err)
542 }
543 if string(val) != "10" {
544 t.Fatalf("Get [0] = %q, want %q", string(val), "10")
545 }
546}
547
548// Verifies: SYS-REQ-001 [boundary]
549// Code MC/DC gap: parser.go:287 searchKeys keyLevel == level-1

Callers

nothing calls this directly

Calls 1

GetFunction · 0.85

Tested by

no test coverage detected