forked from MontFerret/ferret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
65 lines (53 loc) · 1.25 KB
/
helpers_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
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
package datetime_test
import (
"context"
"testing"
"time"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
. "github.com/smartystreets/goconvey/convey"
)
type testCase struct {
Name string
Expected core.Value
TimeArg time.Time
Args []core.Value
ShouldErr bool
}
func (tc *testCase) Do(t *testing.T, fn core.Function) {
Convey(tc.Name, t, func() {
expected := tc.Expected
actual, err := fn(context.Background(), tc.Args...)
if tc.ShouldErr {
So(err, ShouldBeError)
expected = values.None
} else {
So(err, ShouldBeNil)
}
So(actual.Compare(expected), ShouldEqual, 0)
})
}
func mustDefaultLayoutDt(timeString string) values.DateTime {
dt, err := defaultLayoutDt(timeString)
if err != nil {
panic(err)
}
return dt
}
func mustLayoutDt(layout, value string) values.DateTime {
dt, err := layoutDt(layout, value)
if err != nil {
panic(err)
}
return dt
}
func defaultLayoutDt(timeString string) (values.DateTime, error) {
return layoutDt(values.DefaultTimeLayout, timeString)
}
func layoutDt(layout, value string) (values.DateTime, error) {
t, err := time.Parse(layout, value)
if err != nil {
return values.DateTime{}, err
}
return values.NewDateTime(t), nil
}