(t *testing.T)
| 660 | } |
| 661 | |
| 662 | func 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 | |
| 711 | func TestParseUpdateCommand(t *testing.T) { |
| 712 | tests := []struct { |
nothing calls this directly
no test coverage detected