github.com/dolthub/go-mysql-server@v0.18.0/sql/planbuilder/dateparse/parsers_test.go (about) 1 package dateparse 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestParsers(t *testing.T) { 10 tests := [...]struct { 11 name string 12 chars string 13 parser parser 14 expectedRest string 15 expectedDatetime datetime 16 }{ 17 {"24_timestamp", "13:12:15", parse24HourTimestamp, "", 18 datetime{hours: uintPtr(13), minutes: uintPtr(12), seconds: uintPtr(15)}, 19 }, 20 } 21 for _, tt := range tests { 22 t.Run(tt.name, func(t *testing.T) { 23 var dt datetime 24 rest, err := tt.parser(&dt, tt.chars) 25 require.NoError(t, err) 26 require.Equal(t, tt.expectedRest, rest) 27 require.Equal(t, tt.expectedDatetime, dt) 28 }) 29 } 30 } 31 32 func TestParserErr(t *testing.T) { 33 tests := [...]struct { 34 name string 35 chars string 36 parser parser 37 expectedErr string 38 }{ 39 {"24_timestamp", "13:12", parse24HourTimestamp, `expected literal ":", found empty string`}, 40 } 41 for _, tt := range tests { 42 t.Run(tt.name, func(t *testing.T) { 43 var dt datetime 44 _, err := tt.parser(&dt, tt.chars) 45 require.Error(t, err) 46 require.Equal(t, tt.expectedErr, err.Error()) 47 }) 48 } 49 } 50 51 func uintPtr(u uint) *uint { return &u }