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

Function TestEscapeControlChars

escape_test.go:379–412  ·  view source on GitHub ↗

Verifies: SYS-REQ-014 (escape handling) reqproof:proptest:skip targeted witness/regression test; not a property-test subject

(t *testing.T)

Source from the content-addressed store, hash-verified

377// Verifies: SYS-REQ-014 (escape handling)
378// reqproof:proptest:skip targeted witness/regression test; not a property-test subject
379func TestEscapeControlChars(t *testing.T) {
380 for c := byte(0); c < 0x20; c++ {
381 escaped := Escape(string([]byte{c}))
382
383 var want string
384 switch c {
385 case '\b':
386 want = `"\b"`
387 case '\f':
388 want = `"\f"`
389 case '\n':
390 want = `"\n"`
391 case '\r':
392 want = `"\r"`
393 case '\t':
394 want = `"\t"`
395 default:
396 want = string([]byte{'"', '\\', 'u', '0', '0', lowerHex[c>>4], lowerHex[c&0x0f], '"'})
397 }
398
399 if got := string(escaped); got != want {
400 t.Errorf("Escape control character 0x%02x = %q; want %q", c, got, want)
401 }
402
403 unescaped, err := Unescape(escaped[1:len(escaped)-1], nil)
404 if err != nil {
405 t.Errorf("Unescape(Escape(0x%02x)) returned error: %v", c, err)
406 continue
407 }
408 if len(unescaped) != 1 || unescaped[0] != c {
409 t.Errorf("Unescape(Escape(0x%02x)) = % x; want %02x", c, unescaped, c)
410 }
411 }
412}
413
414// Verifies: SYS-REQ-014 (escape handling)
415// reqproof:proptest:skip targeted witness/regression test; not a property-test subject

Callers

nothing calls this directly

Calls 2

EscapeFunction · 0.85
UnescapeFunction · 0.85

Tested by

no test coverage detected