MCPcopy Create free account
hub / github.com/LissaGreense/GO4SQL / TestSelectWithRightJoinCommand

Function TestSelectWithRightJoinCommand

parser/parser_test.go:584–621  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

582}
583
584func TestSelectWithRightJoinCommand(t *testing.T) {
585 input := "SELECT tbl.one, tbl2.two FROM tbl RIGHT JOIN tbl2 ON tbl.one EQUAL tbl2.one;"
586 expectedJoinCommand := ast.JoinCommand{
587 Token: token.Token{Type: token.JOIN, Literal: "JOIN"},
588 Name: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl2"}},
589 JoinType: token.Token{Type: token.RIGHT, Literal: "RIGHT"},
590 Expression: ast.ConditionExpression{
591 Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl.one"}},
592 Right: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl2.one"}},
593 Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"},
594 },
595 }
596 expectedTableName := "tbl"
597 expectedSpaces := []ast.Space{{ColumnName: token.Token{Type: token.IDENT, Literal: "tbl.one"}}, {ColumnName: token.Token{Type: token.IDENT, Literal: "tbl2.two"}}}
598
599 lexer := lexer.RunLexer(input)
600 parserInstance := New(lexer)
601 sequences, err := parserInstance.ParseSequence()
602 if err != nil {
603 t.Fatalf("Got error from parser: %s", err)
604 }
605
606 if len(sequences.Commands) != 1 {
607 t.Fatalf("sequences does not contain 1 statements. got=%d", len(sequences.Commands))
608 }
609
610 selectCommand := sequences.Commands[0].(*ast.SelectCommand)
611
612 if !testSelectStatement(t, selectCommand, expectedTableName, expectedSpaces, false) {
613 return
614 }
615
616 if !selectCommand.HasJoinCommand() {
617 t.Fatalf("select command should have join command")
618 }
619
620 testJoinCommands(t, expectedJoinCommand, *selectCommand.JoinCommand)
621}
622
623func TestSelectWithFullJoinCommand(t *testing.T) {
624 input := "SELECT tbl.one, tbl2.two FROM tbl FULL JOIN tbl2 ON tbl.one EQUAL tbl2.one;"

Callers

nothing calls this directly

Calls 6

RunLexerFunction · 0.92
testSelectStatementFunction · 0.85
testJoinCommandsFunction · 0.85
ParseSequenceMethod · 0.80
HasJoinCommandMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected