Skip to content

Commit

Permalink
test: 添加语法树单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchuanchuan committed May 4, 2019
1 parent 002072e commit 401e4dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
32 changes: 32 additions & 0 deletions session/session_inception_print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,35 @@ func (s *testSessionPrintSuite) TestInsert(c *C) {
c.Assert(row[4], Equals, "line 1 column 21 near \"\" (total length 21)", Commentf("%v", row))

}

func (s *testSessionPrintSuite) TestUpdate(c *C) {

res := s.makeSQL(`update t1 set c1=1 where a=1;`)
row := res.Rows()[int(s.tk.Se.AffectedRows())-1]
c.Assert(row[2], Equals, "0", Commentf("%v", row))

res = s.makeSQL("update t1 inner join t2 on t1.id=t2.id set c2=1 where t1.c1=1;")
row = res.Rows()[int(s.tk.Se.AffectedRows())-1]
c.Assert(row[2], Equals, "0", Commentf("%v", row))

}

func (s *testSessionPrintSuite) TestDelete(c *C) {

res := s.makeSQL(`delete from t1 where id=1;`)
row := res.Rows()[int(s.tk.Se.AffectedRows())-1]
c.Assert(row[2], Equals, "0", Commentf("%v", row))

// res = s.makeSQL("update t1 inner join t2 on t1.id=t2.id set c2=1 where t1.c1=1;")
// row = res.Rows()[int(s.tk.Se.AffectedRows())-1]
// c.Assert(row[2], Equals, "0", Commentf("%v", row))

}

func (s *testSessionPrintSuite) TestAlterTable(c *C) {

res := s.makeSQL(`alter table t1 add column c1 int;`)
row := res.Rows()[int(s.tk.Se.AffectedRows())-1]
c.Assert(row[2], Equals, "0", Commentf("%v", row))

}
5 changes: 2 additions & 3 deletions session/session_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ func (s *session) printCommand(ctx context.Context, stmtNode ast.StmtNode,
log.Debug("printCommand")

// b, err := json.MarshalIndent(stmtNode, "", " ")
b, err := json.Marshal(stmtNode)
tree, err := json.Marshal(stmtNode)
if err != nil {
log.Error(err)
s.printSets.Append(2, currentSql, "", err.Error())
} else {
str := string(b)
s.printSets.Append(0, currentSql, str, "")
s.printSets.Append(0, currentSql, string(tree), "")
}

return nil, nil
Expand Down

0 comments on commit 401e4dd

Please sign in to comment.