Skip to content

Commit bbec715

Browse files
committed
Merge master with corrected parser tests
2 parents 718c774 + 04766ad commit bbec715

7 files changed

Lines changed: 774 additions & 708 deletions

File tree

‎dependency/sqltypes/value_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ func TestEncode(t *testing.T) {
380380
outASCII: "'Zm9v'",
381381
}, {
382382
in: TestValue(VarChar, "\x00''\b\n\r\t\x1A\\"),
383-
outSQL: `\x00''\b\n\r\t\x1A\\`,
384-
outASCII: "'ACciCAoNCRpc'",
383+
outSQL: `'\0''''\b\n\r\t\Z\'`,
384+
outASCII: "'ACcnCAoNCRpc'",
385385
}}
386386
for _, tcase := range testcases {
387387
buf := &bytes.Buffer{}

‎encodable_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestEncodable(t *testing.T) {
3535
sqltypes.NewInt64(2),
3636
sqltypes.NewVarBinary("bar(`b`)"),
3737
}},
38-
out: "(1, 'foo(\\'a\\')'), (2, 'bar(`b`)')",
38+
out: "(1, 'foo(''a'')'), (2, 'bar(`b`)')",
3939
}, {
4040
// Single column.
4141
in: &TupleEqualityList{

‎parse_test.go‎

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,12 @@ var (
393393
input: "select /* quote in double quoted string */ \"a'a\" from t",
394394
output: "select /* quote in double quoted string */ 'a''a' from t",
395395
}, {
396-
input: "select /* backslash quote in string */ 'a''a' from t",
396+
input: "select /* backslash quote in string */ 'a''a' from t",
397397
output: "select /* backslash quote in string */ 'a''a' from t",
398398
}, {
399399
input: "select /* literal backslash in string */ 'a\\\\na' from t",
400400
}, {
401-
input: "select /* non-escape */ '\\x' from t",
401+
input: "select /* non-escape */ '\\x' from t",
402402
}, {
403403
input: "select /* unescaped backslash */ '\\n' from t",
404404
}, {
@@ -505,17 +505,10 @@ var (
505505
}, {
506506
input: "insert /* set */ into a set a = 1, b = 2",
507507
output: "insert /* set */ into a(a, b) values (1, 2)",
508-
}, {
509-
input: "insert /* set default */ into a set a = default, b = 2",
510-
output: "insert /* set default */ into a(a, b) values (default, 2)",
511508
}, {
512509
input: "insert /* value expression list */ into a values (a + 1, 2 * 3)",
513-
}, {
514-
input: "insert /* default */ into a values (default, 2 * 3)",
515510
}, {
516511
input: "insert /* column list */ into a(a, b) values (1, 2)",
517-
}, {
518-
input: "insert into a(a, b) values (1, ifnull(null, default(b)))",
519512
}, {
520513
input: "insert /* qualified column list */ into a(a, b) values (1, 2)",
521514
}, {
@@ -688,6 +681,51 @@ func TestValid(t *testing.T) {
688681
}
689682
}
690683

684+
func TestInsertComments(t *testing.T) {
685+
cases := []struct {
686+
input, output string
687+
}{
688+
{"insert /* first */ /* second */ into t values (1)", "insert /* first */ /* second */ into t values (1)"},
689+
{"replace /* first */ into t values (1)", "replace /* first */ into t values (1)"},
690+
{"insert or replace /* first */ into t values (1)", "replace /* first */ into t values (1)"},
691+
{"insert /* first */ or replace /* second */ into t values (1)", "replace /* first */ /* second */ into t values (1)"},
692+
{"insert /* first */ into t set a = 1", "insert /* first */ into t(a) values (1)"},
693+
{"insert or replace /* first */ into t set a = 1", "replace /* first */ into t(a) values (1)"},
694+
}
695+
parsers := []struct {
696+
name string
697+
parse func(string) (Statement, error)
698+
}{
699+
{"Parse", Parse},
700+
{"ParseStrictDDL", ParseStrictDDL},
701+
{"ParseNext", func(sql string) (Statement, error) {
702+
return ParseNext(NewTokenizer(strings.NewReader(sql)))
703+
}},
704+
{"ParseMultiple", func(sql string) (Statement, error) {
705+
queries, statements, err := ParseMultiple(NewStringTokenizer(sql))
706+
if err != nil {
707+
return nil, err
708+
}
709+
if len(queries) != 1 || queries[0] != sql || len(statements) != 1 {
710+
return nil, fmt.Errorf("unexpected statements: %v, %v", queries, statements)
711+
}
712+
return statements[0], nil
713+
}},
714+
}
715+
for _, parser := range parsers {
716+
for _, tc := range cases {
717+
stmt, err := parser.parse(tc.input)
718+
if err != nil {
719+
t.Errorf("%s(%q): %v", parser.name, tc.input, err)
720+
continue
721+
}
722+
if got := String(stmt); got != tc.output {
723+
t.Errorf("%s(%q) = %q, want %q", parser.name, tc.input, got, tc.output)
724+
}
725+
}
726+
}
727+
}
728+
691729
func TestCaseSensitivity(t *testing.T) {
692730
validSQL := []struct {
693731
input string
@@ -1117,6 +1155,15 @@ var (
11171155
output string
11181156
excludeMulti bool // Don't use in the ParseNext multi-statement parsing tests.
11191157
}{{
1158+
input: "insert /* set default */ into a set a = default, b = 2",
1159+
output: "syntax error at position 48 near 'default'",
1160+
}, {
1161+
input: "insert /* default */ into a values (default, 2 * 3)",
1162+
output: "syntax error at position 44 near 'default'",
1163+
}, {
1164+
input: "insert into a(a, b) values (1, ifnull(null, default(b)))",
1165+
output: "syntax error at position 52 near 'default'",
1166+
}, {
11201167
input: "select $ from t",
11211168
output: "syntax error at position 9 near '$'",
11221169
}, {

0 commit comments

Comments
 (0)