Add test for #2331

This commit is contained in:
Lunny Xiao 2023-10-19 16:29:40 +08:00
parent dbe499091a
commit f556e8a899
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 9 additions and 3 deletions

View File

@ -131,6 +131,8 @@ func TestJoin(t *testing.T) {
assert.EqualValues(t, "[a].*,[b].[c]", quoter.Join([]string{"a.*", " b.c"}, ",")) assert.EqualValues(t, "[a].*,[b].[c]", quoter.Join([]string{"a.*", " b.c"}, ","))
assert.EqualValues(t, "[a] [c]", quoter.Join([]string{"a c"}, ","))
assert.EqualValues(t, "[f1], [f2], [f3]", quoter.Join(cols, ", ")) assert.EqualValues(t, "[f1], [f2], [f3]", quoter.Join(cols, ", "))
quoter.IsReserved = AlwaysNoReserve quoter.IsReserved = AlwaysNoReserve
@ -146,7 +148,7 @@ func TestStrings(t *testing.T) {
} }
func TestTrim(t *testing.T) { func TestTrim(t *testing.T) {
var kases = map[string]string{ kases := map[string]string{
"[table_name]": "table_name", "[table_name]": "table_name",
"[schema].[table_name]": "schema.table_name", "[schema].[table_name]": "schema.table_name",
} }
@ -159,7 +161,7 @@ func TestTrim(t *testing.T) {
func TestReplace(t *testing.T) { func TestReplace(t *testing.T) {
q := Quoter{'[', ']', AlwaysReserve} q := Quoter{'[', ']', AlwaysReserve}
var kases = []struct { kases := []struct {
source string source string
expected string expected string
}{ }{
@ -171,6 +173,10 @@ func TestReplace(t *testing.T) {
"SELECT 'abc```test```''', `a` FROM b", "SELECT 'abc```test```''', `a` FROM b",
"SELECT 'abc```test```''', [a] FROM b", "SELECT 'abc```test```''', [a] FROM b",
}, },
{
"SELECT * FROM `a` INNER JOIN `b` `c` WHERE `a`.`id` = `c`.`a_id`",
"SELECT * FROM [a] INNER JOIN [b] [c] WHERE [a].[id] = [c].[a_id]",
},
{ {
"UPDATE table SET `a` = ~ `a`, `b`='abc`'", "UPDATE table SET `a` = ~ `a`, `b`='abc`'",
"UPDATE table SET [a] = ~ [a], [b]='abc`'", "UPDATE table SET [a] = ~ [a], [b]='abc`'",