Skip to content

Commit

Permalink
add tests for unknown syntax in rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Veneman committed Jun 2, 2024
1 parent fa78a2b commit 26d7717
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ function print_selectorlist(node, css, indent_level) {
children.forEach((selector, item) => {
if (selector.type === TYPE_SELECTOR) {
buffer += print_selector(selector, css, indent_level)
} else {
buffer += print_unknown(selector, css, indent_level)
}

if (item.next !== null) {
Expand Down Expand Up @@ -231,16 +229,16 @@ function print_selector(node, css, indent_level) {
function print_block(node, css, indent_level) {
let children = node.children
let buffer = OPTIONAL_SPACE
let only_raw = true
// let only_raw = true

for (let child of children) {
if (child.type !== 'Raw') {
only_raw = false
break
}
}
// for (let child of children) {
// if (child.type !== 'Raw') {
// only_raw = false
// break
// }
// }

if (children.isEmpty || only_raw) {
if (children.isEmpty) {
return buffer + '{}'
}

Expand All @@ -266,6 +264,8 @@ function print_block(node, css, indent_level) {
buffer += print_rule(child, css, indent_level)
} else if (child.type === TYPE_ATRULE) {
buffer += print_atrule(child, css, indent_level)
} else {
buffer += print_unknown(child, css, indent_level)
}
}

Expand Down
46 changes: 44 additions & 2 deletions test/rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,30 @@ test("formats nested rules with a selector starting with &", () => {
assert.equal(actual, expected);
})

test.only('formats unknown stuff in curly braces', () => {
test('formats unknown stuff in curly braces', () => {
let actual = format(`
selector {
{ color: red; }
}
`)
let expected = `selector {}`;
let expected = `selector {
{ color: red; }
}`;
assert.is(actual, expected);
})

test("[check broken test] Relaxed nesting: formats nested rules with a selector with a &", () => {
let actual = format(`
selector {
a & { color:red }
}
`)
let expected = `selector {
a & { color:red }
}`;
assert.equal(actual, expected);
})

test.skip("Relaxed nesting: formats nested rules with a selector with a &", () => {
let actual = format(`
selector {
Expand All @@ -203,6 +217,18 @@ test.skip("Relaxed nesting: formats nested rules with a selector with a &", () =
assert.equal(actual, expected);
})

test("[check broken test] Relaxed nesting: formats nested rules with a selector without a &", () => {
let actual = format(`
selector {
a { color:red }
}
`)
let expected = `selector {
a { color:red }
}`;
assert.equal(actual, expected);
})

test.skip("Relaxed nesting: formats nested rules with a selector without a &", () => {
let actual = format(`
selector {
Expand All @@ -217,6 +243,22 @@ test.skip("Relaxed nesting: formats nested rules with a selector without a &", (
assert.equal(actual, expected);
})

test("[check broken test] Relaxed nesting: formats nested rules with a selector starting with a selector combinator", () => {
let actual = format(`
selector {
> a { color:red }
~ a { color:red }
+ a { color:red }
}
`)
let expected = `selector {
> a { color:red }
~ a { color:red }
+ a { color:red }
}`;
assert.equal(actual, expected);
})

test.skip("Relaxed nesting: formats nested rules with a selector starting with a selector combinator", () => {
let actual = format(`
selector {
Expand Down

0 comments on commit 26d7717

Please sign in to comment.