----------------------------------------------------------------------------- TestMultipleStatementPositions verifies position accuracy in batches -----------------------------------------------------------------------------
(t *testing.T)
| 336 | // ----------------------------------------------------------------------------- |
| 337 | |
| 338 | func TestMultipleStatementPositions(t *testing.T) { |
| 339 | sql := "SELECT 1;\nINSERT INTO t (x) VALUES (2);\nDELETE FROM t WHERE x = 2" |
| 340 | tree := parseWithPositions(t, sql) |
| 341 | |
| 342 | if len(tree.Statements) != 3 { |
| 343 | t.Fatalf("expected 3 statements, got %d", len(tree.Statements)) |
| 344 | } |
| 345 | |
| 346 | // Statement 1: SELECT on line 1 |
| 347 | sel, ok := tree.Statements[0].(*ast.SelectStatement) |
| 348 | if !ok { |
| 349 | t.Fatalf("expected *ast.SelectStatement, got %T", tree.Statements[0]) |
| 350 | } |
| 351 | assertPosEqual(t, "SELECT.Pos", sel.Pos, 1, 1) |
| 352 | |
| 353 | // Statement 2: INSERT on line 2 |
| 354 | ins, ok := tree.Statements[1].(*ast.InsertStatement) |
| 355 | if !ok { |
| 356 | t.Fatalf("expected *ast.InsertStatement, got %T", tree.Statements[1]) |
| 357 | } |
| 358 | assertPosEqual(t, "INSERT.Pos", ins.Pos, 2, 1) |
| 359 | |
| 360 | // Statement 3: DELETE on line 3 |
| 361 | del, ok := tree.Statements[2].(*ast.DeleteStatement) |
| 362 | if !ok { |
| 363 | t.Fatalf("expected *ast.DeleteStatement, got %T", tree.Statements[2]) |
| 364 | } |
| 365 | assertPosEqual(t, "DELETE.Pos", del.Pos, 3, 1) |
| 366 | } |
| 367 | |
| 368 | // ----------------------------------------------------------------------------- |
| 369 | // TestPositionsWithoutPositionTracking verifies that ParseFromModelTokens |
nothing calls this directly
no test coverage detected