github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/parsers/sqlparse_test.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package parsers 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect" 22 "github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect/mysql" 23 "github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect/postgresql" 24 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 25 ) 26 27 var ( 28 debugSQL = struct { 29 input string 30 output string 31 }{ 32 input: "use db1", 33 } 34 ) 35 36 func TestMysql(t *testing.T) { 37 ctx := context.TODO() 38 if debugSQL.output == "" { 39 debugSQL.output = debugSQL.input 40 } 41 ast, err := mysql.ParseOne(ctx, debugSQL.input) 42 if err != nil { 43 t.Errorf("Parse(%q) err: %v", debugSQL.input, err) 44 return 45 } 46 out := tree.String(ast, dialect.MYSQL) 47 if debugSQL.output != out { 48 t.Errorf("Parsing failed. \nExpected/Got:\n%s\n%s", debugSQL.output, out) 49 } 50 } 51 52 func TestPostgresql(t *testing.T) { 53 ctx := context.TODO() 54 if debugSQL.output == "" { 55 debugSQL.output = debugSQL.input 56 } 57 ast, err := postgresql.ParseOne(ctx, debugSQL.input) 58 if err != nil { 59 t.Errorf("Parse(%q) err: %v", debugSQL.input, err) 60 return 61 } 62 out := tree.String(ast, dialect.POSTGRESQL) 63 if debugSQL.output != out { 64 t.Errorf("Parsing failed. \nExpected/Got:\n%s\n%s", debugSQL.output, out) 65 } 66 }