Skip to content

Commit

Permalink
chore: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jul 14, 2021
1 parent 985d843 commit 9a4c7d7
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions tests/lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5529,7 +5529,10 @@ var a = "test2";
let messages;

it("//eslint-disable", () => {
const codes = linebreaks.map(linebreak => `//eslint-disable no-debugger${linebreak}debugger;`);
const codes = [
...linebreaks.map(linebreak => `//eslint-disable no-debugger${linebreak}debugger;`),
...linebreaks.map(linebreak => `// eslint-disable no-debugger${linebreak}debugger;`)
];

for (const code of codes) {
messages = linter.verify(code, { rules: { "no-debugger": 2 } });
Expand All @@ -5541,7 +5544,10 @@ var a = "test2";
});

it("//eslint-enable", () => {
const codes = linebreaks.map(linebreak => `//eslint-disable no-debugger${linebreak}//eslint-enable no-debugger${linebreak}debugger;`);
const codes = [
...linebreaks.map(linebreak => `//eslint-disable no-debugger${linebreak}//eslint-enable no-debugger${linebreak}debugger;`),
...linebreaks.map(linebreak => `// eslint-disable no-debugger${linebreak}//eslint-enable no-debugger${linebreak}debugger;`)
];

for (const code of codes) {
messages = linter.verify(code, { rules: { "no-debugger": 2 } });
Expand All @@ -5550,7 +5556,10 @@ var a = "test2";
});

it("//eslint", () => {
const codes = linebreaks.map(linebreak => `//eslint no-debugger:'error'${linebreak}debugger;`);
const codes = [
...linebreaks.map(linebreak => `//eslint no-debugger:'error'${linebreak}debugger;`),
...linebreaks.map(linebreak => `// eslint no-debugger:'error'${linebreak}debugger;`)
];

for (const code of codes) {
messages = linter.verify(code, { rules: { "no-debugger": 0 } });
Expand All @@ -5563,8 +5572,10 @@ var a = "test2";
it("//global(s)", () => {
const config = { rules: { "no-undef": 2 } };
const codes = [
"//globals foo: true\nfoo;",
"//global foo: true\nfoo;"
...linebreaks.map(linebreak => `//globals foo: true${linebreak}foo;`),
...linebreaks.map(linebreak => `// globals foo: true${linebreak}foo;`),
...linebreaks.map(linebreak => `//global foo: true${linebreak}foo;`),
...linebreaks.map(linebreak => `// global foo: true${linebreak}foo;`)
];

for (const code of codes) {
Expand All @@ -5573,11 +5584,16 @@ var a = "test2";
}
});
it("//exported", () => {
const code = "//exported foo\nvar foo = 0;";
const codes = [
...linebreaks.map(linebreak => `//exported foo${linebreak}var foo = 0;`),
...linebreaks.map(linebreak => `// exported foo${linebreak}var foo = 0;`)
];
const config = { rules: { "no-unused-vars": 2 } };

messages = linter.verify(code, config, filename);
assert.strictEqual(messages.length, 0);
for (const code of codes) {
messages = linter.verify(code, config, filename);
assert.strictEqual(messages.length, 0);
}
});

describe("//eslint-env", () => {
Expand All @@ -5599,7 +5615,9 @@ var a = "test2";
it("multiple envs enabled with different line breaks", () => {
const codes = [
...linebreaks.map(linebreak => `//${ESLINT_ENV} browser,es6${linebreak}window;Promise;`),
...linebreaks.map(linebreak => `//${ESLINT_ENV} browser${linebreak}//${ESLINT_ENV} es6${linebreak}window;Promise;`)
...linebreaks.map(linebreak => `// ${ESLINT_ENV} browser,es6${linebreak}window;Promise;`),
...linebreaks.map(linebreak => `//${ESLINT_ENV} browser${linebreak}//${ESLINT_ENV} es6${linebreak}window;Promise;`),
...linebreaks.map(linebreak => `// ${ESLINT_ENV} browser${linebreak}//${ESLINT_ENV} es6${linebreak}window;Promise;`)
];

for (const code of codes) {
Expand All @@ -5611,7 +5629,9 @@ var a = "test2";
it("no env enabled with different linebreaks", () => {
const codes = [
...linebreaks.map(linebreak => `//${ESLINT_ENV}${linebreak}browser${linebreak}window;`),
...linebreaks.map(linebreak => `//${ESLINT_ENV}browser${linebreak}window;window;`)
...linebreaks.map(linebreak => `// ${ESLINT_ENV}${linebreak}browser${linebreak}window;`),
...linebreaks.map(linebreak => `//${ESLINT_ENV}browser${linebreak}window;window;`),
...linebreaks.map(linebreak => `// ${ESLINT_ENV}browser${linebreak}window;window;`)
];

for (const code of codes) {
Expand Down

0 comments on commit 9a4c7d7

Please sign in to comment.