Skip to content

Commit

Permalink
chore: add tests for more advanced math expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema committed May 13, 2024
1 parent 4bf595f commit 2d26dff
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions test/spec/checkAndEvaluateMath.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@ describe('check and evaluate math', () => {
// we can strip the unit, do the calculation, and add back the unit.
// However, there's not really a good way to do calculations with mixed units,
// e.g. 2em * 4rem is not possible
it.skip('can evaluate math expressions where more than one token has a unit, as long as for each piece of the expression the unit is the same', () => {
expect(checkAndEvaluateMath('4em * 7em')).to.equal('28em');
expect(checkAndEvaluateMath('4pt * 7pt * 8pt')).to.equal('228pt');
expect(checkAndEvaluateMath('4pt * 10vw * 8pt')).to.equal('4pt * 10vw * 8pt');
it('can evaluate math expressions where more than one token has a unit, as long as for each piece of the expression the unit is the same', () => {
// can resolve them, because all values share the same unit
// TODO: implement tests below, failing atm
expect(checkAndEvaluateMath('5rem * 4rem / 2rem')).to.equal('10rem'); // current: '5rem * 4rem / 2rem'
expect(checkAndEvaluateMath('10vw + 20vw')).to.equal('10vw'); // current: '10vw + 20vw'

// cannot resolve them, because em is dynamic and 20/20px is static value
expect(checkAndEvaluateMath('2em + 20')).to.equal('2em + 20');
expect(checkAndEvaluateMath('2em + 20px')).to.equal('2em + 20px');

// can resolve them, because multiplying by pixels/unitless is possible, regardless of the other value's unit
expect(checkAndEvaluateMath('2pt * 4')).to.equal('8pt');
expect(checkAndEvaluateMath('2em * 20px')).to.equal('40em');
});

it('supports multi-value expressions with math expressions', () => {
Expand Down

0 comments on commit 2d26dff

Please sign in to comment.