github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_val_test.go (about) 1 package jzon 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestIterator_Val_ReadVal(t *testing.T) { 10 t.Run("nil pointer receiver error", func(t *testing.T) { 11 withIterator("", func(it *Iterator) { 12 err := it.ReadVal(nil) 13 require.Equal(t, ErrNilPointerReceiver, err) 14 }) 15 }) 16 t.Run("pointer receiver error", func(t *testing.T) { 17 withIterator("", func(it *Iterator) { 18 var o string 19 err := it.ReadVal(o) 20 require.Equal(t, ErrPointerReceiver, err) 21 }) 22 }) 23 t.Run("struct", func(t *testing.T) { 24 withIterator(` { "k": "v" } `, func(it *Iterator) { 25 var p struct { 26 K string `json:"k"` 27 } 28 err := it.ReadVal(&p) 29 require.NoError(t, err) 30 require.Equal(t, "v", p.K) 31 }) 32 }) 33 }