(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func TestParseSelectCommand(t *testing.T) { |
| 127 | tests := []struct { |
| 128 | input string |
| 129 | expectedTableName string |
| 130 | expectedSpaces []ast.Space |
| 131 | expectedDistinct bool |
| 132 | }{ |
| 133 | {"SELECT * FROM TBL;", "TBL", []ast.Space{{ColumnName: token.Token{Type: token.ASTERISK, Literal: "*"}}}, false}, |
| 134 | {"SELECT ONE, TWO, THREE FROM TBL;", "TBL", []ast.Space{{ColumnName: token.Token{Type: token.IDENT, Literal: "ONE"}}, {ColumnName: token.Token{Type: token.IDENT, Literal: "TWO"}}, {ColumnName: token.Token{Type: token.IDENT, Literal: "THREE"}}}, false}, |
| 135 | {"SELECT DISTINCT * FROM TBL;", "TBL", []ast.Space{{ColumnName: token.Token{Type: token.ASTERISK, Literal: "*"}}}, true}, |
| 136 | } |
| 137 | |
| 138 | for testIndex, tt := range tests { |
| 139 | lexer := lexer.RunLexer(tt.input) |
| 140 | parserInstance := New(lexer) |
| 141 | sequences, err := parserInstance.ParseSequence() |
| 142 | if err != nil { |
| 143 | t.Fatalf("[%d] Got error from parser: %s", testIndex, err) |
| 144 | } |
| 145 | |
| 146 | if len(sequences.Commands) != 1 { |
| 147 | t.Fatalf("[%d] sequences does not contain 1 statements. got=%d", testIndex, len(sequences.Commands)) |
| 148 | } |
| 149 | |
| 150 | if !testSelectStatement(t, sequences.Commands[0], tt.expectedTableName, tt.expectedSpaces, tt.expectedDistinct) { |
| 151 | return |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | func TestParseWhereCommand(t *testing.T) { |
| 157 | firstExpression := ast.ConditionExpression{ |
nothing calls this directly
no test coverage detected