-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testtableentry.go
85 lines (72 loc) · 1.81 KB
/
testtableentry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package tests
import (
"fmt"
"testing"
)
// func NewEntry[In any, W comparable](name string, fn func(in ...In) W, in []In, want W, wantErr bool) *TestTableEntry[In, W] {
// return &TestTableEntry[In, W]{name, fn, in, want, wantErr}
// }
type (
TestRunner interface {
Run(t *testing.T) error
}
TestDataType[In any, W comparable] struct {
NameFunc string
Fn func(In) W
TestDataDetails[In, W]
}
TestDataDetails[In any, W comparable] struct {
Name string
In In
Want W
WantErr bool
}
)
func (tt *TestDataType[In, W]) Got() W { return tt.Fn(tt.In) }
func (tt *TestDataType[In, W]) Run(t *testing.T) (err error) {
name := fmt.Sprintf("%s(%s): ", tt.NameFunc, tt.Name)
t.Run(name, func(t *testing.T) {
if tt.Got() != tt.Want {
if !tt.WantErr {
err = fmt.Errorf(fmtErrorfWithWantErr, name, tt.Got(), tt.Want, tt.WantErr, err)
}
}
})
return err
}
func (tt *TestDataType[In, W]) Benchmark(b *testing.B) (err error) {
name := fmt.Sprintf("%s(%s): ", tt.NameFunc, tt.Name)
b.Run(name, func(b *testing.B) {
if tt.Got() != tt.Want {
if !tt.WantErr {
err = fmt.Errorf(fmtErrorfWithWantErr, name, tt.Got(), tt.Want, tt.WantErr, err)
}
}
})
return err
}
// TableEntryInfo[In any, W comparable] interface {
// In() []In
// Got() W
// Want() W
// WantErr() bool
// }
// TestTableEntryer[In any, W comparable] interface {
// TestRunner
// TableEntryInfo[In, W]
// }
// TestTableEntry describes a set of tests with
// with the same name and function and set of
// expected input and output values
// TestTableEntry[In any, W comparable] struct {
// FnName string
// Fn func(in ...In) W
// Tests []TestDataType[In, W]
// }
// testTableEntry[In any, W comparable] struct {
// name string
// fn func(in ...In) W
// in []In
// want W
// wantErr bool
// }