Skip to content

Commit

Permalink
Fix tests for *-empty-line-before rules (#2688)
Browse files Browse the repository at this point in the history
* Fix tests for *-empty-line-before rules

* Test addition and tweak
  • Loading branch information
hudochenkov authored and jeddy3 committed Jun 28, 2017
1 parent f06475c commit 9dc852a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
52 changes: 22 additions & 30 deletions lib/rules/at-rule-empty-line-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ testRule(rule, {
}, {
code: stripIndent`
@charset "UTF-8";
@import url(x.css); /* comment */
@import url(y.css);`,
description: "shared-line comment accepted",
} ],

reject: [ {
code: "@keyframes foo {}\n@import 'x.css'",
fixed: "@keyframes foo {}\n\n@import 'x.css'",
Expand All @@ -184,46 +184,24 @@ testRule(rule, {
} ],
})

testRule(rule, {
ruleName,
config: [ "always", { ignore: ["blockless-group"] } ],
fix: true,

accept: [{
code: "@media {}; @import 'x.css';",
}],

reject: [ {
code: "@import 'x.css'; @media {};",
fixed: "@import 'x.css';\n\n @media {};",
message: messages.expected,
line: 1,
column: 18,
}, {
code: "@import 'test'; @include mixin(1) { @content; };",
fixed: "@import 'test';\n\n @include mixin(1) { @content; };",
message: messages.expected,
} ],
})

testRule(rule, {
ruleName,
config: [ "always", { ignore: ["blockless-after-blockless"] } ],
fix: true,

accept: [{
code: "@media {}; @import 'x.css';",
code: "@charset 'UTF-8'; @import 'x.css';",
}],

reject: [ {
code: "@import 'x.css'; @media {};",
fixed: "@import 'x.css';\n\n @media {};",
message: messages.expected,
line: 1,
column: 12,
column: 18,
}, {
code: "@import 'test'; @include mixin(1) { @content; };",
fixed: "@import 'test';\n\n @include mixin(1) { @content; };",
fixed: "@import 'test';\n\n @include mixin(1) {\n\n @content; };",
message: messages.expected,
} ],
})
Expand All @@ -248,6 +226,7 @@ testRule(rule, {
message: messages.expected,
}, {
code: "bar {} /* foo */\n@media {}",
fixed: "bar {} /* foo */\n\n@media {}",
message: messages.expected,
line: 2,
column: 1,
Expand Down Expand Up @@ -443,14 +422,26 @@ testRule(rule, {
accept: [ {
code: `
@media {};
@import 'x.css';
`,
}, {
code: `
@media {};
@import 'x.css';
@import 'y.css';
`,
}, {
code: `
@import 'x.css';
@import 'y.css';
`,
} ],

reject: [{
code: `
@import 'x.css';
@media {};
`,
fixed: `
@import 'x.css';
Expand All @@ -459,7 +450,7 @@ testRule(rule, {
message: messages.rejected,
line: 4,
column: 7,
} ],
}],
})

testRule(rule, {
Expand All @@ -470,7 +461,7 @@ testRule(rule, {
accept: [ {
code: "/* foo */\n@media {}",
}, {
code: "/* foo */\r\na@media {}",
code: "/* foo */\r\n\r\n@media {}",
description: "CRLF",
}, {
code: "/* foo */\n\n@media {}",
Expand All @@ -487,6 +478,7 @@ testRule(rule, {
message: messages.rejected,
}, {
code: "b {} /* comment */\n\n@media {}",
fixed: "b {} /* comment */\n@media {}",
description: "after shared-line comment",
message: messages.rejected,
line: 3,
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/comment-empty-line-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ const alwaysTests = {
description: "Mixed",
}, {
code: "a { color: pink;\n\n/** comment */\ntop: 0; }",
}, {
code: "/** comment */ /** comment */",
description: "no newline between comments",
} ],

reject: [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ testRule(rule, {
column: 2,
}, {
code: "a {\ncolor: pink; /* comment */\n--custom-prop: value;\n}",
fixed: "a {\ncolor: pink; /* comment */\n\n--custom-prop: value;\n}",
message: messages.expected,
line: 3,
column: 1,
description: "shared-line comments do not apply",
}, {
code: "a {\n/* comment */ --custom-prop: value;\n}",
fixed: "a {\n/* comment */\n\n --custom-prop: value;\n}",
message: messages.expected,
line: 2,
column: 15,
Expand Down Expand Up @@ -181,12 +183,14 @@ testRule(rule, {
column: 2,
}, {
code: "a {\ncolor: pink; /* I am a comment */\n--custom-prop2: value;}",
fixed: "a {\ncolor: pink; /* I am a comment */\n\n--custom-prop2: value;}",
message: messages.expected,
line: 3,
column: 1,
description: "shared-line comments do not apply",
}, {
code: "a {/* I am a comment */ \n --custom-prop2: value;}",
fixed: "a {/* I am a comment */ \n\n --custom-prop2: value;}",
message: messages.expected,
line: 2,
column: 2,
Expand Down Expand Up @@ -339,6 +343,7 @@ testRule(rule, {
column: 2,
}, {
code: "a {/* I am a comment */ \n\n --custom-prop2: value;}",
fixed: "a {/* I am a comment */ \n --custom-prop2: value;}",
message: messages.rejected,
line: 3,
column: 2,
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/declaration-empty-line-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,14 @@ testRule(rule, {

reject: [ {
code: "a {\n/* comment */ top: 15px;\n}",
fixed: "a {\n/* comment */\n\n top: 15px;\n}",
message: messages.expected,
line: 2,
column: 15,
description: "shared-line comments don't save you",
}, {
code: "a {/* comment */\n top: 15px;\n}",
fixed: "a {/* comment */\n\n top: 15px;\n}",
message: messages.expected,
line: 2,
column: 2,
Expand Down Expand Up @@ -276,6 +278,7 @@ testRule(rule, {
column: 2,
}, {
code: "a {\n --foo: pink;\n top: 15px;\n}",
fixed: "a {\n --foo: pink;\n\n top: 15px;\n}",
message: messages.expected,
line: 3,
column: 3,
Expand Down Expand Up @@ -338,12 +341,14 @@ testRule(rule, {
column: 2,
}, {
code: "a {\n\n color: pink; /* I am a comment */\n bottom: 5px;}",
fixed: "a {\n\n color: pink; /* I am a comment */\n\n bottom: 5px;}",
message: messages.expected,
line: 4,
column: 2,
description: "shared-line comments do not apply",
}, {
code: "a {/* I am a comment */ \n bottom: 5px;}",
fixed: "a {/* I am a comment */ \n\n bottom: 5px;}",
message: messages.expected,
line: 2,
column: 2,
Expand Down Expand Up @@ -381,6 +386,7 @@ testRule(rule, {
column: 2,
}, {
code: "a {\n --foo: pink;\n bottom: 5px;}",
fixed: "a {\n --foo: pink;\n\n bottom: 5px;}",
message: messages.expected,
line: 3,
column: 3,
Expand Down Expand Up @@ -414,6 +420,7 @@ testRule(rule, {
column: 2,
}, {
code: "a {\n $foo: pink;\n bottom: 5px;}",
fixed: "a {\n $foo: pink;\n\n bottom: 5px;}",
message: messages.expected,
line: 3,
column: 3,
Expand Down Expand Up @@ -588,12 +595,14 @@ testRule(rule, {
column: 2,
}, {
code: "a {\n color: pink; /* I am a comment */\n\n bottom: 5px;}",
fixed: "a {\n color: pink; /* I am a comment */\n bottom: 5px;}",
message: messages.rejected,
line: 4,
column: 2,
description: "shared-line comments do not apply",
}, {
code: "a {/* I am a comment */ \n\n bottom: 5px;}",
fixed: "a {/* I am a comment */ \n bottom: 5px;}",
message: messages.rejected,
line: 3,
column: 2,
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/rule-empty-line-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,11 @@ testRule(rule, {
message: messages.rejected,
}, {
code: "b {}\n \t\na {}",
fixed: "b {}\na {}",
message: messages.rejected,
}, {
code: "b {}\r\n \t\r\na {}",
fixed: "b {}\r\na {}",
description: "CRLF",
message: messages.rejected,
}, {
Expand Down Expand Up @@ -461,9 +463,11 @@ testRule(rule, {
message: messages.rejected,
}, {
code: "b\n{}\n \t\na\n{}",
fixed: "b\n{}\na\n{}",
message: messages.rejected,
}, {
code: "b\r\n{}\r\n \t\r\na\r\n{}",
fixed: "b\r\n{}\r\na\r\n{}",
description: "CRLF",
message: messages.rejected,
}, {
Expand Down

0 comments on commit 9dc852a

Please sign in to comment.