• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var chai = require('chai')
2var sinon = require('sinon')
3var sinonChai = require('sinon-chai')
4var expect = chai.expect
5chai.use(sinonChai)
6
7var shorthandParser = require('../lib/shorthand-parser')
8
9describe('shorthand-parser', function () {
10  it('parse transition', function () {
11    var declarations = [
12      {
13        type: 'declaration',
14        property: 'transition',
15        value: 'margin-top 500ms ease-in-out 1s',
16        position: {}
17      }
18    ]
19    var result = shorthandParser(declarations)
20    expect(result).eql([
21      {
22        type: 'declaration',
23        property: 'transition-property',
24        value: 'margin-top',
25        position: {}
26      },
27      {
28        type: 'declaration',
29        property: 'transition-duration',
30        value: '500ms',
31        position: {}
32      },
33      {
34        type: 'declaration',
35        property: 'transition-timing-function',
36        value: 'ease-in-out',
37        position: {}
38      },
39      {
40        type: 'declaration',
41        property: 'transition-delay',
42        value: '1s',
43        position: {}
44      }
45    ])
46  })
47
48  it('parse margin', function () {
49    var declarations = [
50      {
51        type: 'declaration',
52        property: 'margin',
53        value: '1px',
54        position: {}
55      },
56      {
57        type: 'declaration',
58        property: 'margin',
59        value: '21px 22px',
60        position: {}
61      },
62      {
63        type: 'declaration',
64        property: 'margin',
65        value: '31px 32px 33px',
66        position: {}
67      },
68      {
69        type: 'declaration',
70        property: 'margin',
71        value: '41px 42px 43px 44px',
72        position: {}
73      }
74    ]
75    var result = shorthandParser(declarations)
76    expect(result).eql([
77      {
78        type: 'declaration',
79        property: 'margin-top',
80        value: '1px',
81        position: {}
82      },
83      {
84        type: 'declaration',
85        property: 'margin-right',
86        value: '1px',
87        position: {}
88      },
89      {
90        type: 'declaration',
91        property: 'margin-bottom',
92        value: '1px',
93        position: {}
94      },
95      {
96        type: 'declaration',
97        property: 'margin-left',
98        value: '1px',
99        position: {}
100      },
101
102      {
103        type: 'declaration',
104        property: 'margin-top',
105        value: '21px',
106        position: {}
107      },
108      {
109        type: 'declaration',
110        property: 'margin-right',
111        value: '22px',
112        position: {}
113      },
114      {
115        type: 'declaration',
116        property: 'margin-bottom',
117        value: '21px',
118        position: {}
119      },
120      {
121        type: 'declaration',
122        property: 'margin-left',
123        value: '22px',
124        position: {}
125      },
126
127      {
128        type: 'declaration',
129        property: 'margin-top',
130        value: '31px',
131        position: {}
132      },
133      {
134        type: 'declaration',
135        property: 'margin-right',
136        value: '32px',
137        position: {}
138      },
139      {
140        type: 'declaration',
141        property: 'margin-bottom',
142        value: '33px',
143        position: {}
144      },
145      {
146        type: 'declaration',
147        property: 'margin-left',
148        value: '32px',
149        position: {}
150      },
151
152      {
153        type: 'declaration',
154        property: 'margin-top',
155        value: '41px',
156        position: {}
157      },
158      {
159        type: 'declaration',
160        property: 'margin-right',
161        value: '42px',
162        position: {}
163      },
164      {
165        type: 'declaration',
166        property: 'margin-bottom',
167        value: '43px',
168        position: {}
169      },
170      {
171        type: 'declaration',
172        property: 'margin-left',
173        value: '44px',
174        position: {}
175      }
176    ])
177  })
178})
179