github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/datetime/quarter_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 TestDateQuarter(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 } 36 37 for month := time.January; month <= time.December; month++ { 38 tcs = append(tcs, &testCase{ 39 Name: "When " + month.String(), 40 Expected: values.NewInt(((int(month) - 1) / 3) + 1), 41 Args: []core.Value{ 42 values.NewDateTime(time.Date(1999, month, 1, 1, 1, 1, 1, time.Local)), 43 }, 44 }) 45 } 46 47 for _, tc := range tcs { 48 tc.Do(t, datetime.DateQuarter) 49 } 50 }