Skip to content

Commit

Permalink
add test cases for @media+calc(), space toggles and relative colors (#70
Browse files Browse the repository at this point in the history
)

closes #69 
closes #68 
closes #67
  • Loading branch information
bartveneman authored Jun 12, 2024
1 parent f3d411b commit 623a26d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ function print_declaration(node, css, indent_level) {
value = value.replace(/\s*\/\s*/, '/')
}

// Hacky: add a space in case of a `space toggle` during minification
if (value === EMPTY_STRING && OPTIONAL_SPACE === EMPTY_STRING) {
value += SPACE
}

return indent(indent_level) + property + COLON + OPTIONAL_SPACE + value
}

Expand Down
8 changes: 8 additions & 0 deletions test/atrules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ test('@media prelude formatting', () => {
}
})

test.skip('calc() inside @media', () => {
let actual = format(`
@media (min-width: calc(300px* 3)) {}
`)
let expected = `@media (min-width: calc(300px * 3)) {}`
assert.equal(actual, expected)
})

test('@supports prelude formatting', () => {
let fixtures = [
[`@supports (display:grid){}`, `@supports (display: grid) {}`],
Expand Down
37 changes: 37 additions & 0 deletions test/values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ test('lowercases CSS functions', () => {
assert.is(actual, expected)
})

test('relative colors', () => {
let actual = format(`a {
color: rgb( from red 0 0 255);
color: rgb( from rgb( 200 0 0 ) r r r ) ;
color: hwb( from var( --base-color ) h w b / var( --standard-opacity ) ) ;
color: lch(from var(--base-color) calc(l + 20) c h);
}`)
let expected = `a {
color: rgb(from red 0 0 255);
color: rgb(from rgb(200 0 0) r r r);
color: hwb(from var(--base-color) h w b / var(--standard-opacity));
color: lch(from var(--base-color) calc(l + 20) c h);
}`
assert.is(actual, expected)
})

test('does not change casing of `NaN`', () => {
let actual = format(`a {
height: calc(1 * NaN);
Expand Down Expand Up @@ -223,4 +239,25 @@ test('formats unknown content in value', () => {
assert.is(actual, expected)
})

test('does not break space toggles', () => {
let actual = format(`a {
--ON: initial;
--OFF: ;
}`)
let expected = `a {
--ON: initial;
--OFF: ;
}`
assert.is(actual, expected)
})

test('does not break space toggles (minified)', () => {
let actual = format(`a {
--ON: initial;
--OFF: ;
}`, { minify: true })
let expected = `a{--ON:initial;--OFF: }`
assert.is(actual, expected)
})

test.run();

0 comments on commit 623a26d

Please sign in to comment.