parentheses.test 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Pretty printer generates least-parentheses output
  2. -----
  3. <?php
  4. echo 'abc' . 'cde' . 'fgh';
  5. echo 'abc' . ('cde' . 'fgh');
  6. echo 'abc' . 1 + 2 . 'fgh';
  7. echo 'abc' . (1 + 2) . 'fgh';
  8. echo 1 * 2 + 3 / 4 % 5 . 6;
  9. echo 1 * (2 + 3) / (4 % (5 . 6));
  10. $a = $b = $c = $d = $f && true;
  11. ($a = $b = $c = $d = $f) && true;
  12. $a = $b = $c = $d = $f and true;
  13. $a = $b = $c = $d = ($f and true);
  14. $a ? $b : $c ? $d : $e ? $f : $g;
  15. $a ? $b : ($c ? $d : ($e ? $f : $g));
  16. $a ? $b ? $c : $d : $f;
  17. (1 > 0) > (1 < 0);
  18. // this will currently unnecessarily print !($a = $b). This is correct as far as operator precedence is concerned, but
  19. // the parentheses are not really necessary, because = takes only variables as the left hand side operator.
  20. !$a = $b;
  21. -----
  22. echo 'abc' . 'cde' . 'fgh';
  23. echo 'abc' . ('cde' . 'fgh');
  24. echo 'abc' . 1 + 2 . 'fgh';
  25. echo 'abc' . (1 + 2) . 'fgh';
  26. echo 1 * 2 + 3 / 4 % 5 . 6;
  27. echo 1 * (2 + 3) / (4 % (5 . 6));
  28. $a = $b = $c = $d = $f && true;
  29. ($a = $b = $c = $d = $f) && true;
  30. $a = $b = $c = $d = $f and true;
  31. $a = $b = $c = $d = ($f and true);
  32. $a ? $b : $c ? $d : $e ? $f : $g;
  33. $a ? $b : ($c ? $d : ($e ? $f : $g));
  34. $a ? $b ? $c : $d : $f;
  35. (1 > 0) > (1 < 0);
  36. // this will currently unnecessarily print !($a = $b). This is correct as far as operator precedence is concerned, but
  37. // the parentheses are not really necessary, because = takes only variables as the left hand side operator.
  38. !($a = $b);