(t *testing.T)
| 805 | } |
| 806 | |
| 807 | func TestParseLogicOperatorsInCommand(t *testing.T) { |
| 808 | |
| 809 | firstExpression := ast.OperationExpression{ |
| 810 | Left: ast.ConditionExpression{ |
| 811 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName1"}}, |
| 812 | Right: ast.Anonymitifier{Token: token.Token{Type: token.IDENT, Literal: "fda"}}, |
| 813 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}}, |
| 814 | Right: ast.ConditionExpression{ |
| 815 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName2"}}, |
| 816 | Right: ast.Anonymitifier{Token: token.Token{Type: token.NULL, Literal: "NULL"}}, |
| 817 | Condition: token.Token{Type: token.EQUAL, Literal: "NOT"}}, |
| 818 | Operation: token.Token{Type: token.AND, Literal: "AND"}, |
| 819 | } |
| 820 | |
| 821 | secondExpression := ast.OperationExpression{ |
| 822 | Left: ast.ConditionExpression{ |
| 823 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName2"}}, |
| 824 | Right: ast.Anonymitifier{Token: token.Token{Type: token.LITERAL, Literal: "6462389"}}, |
| 825 | Condition: token.Token{Type: token.NOT, Literal: "NOT"}}, |
| 826 | Right: ast.ConditionExpression{ |
| 827 | Left: ast.Identifier{Token: token.Token{Type: token.IDENT, Literal: "colName1"}}, |
| 828 | Right: ast.Anonymitifier{Token: token.Token{Type: token.IDENT, Literal: "NULL"}}, |
| 829 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}}, |
| 830 | Operation: token.Token{Type: token.OR, Literal: "OR"}, |
| 831 | } |
| 832 | |
| 833 | thirdExpression := ast.BooleanExpression{ |
| 834 | Boolean: token.Token{Type: token.TRUE, Literal: "TRUE"}, |
| 835 | } |
| 836 | |
| 837 | fourthExpression := ast.ConditionExpression{ |
| 838 | Left: ast.Anonymitifier{Token: token.Token{Type: token.IDENT, Literal: "colName1 EQUAL;"}}, |
| 839 | Right: ast.Anonymitifier{Token: token.Token{Type: token.IDENT, Literal: "colName1 EQUAL;"}}, |
| 840 | Condition: token.Token{Type: token.EQUAL, Literal: "EQUAL"}} |
| 841 | |
| 842 | tests := []struct { |
| 843 | input string |
| 844 | expectedExpression ast.Expression |
| 845 | }{ |
| 846 | { |
| 847 | input: "SELECT * FROM TBL WHERE colName1 EQUAL 'fda' AND colName2 NOT NULL;", |
| 848 | expectedExpression: firstExpression, |
| 849 | }, |
| 850 | { |
| 851 | input: "SELECT * FROM TBL WHERE colName2 NOT 6462389 OR colName1 EQUAL 'NULL';", |
| 852 | expectedExpression: secondExpression, |
| 853 | }, |
| 854 | { |
| 855 | input: "SELECT * FROM TBL WHERE TRUE;", |
| 856 | expectedExpression: thirdExpression, |
| 857 | }, |
| 858 | { |
| 859 | input: "SELECT * FROM TBL WHERE 'colName1 EQUAL;' EQUAL 'colName1 EQUAL;';", |
| 860 | expectedExpression: fourthExpression, |
| 861 | }, |
| 862 | } |
| 863 | |
| 864 | for testIndex, tt := range tests { |
nothing calls this directly
no test coverage detected