(t *testing.T)
| 147 | } |
| 148 | |
| 149 | func TestArray_Decode(t *testing.T) { |
| 150 | t.Run("target is empty interface", func(t *testing.T) { |
| 151 | reporter := newMockReporter(t) |
| 152 | |
| 153 | testValue := []interface{}{"Foo", 123.0} |
| 154 | arr := NewArray(reporter, testValue) |
| 155 | |
| 156 | var target interface{} |
| 157 | arr.Decode(&target) |
| 158 | |
| 159 | arr.chain.assert(t, success) |
| 160 | assert.Equal(t, testValue, target) |
| 161 | }) |
| 162 | |
| 163 | t.Run("target is slice of empty interfaces", func(t *testing.T) { |
| 164 | reporter := newMockReporter(t) |
| 165 | |
| 166 | testValue := []interface{}{"Foo", 123.0} |
| 167 | arr := NewArray(reporter, testValue) |
| 168 | |
| 169 | var target []interface{} |
| 170 | arr.Decode(&target) |
| 171 | |
| 172 | arr.chain.assert(t, success) |
| 173 | assert.Equal(t, testValue, target) |
| 174 | }) |
| 175 | |
| 176 | t.Run("target is slice of structs", func(t *testing.T) { |
| 177 | reporter := newMockReporter(t) |
| 178 | |
| 179 | type S struct { |
| 180 | Foo int `json:"foo"` |
| 181 | } |
| 182 | |
| 183 | actualStruct := []S{{123}, {456}} |
| 184 | testValue := []interface{}{ |
| 185 | map[string]interface{}{ |
| 186 | "foo": 123, |
| 187 | }, |
| 188 | map[string]interface{}{ |
| 189 | "foo": 456, |
| 190 | }, |
| 191 | } |
| 192 | arr := NewArray(reporter, testValue) |
| 193 | |
| 194 | var target []S |
| 195 | arr.Decode(&target) |
| 196 | |
| 197 | arr.chain.assert(t, success) |
| 198 | assert.Equal(t, actualStruct, target) |
| 199 | }) |
| 200 | |
| 201 | t.Run("target is unmarshable", func(t *testing.T) { |
| 202 | reporter := newMockReporter(t) |
| 203 | |
| 204 | testValue := []interface{}{"Foo", 123.0} |
| 205 | arr := NewArray(reporter, testValue) |
| 206 |
nothing calls this directly
no test coverage detected
searching dependent graphs…