github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_skip_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_Skip_Skip(t *testing.T) {
    11  	t.Run("eof", func(t *testing.T) {
    12  		withIterator("", func(it *Iterator) {
    13  			err := it.Skip()
    14  			require.Equal(t, io.EOF, err)
    15  		})
    16  	})
    17  	t.Run("skip", func(t *testing.T) {
    18  		s := `{
    19  			"string": "string",
    20  			"null": null,
    21  			"true": true,
    22  			"false": false,
    23  			"number": -123.0456E+789,
    24  			"array": [ "string", null, true, false,
    25  				-123.0456E+789, [ ], { } ],
    26  			"object": {
    27  				"string": "string",
    28  				"null": null,
    29  				"true": true,
    30  				"false": false,
    31  				"number": -123.0456E789,
    32  				"array": [ "string", null, true, false,
    33  					-123.0456E+789, [ ], { } ],
    34  				"object": {	}
    35  			}
    36  		}`
    37  		withIterator(s, func(it *Iterator) {
    38  			err := it.Skip()
    39  			require.NoError(t, err)
    40  			_, err = it.NextValueType()
    41  			require.Equal(t, io.EOF, err)
    42  		})
    43  	})
    44  }