2018-11-01 22:58:22 +02:00
|
|
|
package datetime_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
"github.com/MontFerret/ferret/pkg/stdlib/datetime"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDateMonth(t *testing.T) {
|
|
|
|
tcs := []*testCase{
|
|
|
|
&testCase{
|
|
|
|
Name: "When more than 1 arguments",
|
|
|
|
Expected: values.None,
|
|
|
|
Args: []core.Value{
|
|
|
|
values.NewString("string"),
|
|
|
|
values.NewInt(0),
|
|
|
|
},
|
|
|
|
ShouldErr: true,
|
|
|
|
},
|
|
|
|
&testCase{
|
|
|
|
Name: "When 0 arguments",
|
|
|
|
Expected: values.None,
|
|
|
|
Args: []core.Value{},
|
|
|
|
ShouldErr: true,
|
|
|
|
},
|
2018-11-05 21:48:00 +02:00
|
|
|
&testCase{
|
|
|
|
Name: "When argument isn't DateTime",
|
|
|
|
Expected: values.None,
|
|
|
|
Args: []core.Value{values.NewInt(0)},
|
|
|
|
ShouldErr: true,
|
|
|
|
},
|
2018-11-01 22:58:22 +02:00
|
|
|
&testCase{
|
|
|
|
Name: "When 2th month",
|
|
|
|
Expected: values.NewInt(2),
|
|
|
|
Args: []core.Value{mustDefaultLayoutDt("1999-02-07T15:04:05Z")},
|
|
|
|
},
|
|
|
|
&testCase{
|
|
|
|
Name: "When 12th month",
|
|
|
|
Expected: values.NewInt(12),
|
|
|
|
Args: []core.Value{mustDefaultLayoutDt("1999-12-07T15:04:05Z")},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tcs {
|
|
|
|
tc.Do(t, datetime.DateMonth)
|
|
|
|
}
|
|
|
|
}
|