(t *testing.T)
| 154 | } |
| 155 | |
| 156 | func TestParseWhereCommand(t *testing.T) { |
| 157 | firstExpression := ast.ConditionExpression{ |
| 158 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName1"}}, |
| 159 | Right: ast.Anonymitifier{Token: token.Token{Type: token.IDENT, Literal: "fda"}}, |
| 160 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}, |
| 161 | } |
| 162 | |
| 163 | secondExpression := ast.ConditionExpression{ |
| 164 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName2"}}, |
| 165 | Right: ast.Anonymitifier{Token: token.Token{Type: token.LITERAL, Literal: "6462389"}}, |
| 166 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}, |
| 167 | } |
| 168 | |
| 169 | thirdExpression := ast.ContainExpression{ |
| 170 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName3"}}, |
| 171 | Right: []ast.Anonymitifier{ |
| 172 | {Token: token.Token{Type: token.LITERAL, Literal: "1"}}, |
| 173 | {Token: token.Token{Type: token.LITERAL, Literal: "2"}}, |
| 174 | }, |
| 175 | Contains: true, |
| 176 | } |
| 177 | |
| 178 | fourthExpression := ast.ContainExpression{ |
| 179 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName4"}}, |
| 180 | Right: []ast.Anonymitifier{ |
| 181 | {Token: token.Token{Type: token.IDENT, Literal: "one"}}, |
| 182 | {Token: token.Token{Type: token.IDENT, Literal: "two"}}, |
| 183 | }, |
| 184 | Contains: false, |
| 185 | } |
| 186 | |
| 187 | fifthExpression := ast.ConditionExpression{ |
| 188 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName5"}}, |
| 189 | Right: ast.Anonymitifier{Token: token.Token{Type: token.NULL, Literal: "NULL"}}, |
| 190 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}, |
| 191 | } |
| 192 | |
| 193 | tests := []struct { |
| 194 | input string |
| 195 | expectedExpression ast.Expression |
| 196 | }{ |
| 197 | { |
| 198 | input: "SELECT * FROM TBL WHERE colName1 EQUAL 'fda';", |
| 199 | expectedExpression: firstExpression, |
| 200 | }, |
| 201 | { |
| 202 | input: "SELECT * FROM TBL WHERE colName2 EQUAL 6462389;", |
| 203 | expectedExpression: secondExpression, |
| 204 | }, |
| 205 | { |
| 206 | input: "SELECT * FROM TBL WHERE colName3 IN (1, 2);", |
| 207 | expectedExpression: thirdExpression, |
| 208 | }, |
| 209 | { |
| 210 | input: "SELECT * FROM TBL WHERE colName4 NOTIN ('one', 'two');", |
| 211 | expectedExpression: fourthExpression, |
| 212 | }, |
| 213 | { |
nothing calls this directly
no test coverage detected