github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_bool_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_Bool_ReadBool(t *testing.T) { 11 t.Run("eof", func(t *testing.T) { 12 withIterator("", func(it *Iterator) { 13 _, err := it.ReadBool() 14 require.Equal(t, io.EOF, err) 15 }) 16 }) 17 t.Run("invalid fist byte", func(t *testing.T) { 18 withIterator(" a", func(it *Iterator) { 19 _, err := it.ReadBool() 20 require.IsType(t, UnexpectedByteError{}, err) 21 }) 22 }) 23 t.Run("true", func(t *testing.T) { 24 withIterator(" true ", func(it *Iterator) { 25 b, err := it.ReadBool() 26 require.NoError(t, err) 27 require.True(t, b) 28 _, err = it.NextValueType() 29 require.Equal(t, io.EOF, err) 30 }) 31 }) 32 t.Run("false", func(t *testing.T) { 33 withIterator(" false ", func(it *Iterator) { 34 b, err := it.ReadBool() 35 require.NoError(t, err) 36 require.False(t, b) 37 _, err = it.NextValueType() 38 require.Equal(t, io.EOF, err) 39 }) 40 }) 41 }