(t *testing.T)
| 533 | } |
| 534 | |
| 535 | func TestDecoder(t *testing.T) { |
| 536 | type Struct struct { |
| 537 | FieldA string |
| 538 | FieldB map[string]any |
| 539 | } |
| 540 | |
| 541 | num := 4321 |
| 542 | numptr := &num |
| 543 | str := "boring string" |
| 544 | strptr := &str |
| 545 | |
| 546 | inputs := []any{ |
| 547 | str, |
| 548 | strptr, |
| 549 | num, |
| 550 | numptr, |
| 551 | 100.1, |
| 552 | Struct{ |
| 553 | FieldA: "hello", |
| 554 | FieldB: map[string]any{ |
| 555 | "hello": "world", |
| 556 | }, |
| 557 | }, |
| 558 | &Struct{ |
| 559 | FieldA: "world", |
| 560 | }, |
| 561 | map[string]string{ |
| 562 | "slice": "pizza", |
| 563 | }, |
| 564 | &map[string]any{}, |
| 565 | []string{"hello", "world"}, |
| 566 | &[]int{1, 0, 1}, |
| 567 | [...]float64{3.1415}, |
| 568 | &[...]int64{4, 5, 6}, |
| 569 | } |
| 570 | |
| 571 | for _, tc := range []struct { |
| 572 | desc string |
| 573 | encodeFn func(any) ([]byte, error) |
| 574 | decodeFn Decode |
| 575 | }{ |
| 576 | { |
| 577 | desc: "JSON", |
| 578 | encodeFn: json.Marshal, |
| 579 | decodeFn: JSONDecode, |
| 580 | }, |
| 581 | { |
| 582 | desc: "Gob", |
| 583 | encodeFn: gobMarshal, |
| 584 | decodeFn: GobDecode, |
| 585 | }, |
| 586 | } { |
| 587 | for i, input := range inputs { |
| 588 | t.Run(fmt.Sprintf("%s_%d", tc.desc, i), func(t *testing.T) { |
| 589 | decoder := NewDecoder(input, tc.decodeFn) |
| 590 | b, err := tc.encodeFn(input) |
| 591 | if err != nil { |
| 592 | t.Fatalf("marshal error %v", err) |
nothing calls this directly
no test coverage detected