Selaa lähdekoodia

#63 add more tests for json.RawMessage

Tao Wen 8 vuotta sitten
vanhempi
commit
3b883aeffc
2 muutettua tiedostoa jossa 29 lisäystä ja 10 poistoa
  1. 0 10
      jsoniter_array_test.go
  2. 29 0
      jsoniter_raw_message_test.go

+ 0 - 10
jsoniter_array_test.go

@@ -146,16 +146,6 @@ func Test_write_array_of_interface_in_struct(t *testing.T) {
 	should.Contains(str, `"Field2":""`)
 }
 
-func Test_json_RawMessage(t *testing.T) {
-	should := require.New(t)
-	var data json.RawMessage
-	should.Nil(Unmarshal([]byte(`[1,2,3]`), &data))
-	should.Equal(`[1,2,3]`, string(data))
-	str, err := MarshalToString(data)
-	should.Nil(err)
-	should.Equal(`[1,2,3]`, str)
-}
-
 func Test_encode_byte_array(t *testing.T) {
 	should := require.New(t)
 	bytes, err := json.Marshal([]byte{1, 2, 3})

+ 29 - 0
jsoniter_raw_message_test.go

@@ -0,0 +1,29 @@
+package jsoniter
+
+import (
+	"testing"
+	"encoding/json"
+	"github.com/json-iterator/go/require"
+)
+
+func Test_json_RawMessage(t *testing.T) {
+	should := require.New(t)
+	var data json.RawMessage
+	should.Nil(Unmarshal([]byte(`[1,2,3]`), &data))
+	should.Equal(`[1,2,3]`, string(data))
+	str, err := MarshalToString(data)
+	should.Nil(err)
+	should.Equal(`[1,2,3]`, str)
+}
+
+func Test_json_RawMessage_in_struct(t *testing.T) {
+	type TestObject struct {
+		Field1 string
+		Field2 json.RawMessage
+	}
+	should := require.New(t)
+	var data TestObject
+	should.Nil(Unmarshal([]byte(`{"field1": "hello", "field2": [1,2,3]}`), &data))
+	should.Equal(` [1,2,3]`, string(data.Field2))
+	should.Equal(`hello`, data.Field1)
+}