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

Function TestSelectWithOrderByCommand

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

Source from the content-addressed store, hash-verified

321}
322
323func TestSelectWithOrderByCommand(t *testing.T) {
324 input := "SELECT * FROM tableName ORDER BY colName1 DESC;"
325 expectedSortPattern := ast.SortPattern{
326 ColumnName: token.Token{Type: token.IDENT, Literal: "colName1"},
327 Order: token.Token{Type: token.DESC, Literal: "DESC"},
328 }
329 expectedOrderByCommand := ast.OrderByCommand{
330 Token: token.Token{Type: token.ORDER, Literal: "ORDER"},
331 SortPatterns: []ast.SortPattern{expectedSortPattern},
332 }
333 expectedTableName := "tableName"
334 expectedSpaces := []ast.Space{{ColumnName: token.Token{Type: token.ASTERISK, Literal: "*"}}}
335
336 lexer := lexer.RunLexer(input)
337 parserInstance := New(lexer)
338 sequences, err := parserInstance.ParseSequence()
339 if err != nil {
340 t.Fatalf("Got error from parser: %s", err)
341 }
342
343 if len(sequences.Commands) != 1 {
344 t.Fatalf("sequences does not contain 1 statements. got=%d", len(sequences.Commands))
345 }
346
347 selectCommand := sequences.Commands[0].(*ast.SelectCommand)
348
349 if !testSelectStatement(t, selectCommand, expectedTableName, expectedSpaces, false) {
350 return
351 }
352
353 if !selectCommand.HasOrderByCommand() {
354 t.Fatalf("sequences does not contain where command")
355 }
356
357 testOrderByCommands(t, expectedOrderByCommand, selectCommand.OrderByCommand)
358}
359
360func TestSelectWithLimitCommand(t *testing.T) {
361 input := "SELECT * FROM tableName LIMIT 5;"

Callers

nothing calls this directly

Calls 6

RunLexerFunction · 0.92
testSelectStatementFunction · 0.85
testOrderByCommandsFunction · 0.85
ParseSequenceMethod · 0.80
HasOrderByCommandMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected