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

Function TestSelectWithAggregateFunctions

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

Source from the content-addressed store, hash-verified

660}
661
662func TestSelectWithAggregateFunctions(t *testing.T) {
663 input := "SELECT MIN(colOne), MAX(colOne), COUNT(*), COUNT(colOne), SUM(colOne), AVG(colOne) FROM tbl;"
664
665 expectedTableName := "tbl"
666 expectedSpaces := []ast.Space{
667 {
668 ColumnName: token.Token{Type: token.IDENT, Literal: "colOne"},
669 AggregateFunc: &token.Token{Type: token.MIN, Literal: "MIN"},
670 },
671 {
672 ColumnName: token.Token{Type: token.ASTERISK, Literal: "colOne"},
673 AggregateFunc: &token.Token{Type: token.MAX, Literal: "MAX"},
674 },
675 {
676 ColumnName: token.Token{Type: token.IDENT, Literal: "*"},
677 AggregateFunc: &token.Token{Type: token.COUNT, Literal: "COUNT"},
678 },
679 {
680 ColumnName: token.Token{Type: token.IDENT, Literal: "colOne"},
681 AggregateFunc: &token.Token{Type: token.COUNT, Literal: "COUNT"},
682 },
683 {
684 ColumnName: token.Token{Type: token.IDENT, Literal: "colOne"},
685 AggregateFunc: &token.Token{Type: token.SUM, Literal: "SUM"},
686 },
687 {
688 ColumnName: token.Token{Type: token.IDENT, Literal: "colOne"},
689 AggregateFunc: &token.Token{Type: token.AVG, Literal: "AVG"},
690 },
691 }
692
693 lexer := lexer.RunLexer(input)
694 parserInstance := New(lexer)
695 sequences, err := parserInstance.ParseSequence()
696 if err != nil {
697 t.Fatalf("Got error from parser: %s", err)
698 }
699
700 if len(sequences.Commands) != 1 {
701 t.Fatalf("sequences does not contain 1 statements. got=%d", len(sequences.Commands))
702 }
703
704 selectCommand := sequences.Commands[0].(*ast.SelectCommand)
705
706 if !testSelectStatement(t, selectCommand, expectedTableName, expectedSpaces, false) {
707 return
708 }
709}
710
711func TestParseUpdateCommand(t *testing.T) {
712 tests := []struct {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected