From 623a26dbc694fd987132850ff8d9b1da4dcc82f4 Mon Sep 17 00:00:00 2001 From: Bart Veneman <1536852+bartveneman@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:34:18 +0200 Subject: [PATCH] add test cases for @media+calc(), space toggles and relative colors (#70) closes #69 closes #68 closes #67 --- index.js | 5 +++++ test/atrules.test.js | 8 ++++++++ test/values.test.js | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/index.js b/index.js index 772dfe7..0ff854d 100644 --- a/index.js +++ b/index.js @@ -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 } diff --git a/test/atrules.test.js b/test/atrules.test.js index 32ed99b..311d987 100644 --- a/test/atrules.test.js +++ b/test/atrules.test.js @@ -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) {}`], diff --git a/test/values.test.js b/test/values.test.js index dcc21a7..ecd91ef 100644 --- a/test/values.test.js +++ b/test/values.test.js @@ -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); @@ -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();