|
12 | 12 | import net.sf.jsqlparser.JSQLParserException; |
13 | 13 | import net.sf.jsqlparser.expression.operators.arithmetic.Addition; |
14 | 14 | import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; |
| 15 | +import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor; |
15 | 16 | import net.sf.jsqlparser.expression.operators.arithmetic.Concat; |
| 17 | +import net.sf.jsqlparser.expression.operators.arithmetic.Division; |
| 18 | +import net.sf.jsqlparser.expression.operators.arithmetic.Modulo; |
| 19 | +import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication; |
16 | 20 | import net.sf.jsqlparser.expression.operators.conditional.AndExpression; |
17 | 21 | import net.sf.jsqlparser.expression.operators.relational.Between; |
18 | 22 | import net.sf.jsqlparser.expression.operators.relational.EqualsTo; |
@@ -217,4 +221,35 @@ public void testValuePositionNotStaysOnOperand() throws JSQLParserException { |
217 | 221 | Addition add = Assertions.assertInstanceOf(Addition.class, addition); |
218 | 222 | Assertions.assertInstanceOf(NotExpression.class, add.getRightExpression()); |
219 | 223 | } |
| 224 | + |
| 225 | + @Test |
| 226 | + public void testCaretBindsTighterThanMultiplication() throws JSQLParserException { |
| 227 | + // PostgreSQL's power and MySQL's XOR both evaluate 2 * 3 ^ 2 as 2 * (3 ^ 2) |
| 228 | + Multiplication multiplication = Assertions.assertInstanceOf(Multiplication.class, |
| 229 | + CCJSqlParserUtil.parseExpression("2 * 3 ^ 2")); |
| 230 | + Assertions.assertInstanceOf(LongValue.class, multiplication.getLeftExpression()); |
| 231 | + Assertions.assertInstanceOf(BitwiseXor.class, multiplication.getRightExpression()); |
| 232 | + |
| 233 | + Division division = Assertions.assertInstanceOf(Division.class, |
| 234 | + CCJSqlParserUtil.parseExpression("10 / 2 ^ 2")); |
| 235 | + Assertions.assertInstanceOf(BitwiseXor.class, division.getRightExpression()); |
| 236 | + |
| 237 | + Modulo modulo = Assertions.assertInstanceOf(Modulo.class, |
| 238 | + CCJSqlParserUtil.parseExpression("18 % 4 ^ 2")); |
| 239 | + Assertions.assertInstanceOf(BitwiseXor.class, modulo.getRightExpression()); |
| 240 | + |
| 241 | + multiplication = Assertions.assertInstanceOf(Multiplication.class, |
| 242 | + CCJSqlParserUtil.parseExpression("2 ^ 3 * 2")); |
| 243 | + Assertions.assertInstanceOf(BitwiseXor.class, multiplication.getLeftExpression()); |
| 244 | + |
| 245 | + TestUtils.assertSqlCanBeParsedAndDeparsed("SELECT pi() * r ^ 2 FROM circles"); |
| 246 | + } |
| 247 | + |
| 248 | + @Test |
| 249 | + public void testCaretIsLeftAssociative() throws JSQLParserException { |
| 250 | + BitwiseXor outer = Assertions.assertInstanceOf(BitwiseXor.class, |
| 251 | + CCJSqlParserUtil.parseExpression("2 ^ 3 ^ 2")); |
| 252 | + Assertions.assertInstanceOf(BitwiseXor.class, outer.getLeftExpression()); |
| 253 | + Assertions.assertInstanceOf(LongValue.class, outer.getRightExpression()); |
| 254 | + } |
220 | 255 | } |
0 commit comments