-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
232 lines (210 loc) · 5.7 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import postcss from 'postcss';
import test from 'ava';
import textRemoveGap from './';
function run( tester, input, output, options = {} )
{
return postcss( [ textRemoveGap( options ) ] )
.process( input )
.then(
result =>
{
tester.deepEqual( result.css, output );
tester.deepEqual( result.warnings().length, 0 );
}
);
}
test(
'Regular selector',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif;}',
'p {font: 16px/2 "Arial", sans-serif;}'
)
);
test(
'Inside both',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: both;}',
`p {font: 16px/2 "Arial", sans-serif;}
p::before {display: table;content: "";margin-bottom: -0.63em;}
p::after {display: table;content: "";margin-top: -0.67em;}`
)
);
test(
'Inside before',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: before;}',
`p {font: 16px/2 "Arial", sans-serif;}
p::before {display: table;content: "";margin-bottom: -0.63em;}`
)
);
test(
'Inside after',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: after;}',
`p {font: 16px/2 "Arial", sans-serif;}
p::after {display: table;content: "";margin-top: -0.67em;}`
)
);
test(
'Outside both',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: outside both;}',
`p {font: 16px/2 "Arial", sans-serif; margin-top: -0.63em; margin-bottom: -0.67em;}`
)
);
test(
'Outside before',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: outside before;}',
`p {font: 16px/2 "Arial", sans-serif; margin-top: -0.63em;}`
)
);
test(
'Outside after',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: outside after;}',
`p {font: 16px/2 "Arial", sans-serif; margin-bottom: -0.67em;}`
)
);
test(
'Owerwrite font-family',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: both "Times New Roman";}',
`p {font: 16px/2 "Arial", sans-serif;}
p::before {display: table;content: "";margin-bottom: -0.67em;}
p::after {display: table;content: "";margin-top: -0.66em;}`
)
);
test(
'Owerwrite line-height',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: both 1.5;}',
`p {font: 16px/2 "Arial", sans-serif;}
p::before {display: table;content: "";margin-bottom: -0.38em;}
p::after {display: table;content: "";margin-top: -0.42em;}`
)
);
test(
'All settings',
tester => run(
tester,
'p {font: 16px/2 "Arial", sans-serif; text-remove-gap: outside both 1.5 "Times New Roman", serif;}',
`p {font: 16px/2 "Arial", sans-serif; margin-top: -0.42em; margin-bottom: -0.41em;}`
)
);
test(
'Separate font properties',
tester => run(
tester,
'p {font-family: "Arial", sans-serif; line-height: 2; text-remove-gap: both;}',
`p {font-family: "Arial", sans-serif; line-height: 2;}
p::before {display: table;content: "";margin-bottom: -0.63em;}
p::after {display: table;content: "";margin-top: -0.67em;}`
)
);
test(
'Line-height in pixels',
tester => run(
tester,
'p {font-family: "Arial", sans-serif; line-height: 24px; text-remove-gap: both;}',
`p {font-family: "Arial", sans-serif; line-height: 24px;}
p::before {display: table;content: "";margin-bottom: calc(-0.13em - (24px - 1em) / 2);}
p::after {display: table;content: "";margin-top: calc(-0.17em - (24px - 1em) / 2);}`
)
);
test(
'Only line-height',
tester => run(
tester,
'p {line-height: 2; text-remove-gap: both;}',
`p {line-height: 2;}
p::before {display: table;content: "";margin-bottom: -0.5em;}
p::after {display: table;content: "";margin-top: -0.5em;}`
)
);
test(
'No font settings',
tester => run(
tester,
'p {text-remove-gap: both;}',
`p {}`
)
);
test(
'Default font family',
tester => run(
tester,
'p {line-height: 2; text-remove-gap: both;}',
`p {line-height: 2;}
p::before {display: table;content: "";margin-bottom: -0.63em;}
p::after {display: table;content: "";margin-top: -0.67em;}`,
{defaultFontFamily: 'Arial'}
)
);
test(
'Default line height',
tester => run(
tester,
'p {font-family: "Arial", sans-serif; text-remove-gap: both;}',
`p {font-family: "Arial", sans-serif;}
p::before {display: table;content: "";margin-bottom: -0.63em;}
p::after {display: table;content: "";margin-top: -0.67em;}`,
{defaultLineHeight: 2}
)
);
test(
'Custom font',
tester => run(
tester,
'p {font-family: "_Some Very Custom Font_", sans-serif; text-remove-gap: both;}',
`p {font-family: "_Some Very Custom Font_", sans-serif;}
p::before {display: table;content: "";margin-bottom: -0.1em;}
p::after {display: table;content: "";margin-top: -0.2em;}`,
{fonts: {'_Some Very Custom Font_': [0.1, 0.2]}}
)
);
test(
'Unknown font',
tester => run(
tester,
'p {font-family: "_Some Unknown Font_"; text-remove-gap: both;}',
`p {font-family: "_Some Unknown Font_";}`
)
);
test(
'Unknown font with line-height',
tester => run(
tester,
'p {font: 16px/2 "_Some Unknown Font_"; text-remove-gap: both;}',
`p {font: 16px/2 "_Some Unknown Font_";}
p::before {display: table;content: "";margin-bottom: -0.5em;}
p::after {display: table;content: "";margin-top: -0.5em;}`
)
);
test(
'Two selectors',
tester => run(
tester,
'ul > li, ol > li {font: 16px/2 "Arial", sans-serif; text-remove-gap: both;}',
`ul > li, ol > li {font: 16px/2 "Arial", sans-serif;}
ul > li::before, ol > li::before {display: table;content: "";margin-bottom: -0.63em;}
ul > li::after, ol > li::after {display: table;content: "";margin-top: -0.67em;}`
)
);
test(
'Two selectors, outside',
tester => run(
tester,
'ul > li, ol > li {font: 16px/2 "Arial", sans-serif; text-remove-gap: outside both;}',
`ul > li, ol > li {font: 16px/2 "Arial", sans-serif; margin-top: -0.63em; margin-bottom: -0.67em;}`
)
);