(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func TestEncoderObjectMarshalAPI(t *testing.T) { |
| 103 | t.Run("marshal-basic", func(t *testing.T) { |
| 104 | r, err := Marshal(&testObject{ |
| 105 | "漢字", nil, 1, nil, 1, nil, 1, nil, 1, nil, 1, nil, 1, nil, 1, |
| 106 | nil, 1, nil, 1, nil, 1.1, nil, 1.1, nil, true, nil, |
| 107 | &testObject{}, testSliceInts{}, []interface{}{"h", "o", "l", "a"}, |
| 108 | }) |
| 109 | assert.Nil(t, err, "Error should be nil") |
| 110 | assert.Equal( |
| 111 | t, |
| 112 | `{"testStr":"漢字","testInt":1,"testInt64":1,"testInt32":1,"testInt16":1,"testInt8":1,"testUint64":1,"testUint32":1,"testUint16":1,"testUint8":1,"testFloat64":1.1,"testFloat32":1.1,"testBool":true}`, |
| 113 | string(r), |
| 114 | "Result of marshalling is different as the one expected", |
| 115 | ) |
| 116 | }) |
| 117 | |
| 118 | t.Run("marshal-complex", func(t *testing.T) { |
| 119 | v := &TestEncoding{ |
| 120 | test: "hello world", |
| 121 | test2: "foobar", |
| 122 | testInt: 1, |
| 123 | testBool: true, |
| 124 | testF32: 120.53, |
| 125 | testF64: 120.15, |
| 126 | testInterface: true, |
| 127 | testArr: TestEncodingArr{ |
| 128 | &TestEncoding{ |
| 129 | test: "1", |
| 130 | }, |
| 131 | }, |
| 132 | sub: &SubObject{ |
| 133 | test1: 10, |
| 134 | test2: "hello world", |
| 135 | test3: 1.23543, |
| 136 | testBool: true, |
| 137 | sub: &SubObject{ |
| 138 | test1: 10, |
| 139 | testBool: false, |
| 140 | test2: "hello world", |
| 141 | }, |
| 142 | }, |
| 143 | } |
| 144 | r, err := MarshalJSONObject(v) |
| 145 | assert.Nil(t, err, "Error should be nil") |
| 146 | assert.Equal( |
| 147 | t, |
| 148 | `{"test":"hello world","test2":"foobar","testInt":1,"testBool":true,"testArr":[{"test":"1","test2":"","testInt":0,"testBool":false,"testArr":[],"testF64":0,"testF32":0,"sub":{}}],"testF64":120.15,"testF32":120.53,"testInterface":true,"sub":{"test1":10,"test2":"hello world","test3":1.23543,"testBool":true,"sub":{"test1":10,"test2":"hello world","test3":0,"testBool":false,"sub":{}}}}`, |
| 149 | string(r), |
| 150 | "Result of marshalling is different as the one expected", |
| 151 | ) |
| 152 | }) |
| 153 | |
| 154 | t.Run("marshal-interface-string", func(t *testing.T) { |
| 155 | v := testEncodingObjInterfaces{"string"} |
| 156 | r, err := Marshal(&v) |
| 157 | assert.Nil(t, err, "Error should be nil") |
| 158 | assert.Equal( |
| 159 | t, |
nothing calls this directly
no test coverage detected
searching dependent graphs…