parseWithPositions is a test helper that tokenizes and parses SQL with full position tracking enabled, returning the AST ready for inspection.
(t *testing.T, sql string)
| 31 | // parseWithPositions is a test helper that tokenizes and parses SQL with |
| 32 | // full position tracking enabled, returning the AST ready for inspection. |
| 33 | func parseWithPositions(t *testing.T, sql string) *ast.AST { |
| 34 | t.Helper() |
| 35 | |
| 36 | tkz := tokenizer.GetTokenizer() |
| 37 | defer tokenizer.PutTokenizer(tkz) |
| 38 | |
| 39 | tokens, err := tkz.Tokenize([]byte(sql)) |
| 40 | if err != nil { |
| 41 | t.Fatalf("tokenize failed: %v", err) |
| 42 | } |
| 43 | |
| 44 | p := parser.GetParser() |
| 45 | defer parser.PutParser(p) |
| 46 | |
| 47 | result, err := p.ParseFromModelTokens(tokens) |
| 48 | if err != nil { |
| 49 | t.Fatalf("parse failed: %v", err) |
| 50 | } |
| 51 | return result |
| 52 | } |
| 53 | |
| 54 | // assertPos checks that a Location is non-zero (has been populated). |
| 55 | func assertPos(t *testing.T, label string, loc models.Location) { |
no test coverage detected