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

Function TestSelectWithDefaultInnerJoinCommand

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

Source from the content-addressed store, hash-verified

465}
466
467func TestSelectWithDefaultInnerJoinCommand(t *testing.T) {
468 input := "SELECT tbl.one, tbl2.two FROM tbl JOIN tbl2 ON tbl.one EQUAL tbl2.one;"
469 expectedJoinCommand := ast.JoinCommand{
470 Token: token.Token{Type: token.JOIN, Literal: "JOIN"},
471 Name: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl2"}},
472 JoinType: token.Token{Type: token.INNER, Literal: "INNER"},
473 Expression: ast.ConditionExpression{
474 Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl.one"}},
475 Right: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "tbl2.one"}},
476 Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"},
477 },
478 }
479 expectedTableName := "tbl"
480 expectedSpace := []ast.Space{{ColumnName: token.Token{Type: token.IDENT, Literal: "tbl.one"}}, {ColumnName: token.Token{Type: token.IDENT, Literal: "tbl2.two"}}}
481
482 lexer := lexer.RunLexer(input)
483 parserInstance := New(lexer)
484 sequences, err := parserInstance.ParseSequence()
485 if err != nil {
486 t.Fatalf("Got error from parser: %s", err)
487 }
488
489 if len(sequences.Commands) != 1 {
490 t.Fatalf("sequences does not contain 1 statements. got=%d", len(sequences.Commands))
491 }
492
493 selectCommand := sequences.Commands[0].(*ast.SelectCommand)
494
495 if !testSelectStatement(t, selectCommand, expectedTableName, expectedSpace, false) {
496 return
497 }
498
499 if !selectCommand.HasJoinCommand() {
500 t.Fatalf("select command should have join command")
501 }
502
503 testJoinCommands(t, expectedJoinCommand, *selectCommand.JoinCommand)
504}
505
506func TestSelectWithInnerJoinCommand(t *testing.T) {
507 input := "SELECT tbl.one, tbl2.two FROM tbl INNER 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