diff --git a/test/unit/simplify/min-max.test.mjs b/test/unit/simplify/min-max.test.mjs index f2f37e3..a40a8b8 100644 --- a/test/unit/simplify/min-max.test.mjs +++ b/test/unit/simplify/min-max.test.mjs @@ -25,3 +25,10 @@ test('min with NaN propagates → calc(NaN)', () => { // Math.min(NaN, 5) is NaN (IEEE-754). assert.equal(out('min(NaN, 5)'), 'calc(NaN)'); }); + +test('min with subtraction', () => { + assert.equal( + out('min(360px, 100% - 24px - 24px)'), + 'min(360px, 100% - 48px)' + ); +}) diff --git a/test/unit/simplify/pow.test.mjs b/test/unit/simplify/pow.test.mjs index e3caf04..a93a33f 100644 --- a/test/unit/simplify/pow.test.mjs +++ b/test/unit/simplify/pow.test.mjs @@ -52,3 +52,7 @@ test('pow: wrong arity → opaque', () => { test('pow: case-insensitive', () => { assert.equal(out('POW(2, 3)'), out('pow(2, 3)')); }); + +test('reduces pow with multiplication', () =>{ + assert.equal(out('1rem * pow(1.618, 3)'), '4.2358rem'); +}) diff --git a/test/unit/simplify/reportedBugs.test.mjs b/test/unit/simplify/reportedBugs.test.mjs new file mode 100644 index 0000000..d33943e --- /dev/null +++ b/test/unit/simplify/reportedBugs.test.mjs @@ -0,0 +1,74 @@ +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { out } from '../../helpers/out.mjs'; + +test('does not output warnings', () => { + assert.equal( + out('calc(5.08lvh * var(--something))'), + 'calc(5.08lvh * var(--something))' + ); +}); + +test('multiple variable fallback', () => { + assert.equal( + out( + 'var(--width-lg, var(--width-md, var(--width-sm, 0))) + var(--offset-lg, var(--offset-md, var(--offset-sm, 0)))' + ), + 'calc(var(--width-lg, var(--width-md, var(--width-sm, 0))) + var(--offset-lg, var(--offset-md, var(--offset-sm, 0))))' + ); +}); + +test('converts nested vars', () => { + assert.equal( + out( + 'calc(\n' + + ' max(\n' + + ' var(1, var(2,3)), \n' + + ' var(4, var(5,6))\n' + + ' ) * 1)' + ), + 'max(var(1, var(2, 3)), var(4, var(5, 6)))' + ); +}); + +test('handles negative values at the end', () => { + assert.equal(out('calc(var(--my-var) * -1)'), 'calc(-1 * var(--my-var))'); +}); + +test('can minimize float with unknown unit', () => { + assert.equal(out('calc(120rpx - 41.7rpx)'), '78.3rpx'); +}); + +test('can minimize custom property and unknown unit', () => { + assert.equal( + out('var(--my-css-var) + -0.3cap'), + 'calc(-0.3cap + var(--my-css-var))' + ); +}); + +test('can minimize clamp and nested values', () => { + assert.equal( + out( + 'calc(\n' + + ' 1\n' + + ' * clamp(\n' + + ' 1 ,\n' + + ' ((1 * 1) * 1) ,\n' + + ' 1\n' + + ' )\n' + + ' )' + ), + '1' + ); +}); + +test('can minimize max and min with custom property', () => { + assert.equal( + out('calc(min(max(var(--foo), 0), 100))'), + 'min(max(var(--foo), 0), 100)' + ); +}); + +test('can minimize nested combination of custom properties and multiplication', () => { + assert.equal(out('calc(var(--b, calc(var(--c) * 1)))'), 'var(--b, var(--c))'); +});