(t *testing.T)
| 543 | } |
| 544 | |
| 545 | func TestSelectWithLeftJoinCommand(t *testing.T) { |
| 546 | input := "SELECT tbl.one, tbl2.two FROM tbl LEFT JOIN tbl2 ON tbl.one EQUAL tbl2.one;" |
| 547 | expectedJoinCommand := ast.JoinCommand{ |
| 548 | Token: token.Token{Type: token.JOIN, Literal: "JOIN"}, |
| 549 | Name: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl2"}}, |
| 550 | JoinType: token.Token{Type: token.LEFT, Literal: "LEFT"}, |
| 551 | Expression: ast.ConditionExpression{ |
| 552 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl.one"}}, |
| 553 | Right: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl2.one"}}, |
| 554 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}, |
| 555 | }, |
| 556 | } |
| 557 | expectedTableName := "tbl" |
| 558 | expectedSpaces := []ast.Space{{ColumnName: token.Token{Type: token.IDENT, Literal: "tbl.one"}}, {ColumnName: token.Token{Type: token.IDENT, Literal: "tbl2.two"}}} |
| 559 | |
| 560 | lexer := lexer.RunLexer(input) |
| 561 | parserInstance := New(lexer) |
| 562 | sequences, err := parserInstance.ParseSequence() |
| 563 | if err != nil { |
| 564 | t.Fatalf("Got error from parser: %s", err) |
| 565 | } |
| 566 | |
| 567 | if len(sequences.Commands) != 1 { |
| 568 | t.Fatalf("sequences does not contain 1 statements. got=%d", len(sequences.Commands)) |
| 569 | } |
| 570 | |
| 571 | selectCommand := sequences.Commands[0].(*ast.SelectCommand) |
| 572 | |
| 573 | if !testSelectStatement(t, selectCommand, expectedTableName, expectedSpaces, false) { |
| 574 | return |
| 575 | } |
| 576 | |
| 577 | if !selectCommand.HasJoinCommand() { |
| 578 | t.Fatalf("select command should have join command") |
| 579 | } |
| 580 | |
| 581 | testJoinCommands(t, expectedJoinCommand, *selectCommand.JoinCommand) |
| 582 | } |
| 583 | |
| 584 | func TestSelectWithRightJoinCommand(t *testing.T) { |
| 585 | input := "SELECT tbl.one, tbl2.two FROM tbl RIGHT JOIN tbl2 ON tbl.one EQUAL tbl2.one;" |
nothing calls this directly
no test coverage detected