import { ruleTester } from '../rule-tester' ; import rule = require ( '../../src/rules/prefer-while' ) ; const message = 'replaceForWithWhileLoop' ; ruleTester . run ( 'prefer-while' , rule , { valid : [ { code : 'for(var i = 0; condition;) { }' } , { code : 'for(var i = 0; condition; i++) { }' } , { code : 'for(var i = 0;; i++) { }' } , { code : 'for (i; condition; ) { }' } , { code : 'for ( ; i < length; i++ ) { }' } , { code : 'while (i < length) { }' } , { code : 'for (a in b) { }' } , { code : 'for (a of b) { }' } , { code : 'for(;;) {}' } , ] , invalid : [ { code : 'for(;condition;) {}' , errors : [ { messageId : message , line : 1 , column : 1 , endColumn : 4 } ] , output : 'while (condition) {}' , } , { code : 'for (;condition; ) foo();' , errors : [ { messageId : message } ] , output : 'while (condition) foo();' , } , { code : `
        for(;i < 10;)
          doSomething();` , errors : [ { messageId : message } ] , output : `
        while (i < 10)
          doSomething();` , } , ] , } ) ;