()
| 2672 | } |
| 2673 | |
| 2674 | func ExampleErrorAssertionFunc() { |
| 2675 | t := &testing.T{} // provided by test |
| 2676 | |
| 2677 | dumbParseNum := func(input string, v interface{}) error { |
| 2678 | return json.Unmarshal([]byte(input), v) |
| 2679 | } |
| 2680 | |
| 2681 | tests := []struct { |
| 2682 | name string |
| 2683 | arg string |
| 2684 | assertion ErrorAssertionFunc |
| 2685 | }{ |
| 2686 | {"1.2 is number", "1.2", NoError}, |
| 2687 | {"1.2.3 not number", "1.2.3", Error}, |
| 2688 | {"true is not number", "true", Error}, |
| 2689 | {"3 is number", "3", NoError}, |
| 2690 | } |
| 2691 | |
| 2692 | for _, tt := range tests { |
| 2693 | t.Run(tt.name, func(t *testing.T) { |
| 2694 | var x float64 |
| 2695 | tt.assertion(t, dumbParseNum(tt.arg, &x)) |
| 2696 | }) |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | func TestErrorAssertionFunc(t *testing.T) { |
| 2701 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…