TestParseTree checks that the implicit grouping done by the grammar is properly reflected in the parse tree.
(t *testing.T)
| 2308 | // TestParseTree checks that the implicit grouping done by the grammar |
| 2309 | // is properly reflected in the parse tree. |
| 2310 | func TestParseTree(t *testing.T) { |
| 2311 | testData := []struct { |
| 2312 | sql string |
| 2313 | expected string |
| 2314 | }{ |
| 2315 | {`SELECT 1`, `SELECT (1)`}, |
| 2316 | {`SELECT -1+2`, `SELECT ((-1) + (2))`}, |
| 2317 | {`SELECT -1:::INT8`, `SELECT (-((1):::INT8))`}, |
| 2318 | {`SELECT 1 = 2::INT8`, `SELECT ((1) = ((2)::INT8))`}, |
| 2319 | {`SELECT 1 = ANY 2::INT8`, `SELECT ((1) = ANY ((2)::INT8))`}, |
| 2320 | {`SELECT 1 = ANY ARRAY[1]:::INT8`, `SELECT ((1) = ANY ((ARRAY[(1)]):::INT8))`}, |
| 2321 | } |
| 2322 | |
| 2323 | for _, d := range testData { |
| 2324 | t.Run(d.sql, func(t *testing.T) { |
| 2325 | stmts, err := parser.Parse(d.sql) |
| 2326 | if err != nil { |
| 2327 | t.Errorf("%s: expected success, but found %s", d.sql, err) |
| 2328 | return |
| 2329 | } |
| 2330 | s := stmts.StringWithFlags(tree.FmtAlwaysGroupExprs) |
| 2331 | if d.expected != s { |
| 2332 | t.Errorf("%s: expected %s, but found (%d statements): %s", d.sql, d.expected, len(stmts), s) |
| 2333 | } |
| 2334 | if _, err := parser.Parse(s); err != nil { |
| 2335 | t.Errorf("expected string found, but not parsable: %s:\n%s", err, s) |
| 2336 | } |
| 2337 | sqlutils.VerifyStatementPrettyRoundtrip(t, d.expected) |
| 2338 | }) |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | // TestParseSyntax verifies that parsing succeeds, though the syntax tree |
| 2343 | // likely differs. All of the test cases here should eventually be moved |
nothing calls this directly
no test coverage detected
searching dependent graphs…