github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/datetime/millisecond_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 TestDateMillisecond(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 129 millisecond", 37 Expected: values.NewInt(129), 38 Args: []core.Value{ 39 values.NewDateTime(time.Date(2018, 11, 4, 17, 3, 12, 129410001, time.Local)), 40 }, 41 }, 42 &testCase{ 43 Name: "When 0 milliseconds [0]", 44 Expected: values.NewInt(0), 45 Args: []core.Value{mustDefaultLayoutDt("1629-02-28T15:59:59Z")}, 46 }, 47 // any nanosec < 1000000 equal to 0 milliseconds 48 &testCase{ 49 Name: "When 0 milliseconds [1]", 50 Expected: values.NewInt(0), 51 Args: []core.Value{ 52 values.NewDateTime(time.Date(0, 0, 0, 0, 0, 0, 999999, time.Local)), 53 }, 54 }, 55 } 56 57 for _, tc := range tcs { 58 tc.Do(t, datetime.DateMillisecond) 59 } 60 }