github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/datetime/daysinmonth_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 TestDateDateDaysInMonth(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 Feb and a leap year", 37 Expected: values.NewInt(29), 38 Args: []core.Value{ 39 values.NewDateTime(time.Date(1972, time.February, 1, 1, 1, 1, 1, time.Local)), 40 }, 41 }, 42 &testCase{ 43 Name: "When Feb and not a leap year", 44 Expected: values.NewInt(28), 45 Args: []core.Value{ 46 values.NewDateTime(time.Date(1999, time.February, 1, 1, 1, 1, 1, time.Local)), 47 }, 48 }, 49 &testCase{ 50 Name: "When January", 51 Expected: values.NewInt(31), 52 Args: []core.Value{ 53 values.NewDateTime(time.Date(1999, time.January, 1, 1, 1, 1, 1, time.Local)), 54 }, 55 }, 56 &testCase{ 57 Name: "When November", 58 Expected: values.NewInt(30), 59 Args: []core.Value{ 60 values.NewDateTime(time.Date(1999, time.November, 1, 1, 1, 1, 1, time.Local)), 61 }, 62 }, 63 } 64 65 for _, tc := range tcs { 66 tc.Do(t, datetime.DateDaysInMonth) 67 } 68 }