github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/datetime/dayofyear_test.go (about) 1 package datetime_test 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/MontFerret/ferret/pkg/runtime/core" 8 "github.com/MontFerret/ferret/pkg/runtime/values" 9 "github.com/MontFerret/ferret/pkg/stdlib/datetime" 10 ) 11 12 func TestDateDayOfYear(t *testing.T) { 13 tcs := []*testCase{ 14 &testCase{ 15 Name: "When more than 1 arguments", 16 Expected: values.None, 17 Args: []core.Value{ 18 values.NewString("string"), 19 values.NewInt(0), 20 }, 21 ShouldErr: true, 22 }, 23 &testCase{ 24 Name: "When 0 arguments", 25 Expected: values.None, 26 Args: []core.Value{}, 27 ShouldErr: true, 28 }, 29 &testCase{ 30 Name: "When argument isn't DateTime", 31 Expected: values.None, 32 Args: []core.Value{values.NewInt(0)}, 33 ShouldErr: true, 34 }, 35 &testCase{ 36 Name: "When 38th day of the year", 37 Expected: values.NewInt(38), 38 Args: []core.Value{mustDefaultLayoutDt("1999-02-07T15:04:05Z")}, 39 }, 40 &testCase{ 41 Name: "When 59th day of the year", 42 Expected: values.NewInt(59), 43 Args: []core.Value{mustDefaultLayoutDt("1629-02-28T15:59:05Z")}, 44 }, 45 &testCase{ 46 Name: "When 366th day of the year", 47 Expected: values.NewInt(366), 48 Args: []core.Value{ 49 values.NewDateTime(time.Date(1972, time.December, 31, 0, 0, 0, 0, time.Local)), 50 }, 51 }, 52 } 53 54 for _, tc := range tcs { 55 tc.Do(t, datetime.DateDayOfYear) 56 } 57 }