MCPcopy
hub / github.com/mitchellh/mapstructure / TestBasicTypes

Function TestBasicTypes

mapstructure_test.go:226–318  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

224}
225
226func TestBasicTypes(t *testing.T) {
227 t.Parallel()
228
229 input := map[string]interface{}{
230 "vstring": "foo",
231 "vint": 42,
232 "vint8": 42,
233 "vint16": 42,
234 "vint32": 42,
235 "vint64": 42,
236 "Vuint": 42,
237 "vbool": true,
238 "Vfloat": 42.42,
239 "vsilent": true,
240 "vdata": 42,
241 "vjsonInt": json.Number("1234"),
242 "vjsonUint": json.Number("1234"),
243 "vjsonUint64": json.Number("9223372036854775809"), // 2^63 + 1
244 "vjsonFloat": json.Number("1234.5"),
245 "vjsonNumber": json.Number("1234.5"),
246 }
247
248 var result Basic
249 err := Decode(input, &result)
250 if err != nil {
251 t.Errorf("got an err: %s", err.Error())
252 t.FailNow()
253 }
254
255 if result.Vstring != "foo" {
256 t.Errorf("vstring value should be 'foo': %#v", result.Vstring)
257 }
258
259 if result.Vint != 42 {
260 t.Errorf("vint value should be 42: %#v", result.Vint)
261 }
262 if result.Vint8 != 42 {
263 t.Errorf("vint8 value should be 42: %#v", result.Vint)
264 }
265 if result.Vint16 != 42 {
266 t.Errorf("vint16 value should be 42: %#v", result.Vint)
267 }
268 if result.Vint32 != 42 {
269 t.Errorf("vint32 value should be 42: %#v", result.Vint)
270 }
271 if result.Vint64 != 42 {
272 t.Errorf("vint64 value should be 42: %#v", result.Vint)
273 }
274
275 if result.Vuint != 42 {
276 t.Errorf("vuint value should be 42: %#v", result.Vuint)
277 }
278
279 if result.Vbool != true {
280 t.Errorf("vbool value should be true: %#v", result.Vbool)
281 }
282
283 if result.Vfloat != 42.42 {

Callers

nothing calls this directly

Calls 2

DecodeFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…