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

Function TestCodeMCDC_SearchKeysArrayKeyNotBracket

mcdc_supplement_test.go:840–869  ·  view source on GitHub ↗

Verifies: SYS-REQ-001 [boundary] Code MC/DC gap: parser.go:327 searchKeys keys[level][0] != '[' Drive keys[level][0] != '[' to TRUE independently. Use a key with keyLen >= 3 that does NOT start with '['.

(t *testing.T)

Source from the content-addressed store, hash-verified

838// Drive keys[level][0] != '[' to TRUE independently.
839// Use a key with keyLen >= 3 that does NOT start with '['.
840func TestCodeMCDC_SearchKeysArrayKeyNotBracket(t *testing.T) {
841 // Key "abc" has keyLen=3 (>= 3 so first term is FALSE),
842 // and keys[level][0]='a' != '[' (second term is TRUE).
843 _, _, _, err := Get([]byte(`[1,2,3]`), "abc")
844 if err == nil {
845 t.Fatal("Get with non-bracket key on array should fail")
846 }
847
848 // Key "a[0" has keyLen=3 (>= 3), keys[level][0]='a' != '[' (TRUE).
849 _, _, _, err = Get([]byte(`[1,2,3]`), "a[0")
850 if err == nil {
851 t.Fatal("Get with malformed key should fail")
852 }
853
854 // Drive keys[level][0] == '[' (FALSE) with keyLen >= 3
855 // AND keys[level][keyLen-1] != ']' (TRUE): key "[ab"
856 _, _, _, err = Get([]byte(`[1,2,3]`), "[ab")
857 if err == nil {
858 t.Fatal("Get with bracket key without closing bracket should fail")
859 }
860
861 // All three terms FALSE: valid index "[0]"
862 val, _, _, err := Get([]byte(`[10,20,30]`), "[1]")
863 if err != nil {
864 t.Fatalf("Get valid array index error: %v", err)
865 }
866 if string(val) != "20" {
867 t.Fatalf("Get [1] = %q, want %q", string(val), "20")
868 }
869}
870
871// Verifies: SYS-REQ-035 [boundary]
872// Code MC/DC gap: parser.go:801 Delete data[endOffset+tokEnd] == ']' && data[tokStart] == ','

Callers

nothing calls this directly

Calls 1

GetFunction · 0.85

Tested by

no test coverage detected