Skip to content

Commit

Permalink
*: add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuyesuifeng committed Oct 24, 2015
1 parent 4d777a8 commit 017389e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mysql/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,26 @@ func (s *testTimeSuite) TestDurationClock(c *C) {
c.Assert(d.MicroSecond(), Equals, t.MicroSecond)
}
}

func (s *testTimeSuite) TestParseDateFormat(c *C) {
tbl := []struct {
Input string
Result []string
}{
{"2011-11-11 10:10:10.123456", []string{"2011", "11", "11", "10", "10", "10", "123456"}},
{" 2011-11-11 10:10:10.123456 ", []string{"2011", "11", "11", "10", "10", "10", "123456"}},
{"2011-11-11 10", []string{"2011", "11", "11", "10"}},
{"2011-11-11T10:10:10.123456", []string{"2011", "11", "11", "10", "10", "10", "123456"}},
{"2011:11:11T10:10:10.123456", []string{"2011", "11", "11", "10", "10", "10", "123456"}},
{"xx2011-11-11 10:10:10", nil},
{"T10:10:10", nil},
{"2011-11-11x", nil},
{"2011-11-11 10:10:10", nil},
{"xxx 10:10:10", nil},
}

for _, t := range tbl {
r := parseDateFormat(t.Input)
c.Assert(r, DeepEquals, t.Result)
}
}
8 changes: 8 additions & 0 deletions tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,14 @@ func (s *testSessionSuite) TestResultType(c *C) {
c.Assert(fs[0].Col.FieldType.Tp, Equals, mysql.TypeString)
}

func (s *testSessionSuite) TestBuiltin(c *C) {
store := newStore(c, s.dbName)
se := newSession(c, store, s.dbName)

// Testcase for https://github.com/pingcap/tidb/issues/382
mustExecFailed(c, se, `select cast("xxx 10:10:10" as datetime)`)
}

func newSession(c *C, store kv.Storage, dbName string) Session {
se, err := CreateSession(store)
c.Assert(err, IsNil)
Expand Down

0 comments on commit 017389e

Please sign in to comment.