Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and bmish committed May 26, 2020
1 parent f6ea659 commit a1c5b30
Showing 1 changed file with 96 additions and 2 deletions.
98 changes: 96 additions & 2 deletions test/no-for-loop.js
Expand Up @@ -499,19 +499,113 @@ ruleTester.run('no-for-loop', rule, {
}
`),

// Avoid naming collision when using default element name (different scope).
testCase(outdent`
function element(element_) {
for (let i = 0; i < arr.length; i += 1) {
console.log(arr[i], element);
}
}
`, outdent`
function element(element_) {
for (const element__ of arr) {
console.log(element__, element);
}
}
`),
testCase(outdent`
for (let i = 0; i < arr.length; i += 1) {
function element__(element) {
console.log(arr[i], element);
}
}
`, outdent`
for (const element_ of arr) {
function element__(element) {
console.log(element_, element);
}
}
`),
testCase(outdent`
for (let i = 0; i < arr.length; i += 1) {
function element_(element) {
console.log(arr[i], element);
}
}
`, outdent`
for (const element__ of arr) {
function element_(element) {
console.log(element__, element);
}
}
`),
testCase(outdent`
for (let i = 0; i < arr.length; i += 1) {
function element() {
console.log(arr[i], element);
}
}
`, outdent`
for (const element_ of arr) {
function element() {
console.log(element_, element);
}
}
`),
testCase(outdent`
for (let i = 0; i < arr.length; i += 1) {
console.log(arr[i], element);
}
`, outdent`
for (const element_ of arr) {
console.log(element_, element);
}
`),
testCase(outdent`
for (let element = 0; element < arr.length; element += 1) {
console.log(element, arr[element]);
}
`, outdent`
for (const [element, element_] of arr.entries()) {
console.log(element, element_);
}
`),
testCase(outdent`
for (let element = 0; element < arr.length; element += 1) {
console.log(arr[element]);
}
`, outdent`
for (const element_ of arr) {
console.log(element_);
}
`),
testCase(outdent`
for (const element of arr) {
for (let j = 0; j < arr2.length; j += 1) {
console.log(element, arr2[j]);
}
}
`, outdent`
for (const element of arr) {
for (const element_ of arr2) {
console.log(element, element_);
}
}
`),

// Avoid naming collision when using default element name (multiple collisions).
testCase(outdent`
for (let i = 0; i < arr.length; i += 1) {
console.log(arr[i]);
const element = foo();
console.log(arr[i]);
const element_ = foo();
console.log(element);
console.log(element_);
}
`, outdent`
for (const element__ of arr) {
console.log(element__);
const element = foo();
console.log(element__);
const element_ = foo();
console.log(element);
console.log(element_);
Expand Down

0 comments on commit a1c5b30

Please sign in to comment.