You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArrayInc.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import org.aspectj.testing.Tester;
  2. /**
  3. * @testcase PR#715 PUREJAVA incrementing array
  4. */
  5. public class ArrayInc {
  6. private static void testCheck(boolean b, String s) {
  7. Tester.check(b,s);
  8. //if (!b) System.err.println("error: " + s);
  9. }
  10. private static int[] IRA=new int[]{0,1,2};
  11. static int[] getIRA() { return IRA; }
  12. static int[] throwError() { throw new Error(""); }
  13. public static void main(String[] args) {
  14. ArrayInc me = new ArrayInc();
  15. me.testArrayExpressionOrdering();
  16. me.testArrayExpression();
  17. }
  18. public void testArrayExpression() {
  19. IRA = new int[]{0};
  20. String[] sra = new String[] {""};
  21. sra[0] += "1";
  22. sra[0] += "string concat";
  23. testCheck(0==getIRA()[0],
  24. "0==getIRA()[0]: " + IRA[0]);
  25. testCheck(0==IRA[0]++, "0==IRA[0]++: " + IRA[0]);
  26. testCheck(1==IRA[0], "1==IRA[0]: " + IRA[0]);
  27. testCheck(2==++getIRA()[0],
  28. "2==++getIRA()[0]: " + IRA[0]);;
  29. testCheck(2==IRA[0], "2==IRA[0]: " + IRA[0]);
  30. }
  31. public void testArrayExpressionOrdering() {
  32. boolean gotError = false;
  33. int i = 0;
  34. try { int k = throwError()[++i]; }
  35. catch (Error e) { gotError = true; }
  36. testCheck(i==0, "i=" + i);
  37. testCheck(gotError, "no error");
  38. i = 0;
  39. gotError = false;
  40. try { int k = throwError()[i++]; }
  41. catch (Error e) { gotError = true; }
  42. testCheck(i==0, "i++ !=0: " + i);
  43. testCheck(gotError, "no error");
  44. }
  45. }