MCPcopy Index your code
hub / github.com/segmentio/encoding / TestDecoderInputOffset

Function TestDecoderInputOffset

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

Source from the content-addressed store, hash-verified

1533}
1534
1535func TestDecoderInputOffset(t *testing.T) {
1536 checkOffset := func(o, expected int64) {
1537 if o != expected {
1538 t.Error("unexpected input offset", o, expected)
1539 }
1540 }
1541
1542 b := []byte(`{"userId": "blah"}{"userId": "blah"}
1543 {"userId": "blah"}{"num": 0}`)
1544 d := NewDecoder(bytes.NewReader(b))
1545
1546 var expected int64
1547 checkOffset(d.InputOffset(), expected)
1548
1549 var a struct {
1550 UserId string `json:"userId"`
1551 }
1552
1553 if err := d.Decode(&a); err != nil {
1554 t.Error("unexpected decode error", err)
1555 }
1556 expected = int64(18)
1557 checkOffset(d.InputOffset(), expected)
1558
1559 if err := d.Decode(&a); err != nil {
1560 t.Error("unexpected decode error", err)
1561 }
1562 expected = int64(38)
1563 checkOffset(d.InputOffset(), expected)
1564
1565 if err := d.Decode(&a); err != nil {
1566 t.Error("unexpected decode error", err)
1567 }
1568 expected = int64(56)
1569 checkOffset(d.InputOffset(), expected)
1570
1571 var z struct {
1572 Num int64 `json:"num"`
1573 }
1574 if err := d.Decode(&z); err != nil {
1575 t.Error("unexpected decode error", err)
1576 }
1577 expected = int64(66)
1578 checkOffset(d.InputOffset(), expected)
1579}
1580
1581func TestGithubIssue18(t *testing.T) {
1582 // https://github.com/segmentio/encoding/issues/18

Callers

nothing calls this directly

Calls 5

InputOffsetMethod · 0.95
DecodeMethod · 0.95
NewDecoderFunction · 0.70
NewReaderMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…