MCPcopy Create free account
hub / github.com/stretchr/testify / ExampleErrorAssertionFunc

Function ExampleErrorAssertionFunc

assert/assertions_test.go:2878–2902  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2876}
2877
2878func ExampleErrorAssertionFunc() {
2879 t := &testing.T{} // provided by test
2880
2881 dumbParseNum := func(input string, v interface{}) error {
2882 return json.Unmarshal([]byte(input), v)
2883 }
2884
2885 tests := []struct {
2886 name string
2887 arg string
2888 assertion ErrorAssertionFunc
2889 }{
2890 {"1.2 is number", "1.2", NoError},
2891 {"1.2.3 not number", "1.2.3", Error},
2892 {"true is not number", "true", Error},
2893 {"3 is number", "3", NoError},
2894 }
2895
2896 for _, tt := range tests {
2897 t.Run(tt.name, func(t *testing.T) {
2898 var x float64
2899 tt.assertion(t, dumbParseNum(tt.arg, &x))
2900 })
2901 }
2902}
2903
2904func TestErrorAssertionFunc(t *testing.T) {
2905 tests := []struct {

Callers

nothing calls this directly

Calls 1

RunMethod · 0.65

Tested by

no test coverage detected