MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / TestParseTree

Function TestParseTree

pkg/sql/parser/parse_test.go:2310–2340  ·  view source on GitHub ↗

TestParseTree checks that the implicit grouping done by the grammar is properly reflected in the parse tree.

(t *testing.T)

Source from the content-addressed store, hash-verified

2308// TestParseTree checks that the implicit grouping done by the grammar
2309// is properly reflected in the parse tree.
2310func 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

Callers

nothing calls this directly

Calls 3

ParseFunction · 0.92
StringWithFlagsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…