1
+ 'use strict' ;
2
+
3
+ var _ava = require ( 'ava' ) ;
4
+
5
+ var _ava2 = _interopRequireDefault ( _ava ) ;
6
+
7
+ var _ = require ( '..' ) ;
8
+
9
+ var _2 = _interopRequireDefault ( _ ) ;
10
+
11
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
12
+
13
+ function testFixture ( t , fixture ) {
14
+ var expected = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : null ;
15
+ var precision = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : 5 ;
16
+
17
+ if ( expected === null ) expected = fixture ;
18
+
19
+ var out = ( 0 , _2 . default ) ( fixture , precision ) ;
20
+ t . deepEqual ( out , expected ) ;
21
+ }
22
+
23
+ function testThrows ( t , fixture , expected ) {
24
+ var precision = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : 5 ;
25
+
26
+ t . throws ( function ( ) {
27
+ return ( 0 , _2 . default ) ( fixture , precision ) ;
28
+ } , expected ) ;
29
+ }
30
+
31
+ ( 0 , _ava2 . default ) ( 'should reduce simple calc (1)' , testFixture , 'calc(1px + 1px)' , '2px' ) ;
32
+
33
+ ( 0 , _ava2 . default ) ( 'should reduce simple calc (2)' , testFixture , 'calc(3em - 1em)' , '2em' ) ;
34
+
35
+ ( 0 , _ava2 . default ) ( 'should reduce simple calc (3)' , testFixture , 'calc(1rem * 1.5)' , '1.5rem' ) ;
36
+
37
+ ( 0 , _ava2 . default ) ( 'should reduce simple calc (4)' , testFixture , 'calc(2ex / 2)' , '1ex' ) ;
38
+
39
+ ( 0 , _ava2 . default ) ( 'should ignore value surrounding calc function (1)' , testFixture , 'a calc(1px + 1px)' , 'a 2px' ) ;
40
+
41
+ ( 0 , _ava2 . default ) ( 'should ignore value surrounding calc function (2)' , testFixture , 'calc(1px + 1px) a' , '2px a' ) ;
42
+
43
+ ( 0 , _ava2 . default ) ( 'should ignore value surrounding calc function (3)' , testFixture , 'a calc(1px + 1px) b' , 'a 2px b' ) ;
44
+
45
+ ( 0 , _ava2 . default ) ( 'should ignore value surrounding calc function (4)' , testFixture , 'a calc(1px + 1px) b calc(1em + 2em) c' , 'a 2px b 3em c' ) ;
46
+
47
+ ( 0 , _ava2 . default ) ( 'should reduce calc with newline characters' , testFixture , 'calc(\n1rem \n* 2 \n* 1.5)' , '3rem' ) ;
48
+
49
+ ( 0 , _ava2 . default ) ( 'should preserve calc with incompatible units' , testFixture , 'calc(100% + 1px)' , 'calc(100% + 1px)' ) ;
50
+
51
+ ( 0 , _ava2 . default ) ( 'should parse fractions without leading zero' , testFixture , 'calc(2rem - .14285em)' , 'calc(2rem - 0.14285em)' ) ;
52
+
53
+ ( 0 , _ava2 . default ) ( 'should handle precision correctly (1)' , testFixture , 'calc(1/100)' , '0.01' ) ;
54
+
55
+ ( 0 , _ava2 . default ) ( 'should handle precision correctly (2)' , testFixture , 'calc(5/1000000)' , '0.00001' ) ;
56
+
57
+ ( 0 , _ava2 . default ) ( 'should handle precision correctly (3)' , testFixture , 'calc(5/1000000)' , '0.000005' , 6 ) ;
58
+
59
+ ( 0 , _ava2 . default ) ( 'should reduce browser-prefixed calc (1)' , testFixture , '-webkit-calc(1px + 1px)' , '2px' ) ;
60
+
61
+ ( 0 , _ava2 . default ) ( 'should reduce browser-prefixed calc (2)' , testFixture , '-moz-calc(1px + 1px)' , '2px' ) ;
62
+
63
+ ( 0 , _ava2 . default ) ( 'should discard zero values (#2) (1)' , testFixture , 'calc(100vw / 2 - 6px + 0px)' , 'calc(50vw - 6px)' ) ;
64
+
65
+ ( 0 , _ava2 . default ) ( 'should discard zero values (#2) (2)' , testFixture , 'calc(500px - 0px)' , '500px' ) ;
66
+
67
+ ( 0 , _ava2 . default ) ( 'should not perform addition on unitless values (#3)' , testFixture , 'calc(1px + 1)' , 'calc(1px + 1)' ) ;
68
+
69
+ ( 0 , _ava2 . default ) ( 'should produce simpler result (postcss-calc#25) (1)' , testFixture , 'calc(14px + 6 * ((100vw - 320px) / 448))' , 'calc(9.71px + 1.34vw)' , 2 ) ;
70
+
71
+ ( 0 , _ava2 . default ) ( 'should produce simpler result (postcss-calc#25) (2)' , testFixture , '-webkit-calc(14px + 6 * ((100vw - 320px) / 448))' , '-webkit-calc(9.71px + 1.34vw)' , 2 ) ;
72
+
73
+ ( 0 , _ava2 . default ) ( 'should reduce mixed units of time (postcss-calc#33)' , testFixture , 'calc(1s - 50ms)' , '0.95s' ) ;
74
+
75
+ ( 0 , _ava2 . default ) ( 'should correctly reduce calc with mixed units (cssnano#211)' , testFixture , 'bar:calc(99.99% * 1/1 - 0rem)' , 'bar:99.99%' ) ;
76
+
77
+ ( 0 , _ava2 . default ) ( 'should apply algebraic reduction (cssnano#319)' , testFixture , 'bar:calc((100px - 1em) + (-50px + 1em))' , 'bar:50px' ) ;
78
+
79
+ ( 0 , _ava2 . default ) ( 'should apply optimization (cssnano#320)' , testFixture , 'bar:calc(50% + (5em + 5%))' , 'bar:calc(55% + 5em)' ) ;
80
+
81
+ ( 0 , _ava2 . default ) ( 'should throw an exception when attempting to divide by zero' , testThrows , 'calc(500px/0)' , / C a n n o t d i v i d e b y z e r o / ) ;
82
+
83
+ ( 0 , _ava2 . default ) ( 'should throw an exception when attempting to divide by unit' , testThrows , 'calc(500px/2px)' , 'Cannot divide by "px", number expected' ) ;
0 commit comments