MCPcopy Create free account
hub / github.com/google/go-cloud / TestDecode

Function TestDecode

docstore/driver/codec_test.go:293–457  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

291func (e *mapEncoder) MapKey(k string) { e.m[k] = e.val }
292
293func TestDecode(t *testing.T) {
294 two := 2
295 tru := true
296 fa := false
297 ptru := &tru
298 pfa := &fa
299 tm := time.Now()
300 tmb, err := tm.MarshalBinary()
301 if err != nil {
302 t.Fatal(err)
303 }
304 ts := &tspb.Timestamp{Seconds: 25, Nanos: 300}
305 tsb, err := proto.Marshal(ts)
306 if err != nil {
307 t.Fatal(err)
308 }
309
310 for _, test := range []struct {
311 in any // pointer that will be set
312 val any // value to set it to
313 want any
314 exactMatch bool
315 }{
316 {new(any), nil, nil, true},
317 {new(int), int64(7), int(7), true},
318 {new(uint8), uint64(250), uint8(250), true},
319 {new(bool), true, true, true},
320 {new(string), "x", "x", true},
321 {new(float32), 4.25, float32(4.25), true},
322 {new(*int), int64(2), &two, true},
323 {new(*int), nil, (*int)(nil), true},
324 {new([]byte), []byte("foo"), []byte("foo"), true},
325 {new([]string), []any{"a", "b"}, []string{"a", "b"}, true},
326 {new([]**bool), []any{true, false}, []**bool{&ptru, &pfa}, true},
327 {&[1]int{1}, []any{2}, [1]int{2}, true},
328 {&[2]int{1, 2}, []any{3}, [2]int{3, 0}, true}, // zero extra elements
329 {&[]int{1, 2}, []any{3}, []int{3}, true}, // truncate slice
330 {
331 // extend slice
332 func() *[]int { s := make([]int, 1, 2); return &s }(),
333 []any{5, 6},
334 []int{5, 6},
335 true,
336 },
337 {
338 new(map[string]string),
339 map[string]any{"a": "b"},
340 map[string]string{"a": "b"},
341 true,
342 },
343 {
344 new(map[int]bool),
345 map[string]any{"17": true},
346 map[int]bool{17: true},
347 true,
348 },
349 {
350 new(map[te]bool),

Callers

nothing calls this directly

Calls 4

specialTypeAlias · 0.85
myStringTypeAlias · 0.85
DecodeFunction · 0.70
MarshalBinaryMethod · 0.45

Tested by

no test coverage detected