MCPcopy Create free account
hub / github.com/segmentio/encoding / TestEmptyString

Function TestEmptyString

json/golang_decode_test.go:1621–1636  ·  view source on GitHub ↗

Test that the empty string doesn't panic decoding when ,string is specified Issue 3450

(t *testing.T)

Source from the content-addressed store, hash-verified

1619// Test that the empty string doesn't panic decoding when ,string is specified
1620// Issue 3450
1621func TestEmptyString(t *testing.T) {
1622 type T2 struct {
1623 Number1 int `json:",string"`
1624 Number2 int `json:",string"`
1625 }
1626 data := `{"Number1":"1", "Number2":""}`
1627 dec := NewDecoder(strings.NewReader(data))
1628 var t2 T2
1629 err := dec.Decode(&t2)
1630 if err == nil {
1631 t.Fatal("Decode: did not return error")
1632 }
1633 if t2.Number1 != 1 {
1634 t.Fatal("Decode: did not set Number1")
1635 }
1636}
1637
1638// Test that a null for ,string is not replaced with the previous quoted string (issue 7046).
1639// It should also not be an error (issue 2540, issue 8587).

Callers

nothing calls this directly

Calls 3

DecodeMethod · 0.95
NewDecoderFunction · 0.70
NewReaderMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…