void () { String in = """ class X {{ for (int i = 0; i < 10; i++) {} for (int i = 0; i < 10; i++) {} for (int i = 0; i < 10; i++) {} for (int i = 0; i < 10; i++) {} for (;;) {} for (int i = 0; ;) {} for (int i = 0; true; ) {} }}"""; assertEquals("find all for loops", 7, findMatchesCount(in, "for(;;) '_st;")); assertEquals("find loops without initializers", 1, findMatchesCount(in, "for('_init{0,0};;) '_st;")); assertEquals("find loops without condition", 2, findMatchesCount(in, "for(;'_cond{0,0};) '_st;")); assertEquals("find loops without update", 3, findMatchesCount(in, "for(;;'_update{0,0}) '_st;")); assertEquals("find all for loops 2", 7, findMatchesCount(in, "for('_init?;;) '_st;")); assertEquals("find all for loops 3", 7, findMatchesCount(in, "for(;;'_update?) '_st;")); assertEquals("find all for loops 4", 7, findMatchesCount(in, "for(;'_cond?;) '_st;")); assertEquals("find loops with initializer, condition and update", 4, findMatchesCount(in, "for ('_init; '_cond; '_update) '_st;")); String in2 = """ class X {{ int i = 0, j = 0; for (i=1, j=1;; i++, j++) {} for (;; i++, j++) {} for (i=1;;i++){} }}"""; assertEquals("find for loops with 2 initializer expressions", 1, findMatchesCount(in2, "for ('_init{2,2};;) '_st;")); assertEquals("find for loops with 2 initializer expressions 2", 1, findMatchesCount(in2, "for ('_init1, '_init2;;) '_st;")); assertEquals("find for loops with 2 update expressions", 2, findMatchesCount(in2, "for (;;'_update{2,2}) '_st;")); assertEquals("find for loops with 2 update expressions 2", 2, findMatchesCount(in2, "for (;;'_update1, '_update2) '_st;")); }