loops.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. while_becomes_for: {
  2. options = { loops: true };
  3. input: {
  4. while (foo()) bar();
  5. }
  6. expect: {
  7. for (; foo(); ) bar();
  8. }
  9. }
  10. drop_if_break_1: {
  11. options = { loops: true };
  12. input: {
  13. for (;;)
  14. if (foo()) break;
  15. }
  16. expect: {
  17. for (; !foo(););
  18. }
  19. }
  20. drop_if_break_2: {
  21. options = { loops: true };
  22. input: {
  23. for (;bar();)
  24. if (foo()) break;
  25. }
  26. expect: {
  27. for (; bar() && !foo(););
  28. }
  29. }
  30. drop_if_break_3: {
  31. options = { loops: true };
  32. input: {
  33. for (;bar();) {
  34. if (foo()) break;
  35. stuff1();
  36. stuff2();
  37. }
  38. }
  39. expect: {
  40. for (; bar() && !foo();) {
  41. stuff1();
  42. stuff2();
  43. }
  44. }
  45. }
  46. drop_if_break_4: {
  47. options = { loops: true, sequences: true };
  48. input: {
  49. for (;bar();) {
  50. x();
  51. y();
  52. if (foo()) break;
  53. z();
  54. k();
  55. }
  56. }
  57. expect: {
  58. for (; bar() && (x(), y(), !foo());) z(), k();
  59. }
  60. }
  61. drop_if_else_break_1: {
  62. options = { loops: true };
  63. input: {
  64. for (;;) if (foo()) bar(); else break;
  65. }
  66. expect: {
  67. for (; foo(); ) bar();
  68. }
  69. }
  70. drop_if_else_break_2: {
  71. options = { loops: true };
  72. input: {
  73. for (;bar();) {
  74. if (foo()) baz();
  75. else break;
  76. }
  77. }
  78. expect: {
  79. for (; bar() && foo();) baz();
  80. }
  81. }
  82. drop_if_else_break_3: {
  83. options = { loops: true };
  84. input: {
  85. for (;bar();) {
  86. if (foo()) baz();
  87. else break;
  88. stuff1();
  89. stuff2();
  90. }
  91. }
  92. expect: {
  93. for (; bar() && foo();) {
  94. baz();
  95. stuff1();
  96. stuff2();
  97. }
  98. }
  99. }
  100. drop_if_else_break_4: {
  101. options = { loops: true, sequences: true };
  102. input: {
  103. for (;bar();) {
  104. x();
  105. y();
  106. if (foo()) baz();
  107. else break;
  108. z();
  109. k();
  110. }
  111. }
  112. expect: {
  113. for (; bar() && (x(), y(), foo());) baz(), z(), k();
  114. }
  115. }