-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TRIM functionality #88
Changes from 17 commits
4bd122a
48cbcd9
6cb20b2
fda66f5
b94ec63
a4179df
644203f
69455f4
d52884a
a0d613c
226ad22
1a32e7f
d79b448
5356407
0e88197
e6b3583
803198c
7b19c4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2643,8 +2643,8 @@ func TestKeywords(t *testing.T) { | |
input: "select /* share and mode as cols */ share, mode from t where share = 'foo'", | ||
output: "select /* share and mode as cols */ `share`, `mode` from t where `share` = 'foo'", | ||
}, { | ||
input: "select /* unused keywords as cols */ write, virtual from t where trailing = 'foo'", | ||
output: "select /* unused keywords as cols */ `write`, `virtual` from t where `trailing` = 'foo'", | ||
input: "select /* unused keywords as cols */ write, virtual from t where varcharacter = 'foo'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened to this test case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment still applies, you changed this test case and should put it back |
||
output: "select /* unused keywords as cols */ `write`, `virtual` from t where `varcharacter` = 'foo'", | ||
}, { | ||
input: "insert into x (status) values (42)", | ||
output: "insert into x(`status`) values (42)", | ||
|
@@ -3489,6 +3489,44 @@ func TestLoadData(t *testing.T) { | |
} | ||
} | ||
|
||
func TestTrim(t *testing.T) { | ||
testCases := []parseTest{ | ||
{ | ||
input: `SELECT TRIM("foo")`, | ||
output: `select trim('foo', ' ', b) from dual`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So generally speaking, the Format function should produce output which is itself parseable, and this won't Unless you have a good reason not to do it this way instead, you should change the Format function to return something similar to the input |
||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM("bar" FROM "foo")`, | ||
output: `select trim('foo', 'bar', b) from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(LEADING "bar" FROM "foo")`, | ||
output: `select trim('foo', 'bar', l) from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(TRAILING "bar" FROM "foo")`, | ||
output: `select trim('foo', 'bar', r) from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(BOTH "bar" FROM "foo")`, | ||
output: `select trim('foo', 'bar', b) from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
{ | ||
input: `SELECT TRIM(TRIM("foobar"))`, | ||
output: `select trim(trim('foobar', ' ', b), ' ', b) from dual`, | ||
serializeSelectExprs: true, | ||
}, | ||
} | ||
for _, tcase := range testCases { | ||
runParseTestCase(t, tcase) | ||
} | ||
} | ||
|
||
func TestCreateTableLike(t *testing.T) { | ||
normal := "create table a like b" | ||
testCases := []struct { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare some exported constants for this value