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

Function TestSelectWithLimitAndOffsetCommand

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

Source from the content-addressed store, hash-verified

424}
425
426func TestSelectWithLimitAndOffsetCommand(t *testing.T) {
427 input := "SELECT * FROM tableName ORDER BY colName1 DESC LIMIT 2 OFFSET 13;"
428 expectedLimitCommand := ast.LimitCommand{
429 Token: token.Token{Type: token.LIMIT, Literal: "LIMIT"},
430 Count: 2,
431 }
432 expectedOffsetCommand := ast.OffsetCommand{
433 Token: token.Token{Type: token.OFFSET, Literal: "OFFSET"},
434 Count: 13,
435 }
436 expectedTableName := "tableName"
437 expectedSpaces := []ast.Space{{ColumnName: token.Token{Type: token.ASTERISK, Literal: "*"}}}
438
439 lexer := lexer.RunLexer(input)
440 parserInstance := New(lexer)
441 sequences, err := parserInstance.ParseSequence()
442 if err != nil {
443 t.Fatalf("Got error from parser: %s", err)
444 }
445
446 if len(sequences.Commands) != 1 {
447 t.Fatalf("sequences does not contain 1 statements. got=%d", len(sequences.Commands))
448 }
449
450 selectCommand := sequences.Commands[0].(*ast.SelectCommand)
451
452 if !testSelectStatement(t, selectCommand, expectedTableName, expectedSpaces, false) {
453 return
454 }
455
456 if !selectCommand.HasLimitCommand() {
457 t.Fatalf("select command should have limit command")
458 }
459 if !selectCommand.HasOffsetCommand() {
460 t.Fatalf("select command should have offset command")
461 }
462
463 testLimitCommands(t, expectedLimitCommand, selectCommand.LimitCommand)
464 testOffsetCommands(t, expectedOffsetCommand, selectCommand.OffsetCommand)
465}
466
467func TestSelectWithDefaultInnerJoinCommand(t *testing.T) {
468 input := "SELECT tbl.one, tbl2.two FROM tbl JOIN tbl2 ON tbl.one EQUAL tbl2.one;"

Callers

nothing calls this directly

Calls 8

RunLexerFunction · 0.92
testSelectStatementFunction · 0.85
testLimitCommandsFunction · 0.85
testOffsetCommandsFunction · 0.85
ParseSequenceMethod · 0.80
HasLimitCommandMethod · 0.80
HasOffsetCommandMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected