github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/val_decoder_json_rawmessage_test.go (about)

     1  package jzon
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  	"testing"
     7  )
     8  
     9  func TestValDecoder_JsonRawMessage(t *testing.T) {
    10  	f := func(t *testing.T, data string, ex error, initValue string) {
    11  		var p1 *json.RawMessage
    12  		var p2 *json.RawMessage
    13  		if initValue != "" {
    14  			b1 := append(json.RawMessage(nil), initValue...)
    15  			p1 = &b1
    16  			b2 := append(json.RawMessage(nil), initValue...)
    17  			p2 = &b2
    18  		}
    19  		checkDecodeWithStandard(t, DefaultDecoderConfig, data, ex, p1, p2)
    20  	}
    21  	f2 := func(t *testing.T, data string, ex error) {
    22  		f(t, data, ex, "1.23")
    23  	}
    24  	t.Run("nil pointer", func(t *testing.T) {
    25  		f(t, "null", ErrNilPointerReceiver, "")
    26  	})
    27  	t.Run("eof", func(t *testing.T) {
    28  		f2(t, "", io.EOF)
    29  	})
    30  	t.Run("valid", func(t *testing.T) {
    31  		f2(t, `null`, nil)
    32  	})
    33  }