github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_null_test.go (about) 1 package jzon 2 3 import ( 4 "io" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestIterator_Null_ReadNull(t *testing.T) { 11 t.Run("eof", func(t *testing.T) { 12 withIterator("", func(it *Iterator) { 13 err := it.ReadNull() 14 require.Equal(t, io.EOF, err) 15 }) 16 }) 17 t.Run("invalid first byte", func(t *testing.T) { 18 withIterator(" a", func(it *Iterator) { 19 err := it.ReadNull() 20 require.IsType(t, UnexpectedByteError{}, err) 21 }) 22 }) 23 t.Run("error 1", func(t *testing.T) { 24 withIterator(" n", func(it *Iterator) { 25 err := it.ReadNull() 26 require.Equal(t, io.EOF, err) 27 }) 28 }) 29 t.Run("error 2", func(t *testing.T) { 30 withIterator(" na", func(it *Iterator) { 31 err := it.ReadNull() 32 require.IsType(t, UnexpectedByteError{}, err) 33 }) 34 }) 35 t.Run("valid", func(t *testing.T) { 36 withIterator(" null ", func(it *Iterator) { 37 err := it.ReadNull() 38 require.NoError(t, err) 39 _, err = it.NextValueType() 40 require.Equal(t, io.EOF, err) 41 }) 42 }) 43 }