-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathzh_test.go
36 lines (31 loc) · 959 Bytes
/
zh_test.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
package zh_test
import (
"github.com/olebedev/when"
"github.com/stretchr/testify/require"
"testing"
"time"
)
var now = time.Date(2022, time.March, 14, 0, 0, 0, 0, time.UTC)
type Fixture struct {
Text string
Index int
Phrase string
Diff time.Duration
}
func ApplyFixtures(t *testing.T, name string, w *when.Parser, fixt []Fixture) {
for i, f := range fixt {
res, err := w.Parse(f.Text, now)
require.Nil(t, err, "[%s] err #%d", name, i)
require.NotNil(t, res, "[%s] res #%d", name, i)
require.Equal(t, f.Index, res.Index, "[%s] index #%d", name, i)
require.Equal(t, f.Phrase, res.Text, "[%s] text #%d", name, i)
require.Equal(t, f.Diff, res.Time.Sub(now), "[%s] diff #%d", name, i)
}
}
func ApplyFixturesNil(t *testing.T, name string, w *when.Parser, fixt []Fixture) {
for i, f := range fixt {
res, err := w.Parse(f.Text, now)
require.Nil(t, err, "[%s] err #%d", name, i)
require.Nil(t, res, "[%s] res #%d", name, i)
}
}