@@ -29,13 +29,21 @@ describe('check and evaluate math', () => {
29
29
expect ( checkAndEvaluateMath ( { value : '4 * 7px * 8px' , type : 'dimension' } ) ) . to . equal ( '224px' ) ;
30
30
} ) ;
31
31
32
- it ( 'cannot evaluate math expressions where more than one token has a unit, when unit is not px' , ( ) => {
33
- expect ( checkAndEvaluateMath ( { value : '4em * 7em' , type : 'dimension' } ) ) . to . equal ( '4em * 7em' ) ;
34
- expect ( checkAndEvaluateMath ( { value : '4 * 7em * 8em' , type : 'dimension' } ) ) . to . equal (
35
- '4 * 7em * 8em' ,
36
- ) ;
37
- // exception for pixels, it strips px, making it 4 * 7em = 28em = 448px, where 4px * 7em would be 4px * 112px = 448px as well
32
+ it ( 'can evaluate math expressions where more than one token has a unit, assuming no mixed units are used' , ( ) => {
33
+ expect ( checkAndEvaluateMath ( { value : '4em + 7em' , type : 'dimension' } ) ) . to . equal ( '11em' ) ;
34
+ expect ( checkAndEvaluateMath ( { value : '4 + 7rem' , type : 'dimension' } ) ) . to . equal ( '4 + 7rem' ) ;
35
+ expect ( checkAndEvaluateMath ( { value : '4em + 7rem' , type : 'dimension' } ) ) . to . equal ( '4em + 7rem' ) ;
36
+ } ) ;
37
+
38
+ it ( 'can evaluate mixed units if operators are exclusively multiplication and the mix is px or unitless' , ( ) => {
39
+ expect ( checkAndEvaluateMath ( { value : '4 * 7em * 8em' , type : 'dimension' } ) ) . to . equal ( '224em' ) ;
38
40
expect ( checkAndEvaluateMath ( { value : '4px * 7em' , type : 'dimension' } ) ) . to . equal ( '28em' ) ;
41
+ // 50em would be incorrect when dividing, as em grows, result should shrink, but doesn't
42
+ expect ( checkAndEvaluateMath ( { value : '1000 / 20em' , type : 'dimension' } ) ) . to . equal (
43
+ '1000 / 20em' ,
44
+ ) ;
45
+ // cannot be expressed/resolved without knowing the value of em
46
+ expect ( checkAndEvaluateMath ( { value : '4px + 7em' , type : 'dimension' } ) ) . to . equal ( '4px + 7em' ) ;
39
47
} ) ;
40
48
41
49
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' , ( ) => {
0 commit comments