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

Function TestGithubIssue13

json/json_test.go:1395–1429  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1393func (s S) String() string { return string(s) }
1394
1395func TestGithubIssue13(t *testing.T) {
1396 // https://github.com/segmentio/encoding/issues/13
1397 v := Issue13{}
1398
1399 b, err := Marshal(v)
1400 if err != nil {
1401 t.Error("unexpected errror:", err)
1402 } else {
1403 t.Log(string(b))
1404 }
1405
1406 v = Issue13{Stringer: S("")}
1407 if err := Unmarshal([]byte(`{"Stringer":null}`), &v); err != nil {
1408 t.Error("unexpected error:", err)
1409 }
1410 if v.Stringer != nil {
1411 t.Error("Stringer field was not overwritten")
1412 }
1413
1414 v = Issue13{}
1415 if err := Unmarshal([]byte(`{"Stringer":"whatever"}`), &v); err == nil {
1416 t.Error("expected error but decoding string value into nil fmt.Stringer but got <nil>")
1417 }
1418
1419 v = Issue13{Stringer: S("")}
1420 if err := Unmarshal([]byte(`{"Stringer":"whatever"}`), &v); err == nil {
1421 t.Error("expected error but decoding string value into non-pointer fmt.Stringer but got <nil>")
1422 }
1423
1424 s := S("")
1425 v = Issue13{Stringer: &s}
1426 if err := Unmarshal([]byte(`{"Stringer":"whatever"}`), &v); err != nil {
1427 t.Error("unexpected error decoding string value into pointer fmt.Stringer:", err)
1428 }
1429}
1430
1431func TestGithubIssue15(t *testing.T) {
1432 // https://github.com/segmentio/encoding/issues/15

Callers

nothing calls this directly

Calls 4

MarshalFunction · 0.70
STypeAlias · 0.70
UnmarshalFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…