github.com/kumasuke120/mockuma@v1.1.9/internal/myjson/unmarshal_test.go (about) 1 package myjson 2 3 import ( 4 "io/ioutil" 5 "path/filepath" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 //noinspection GoImportUsedAsName 13 func TestUnmarshal(t *testing.T) { 14 assert := assert.New(t) 15 require := require.New(t) 16 17 fb1, e1 := ioutil.ReadFile(filepath.Join("testdata", "json1.json")) 18 require.Nil(e1) 19 u1, e1 := Unmarshal(fb1) 20 assert.Nil(e1) 21 expected1 := Object(map[string]interface{}{ 22 "str": String("hello"), 23 "num": Number(1.23), 24 "bool": Boolean(false), 25 "arr": Array([]interface{}{Number(1), String("a"), nil}), 26 "null": nil, 27 }) 28 assert.Equal(expected1, u1) 29 } 30 31 func TestToMyJSON(t *testing.T) { 32 //noinspection GoImportUsedAsName 33 assert := assert.New(t) 34 35 expected1 := Object(map[string]interface{}{ 36 "str": String("hello"), 37 "num": Number(1.23), 38 "bool": Boolean(false), 39 "arr": Array([]interface{}{Number(1), String("a"), nil}), 40 "null": nil, 41 }) 42 from1 := Object(map[string]interface{}{ 43 "str": "hello", 44 "num": 1.23, 45 "bool": false, 46 "arr": []interface{}{Number(1), String("a"), nil}, 47 "null": nil, 48 }) 49 assert.Equal(expected1, toMyJSON(from1)) 50 51 expected2 := Object(map[string]interface{}{ 52 "str": String("hello"), 53 "num": Number(1.23), 54 "bool": Boolean(false), 55 "arr": Array([]interface{}{Number(1), String("a"), nil}), 56 }) 57 from2 := map[string]interface{}{ 58 "str": String("hello"), 59 "num": Number(1.23), 60 "bool": Boolean(false), 61 "arr": Array([]interface{}{Number(1), String("a"), nil}), 62 } 63 assert.Equal(expected2, toMyJSON(from2)) 64 }