From 864305d52152d153e5c817a745d43b093b93247b Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Thu, 27 Dec 2018 14:32:19 +0800 Subject: [PATCH] for test case --- ast/pretty_test.go | 4 +++ ast/testdata/TestPretty.golden | 40 ++++++++++----------- ast/testdata/TestStmtNode2JSON.golden | 1 + ast/testdata/TestVitessStmtNode2JSON.golden | 1 + ast/tidb_test.go | 2 ++ ast/vitess_test.go | 2 ++ 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/ast/pretty_test.go b/ast/pretty_test.go index 15a4ef5..9c0a002 100644 --- a/ast/pretty_test.go +++ b/ast/pretty_test.go @@ -131,6 +131,10 @@ func TestPretty(t *testing.T) { fmt.Println(sql) fmt.Println(Pretty(sql, "builtin")) } + orgMaxPrettySQLLength := common.Config.MaxPrettySQLLength + common.Config.MaxPrettySQLLength = 1 + fmt.Println(Pretty("select 1", "builtin")) + common.Config.MaxPrettySQLLength = orgMaxPrettySQLLength }, t.Name(), update) if nil != err { t.Fatal(err) diff --git a/ast/testdata/TestPretty.golden b/ast/testdata/TestPretty.golden index 95f5529..6aa57d4 100644 --- a/ast/testdata/TestPretty.golden +++ b/ast/testdata/TestPretty.golden @@ -1100,26 +1100,25 @@ SELECT c. city_id FROM sakila. city c); -SELECT visitor_id, url FROM (SELECT id FROM log WHERE ip="123.45.67.89" order by ts desc limit 50, 10) I JOIN log ON (I.id=log.id) JOIN url ON (url.id=log.url_id) order by TS desc; +SELECT city FROM( SELECT city_id FROM city WHERE city = "A Corua (La Corua)" ORDER BY last_update DESC LIMIT 50, 10) I JOIN city ON (I.city_id = city.city_id) JOIN country ON (country.country_id = city.country_id) ORDER BY city DESC; SELECT - visitor_id, url -FROM - ( + city +FROM( SELECT - id + city_id FROM - LOG + city WHERE - ip= "123.45.67.89" + city = "A Corua (La Corua)" ORDER BY - ts desc + last_update DESC LIMIT 50, 10) I - JOIN LOG ON (I. id= LOG. id) - JOIN url ON (url. id= LOG. url_id) + JOIN city ON (I. city_id = city. city_id) + JOIN country ON (country. country_id = city. country_id) ORDER BY - TS desc; + city DESC; DELETE city, country FROM city INNER JOIN country using (country_id) WHERE city.city_id = 1; DELETE city, country FROM @@ -1490,24 +1489,24 @@ ADD ADD index `idx_store_film` ( `store_id`, `film_id`); -SELECT DATE_FORMAT(t.atm, '%Y-%m-%d'), COUNT(DISTINCT (t.usr)) FROM usr_terminal t WHERE t.atm > '2018-10-22 00:00:00' AND t.agent LIKE '%Chrome%' AND t.system = 'eip' GROUP BY DATE_FORMAT(t.atm, '%Y-%m-%d') ORDER BY DATE_FORMAT(t.atm, '%Y-%m-%d'); +SELECT DATE_FORMAT(t.last_update, '%Y-%m-%d'), COUNT(DISTINCT (t.city)) FROM city t WHERE t.last_update > '2018-10-22 00:00:00' AND t.city LIKE '%Chrome%' AND t.city = 'eip' GROUP BY DATE_FORMAT(t.last_update, '%Y-%m-%d') ORDER BY DATE_FORMAT(t.last_update, '%Y-%m-%d'); SELECT - DATE_FORMAT( t. atm, '%Y-%m-%d' + DATE_FORMAT( t. last_update, '%Y-%m-%d' ), COUNT( DISTINCT ( - t. usr)) + t. city)) FROM - usr_terminal t + city t WHERE - t. atm > '2018-10-22 00:00:00' - AND t. agent LIKE '%Chrome%' - AND t. system = 'eip' + t. last_update > '2018-10-22 00:00:00' + AND t. city LIKE '%Chrome%' + AND t. city = 'eip' GROUP BY - DATE_FORMAT( t. atm, '%Y-%m-%d' + DATE_FORMAT( t. last_update, '%Y-%m-%d' ) ORDER BY - DATE_FORMAT( t. atm, '%Y-%m-%d' + DATE_FORMAT( t. last_update, '%Y-%m-%d' ); create table hello.t (id int unsigned); create table hello. t (id int unsigned); @@ -1525,3 +1524,4 @@ ALTER TABLE tb alter column id DROP DEFAULT; +select 1 diff --git a/ast/testdata/TestStmtNode2JSON.golden b/ast/testdata/TestStmtNode2JSON.golden index 2ac5314..407d399 100644 --- a/ast/testdata/TestStmtNode2JSON.golden +++ b/ast/testdata/TestStmtNode2JSON.golden @@ -42,3 +42,4 @@ "IsInBraces": false } ] + diff --git a/ast/testdata/TestVitessStmtNode2JSON.golden b/ast/testdata/TestVitessStmtNode2JSON.golden index 2f44098..155fd39 100644 --- a/ast/testdata/TestVitessStmtNode2JSON.golden +++ b/ast/testdata/TestVitessStmtNode2JSON.golden @@ -30,3 +30,4 @@ "Limit": null, "Lock": "" } + diff --git a/ast/tidb_test.go b/ast/tidb_test.go index 72d210d..641ff0c 100644 --- a/ast/tidb_test.go +++ b/ast/tidb_test.go @@ -27,6 +27,7 @@ func TestPrintPrettyStmtNode(t *testing.T) { common.Log.Debug("Entering function: %s", common.GetFunctionName()) sqls := []string{ `select 1`, + `select * f`, // syntax error case } err := common.GoldenDiff(func() { for _, sql := range sqls { @@ -43,6 +44,7 @@ func TestStmtNode2JSON(t *testing.T) { common.Log.Debug("Entering function: %s", common.GetFunctionName()) sqls := []string{ `select 1`, + `select * f`, // syntax error case } err := common.GoldenDiff(func() { for _, sql := range sqls { diff --git a/ast/vitess_test.go b/ast/vitess_test.go index 45ce550..c50e929 100644 --- a/ast/vitess_test.go +++ b/ast/vitess_test.go @@ -27,6 +27,7 @@ func TestPrintPrettyVitessStmtNode(t *testing.T) { common.Log.Debug("Entering function: %s", common.GetFunctionName()) sqls := []string{ `select 1`, + `select * f`, // syntax error case } err := common.GoldenDiff(func() { for _, sql := range sqls { @@ -43,6 +44,7 @@ func TestVitessStmtNode2JSON(t *testing.T) { common.Log.Debug("Entering function: %s", common.GetFunctionName()) sqls := []string{ `select 1`, + `select * f`, // syntax error case } err := common.GoldenDiff(func() { for _, sql := range sqls { -- GitLab