1 |
|
2 | @use '../test_base' as *;
|
3 | @use '../../src/internal/functions';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | @include describe('hex-to-rgb()') {
|
9 | @include it('should return corresponding rgb color given a hex color') {
|
10 | @include assert-equal(functions.hex-to-rgb(#fff), (255, 255, 255));
|
11 | }
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | @include describe('hex-to-rgb()') {
|
18 | @include it('should return a string surrounded by the delimiter "-"') {
|
19 | @include assert-equal(functions.delimitize('opacity'), '-opacity-');
|
20 | }
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | @include describe('string-split()') {
|
27 | @include it('should return input string split using delimiter ","') {
|
28 | @include assert-equal(functions.string-split('apples,oranges,bananas', ','), ('apples' 'oranges' 'bananas'));
|
29 | }
|
30 | @include it('should return input string split using delimiter "123"') {
|
31 | @include assert-equal(functions.string-split('abc123def', '123'), ('abc' 'def'));
|
32 | }
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | @include describe('map-get-deep()') {
|
39 | @include it('should return value for key "foo" which is nested 1 level deep') {
|
40 | @include assert-equal(
|
41 | functions.map-get-deep(
|
42 | (
|
43 | foo: bar,
|
44 | ),
|
45 | 'foo'
|
46 | ),
|
47 | 'bar'
|
48 | );
|
49 | }
|
50 | @include it('should return value for key "a.b.c" which is nested 2 levels deep') {
|
51 | @include assert-equal(
|
52 | functions.map-get-deep(
|
53 | (
|
54 | a: (
|
55 | b: (
|
56 | c: 1,
|
57 | ),
|
58 | ),
|
59 | ),
|
60 | 'a.b.c'
|
61 | ),
|
62 | 1
|
63 | );
|
64 | }
|
65 | @include it('should throw error if key does not exist') {
|
66 | @include assert-equal(
|
67 | functions.map-get-deep(
|
68 | (
|
69 | a: (
|
70 | b: (
|
71 | c: 1,
|
72 | ),
|
73 | ),
|
74 | ),
|
75 | 'a.d'
|
76 | ),
|
77 | build-true-error-string('map-get-strict()', 'ERROR: Specified key "d" does not exist in the mapping')
|
78 | );
|
79 | }
|
80 | }
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | @include describe('map-get-strict()') {
|
86 | @include it('should return value for key "foo"') {
|
87 | @include assert-equal(
|
88 | functions.map-get-strict(
|
89 | (
|
90 | foo: bar,
|
91 | ),
|
92 | 'foo'
|
93 | ),
|
94 | 'bar'
|
95 | );
|
96 | }
|
97 | @include it('should throw error if key does not exist') {
|
98 | @include assert-equal(
|
99 | functions.map-get-strict(
|
100 | (
|
101 | foo: bar,
|
102 | ),
|
103 | 'baz'
|
104 | ),
|
105 | build-true-error-string('map-get-strict()', 'ERROR: Specified key "baz" does not exist in the mapping')
|
106 | );
|
107 | }
|
108 | }
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | @include describe('get-with-extend()') {
|
114 | @include it('should return default settings for opacity if extend.opacity is empty.') {
|
115 | @include assert-equal(
|
116 | functions.get-with-extend(
|
117 | (
|
118 | opacity: (
|
119 | 0: 0,
|
120 | 100: 1,
|
121 | ),
|
122 | extend: (
|
123 | opacity: (),
|
124 | ),
|
125 | ),
|
126 | opacity
|
127 | ),
|
128 | (
|
129 | 0: 0,
|
130 | 100: 1,
|
131 | )
|
132 | );
|
133 | }
|
134 | @include it(
|
135 | 'should return extended settings for opacity if config.opacity is set to null and extended settings is not null.'
|
136 | ) {
|
137 | @include assert-equal(
|
138 | functions.get-with-extend(
|
139 | (
|
140 | opacity: null,
|
141 | extend: (
|
142 | opacity: (
|
143 | 50: 0.5,
|
144 | ),
|
145 | ),
|
146 | ),
|
147 | opacity
|
148 | ),
|
149 | (
|
150 | 50: 0.5,
|
151 | )
|
152 | );
|
153 | }
|
154 | @include it('should return merged original and extended settings if both are not null.') {
|
155 | @include assert-equal(
|
156 | functions.get-with-extend(
|
157 | (
|
158 | opacity: (
|
159 | 0: 0,
|
160 | 100: 1,
|
161 | ),
|
162 | extend: (
|
163 | opacity: (
|
164 | 50: 0.5,
|
165 | ),
|
166 | ),
|
167 | ),
|
168 | opacity
|
169 | ),
|
170 | (
|
171 | 0: 0,
|
172 | 50: 0.5,
|
173 | 100: 1,
|
174 | )
|
175 | );
|
176 | }
|
177 | @include it('should return empty list if original and extended are null and empty (default) respectively.') {
|
178 | @include assert-equal(
|
179 | functions.get-with-extend(
|
180 | (
|
181 | opacity: null,
|
182 | extend: (
|
183 | opacity: (),
|
184 | ),
|
185 | ),
|
186 | opacity
|
187 | ),
|
188 | ()
|
189 | );
|
190 | }
|
191 | }
|
192 |
|
193 |
|
194 |
|
195 |
|
196 | @include describe('to-property-map()') {
|
197 | @include it('should return mapping when given a valid list of properties') {
|
198 | @include assert-equal(
|
199 | functions.to-property-map((left, right, both)),
|
200 | (
|
201 | left: left,
|
202 | right: right,
|
203 | both: both,
|
204 | )
|
205 | );
|
206 | }
|
207 | }
|
208 |
|
209 |
|
210 |
|
211 |
|
212 | @include describe('get-negative-value-map()') {
|
213 | @include it('should return mapping negated classes when given class mapping of numeric values') {
|
214 | @include assert-equal(
|
215 | functions.get-negative-value-map(
|
216 | (
|
217 | 0: 0rem,
|
218 | 1: 0.5px,
|
219 | 2: 1em,
|
220 | 3: 1.5,
|
221 | )
|
222 | ),
|
223 | (
|
224 | 0: 0rem,
|
225 | 1: 0.5px,
|
226 | n1: -0.5px,
|
227 | 2: 1em,
|
228 | n2: -1em,
|
229 | 3: 1.5,
|
230 | n3: -1.5,
|
231 | ),
|
232 | // Test fails without this
|
233 | $inspect: true
|
234 | );
|
235 | }
|
236 |
|
237 | @include it('should skip creating negative mapping for non-numerical values') {
|
238 | @include assert-equal(
|
239 | functions.get-negative-value-map(
|
240 | (
|
241 | auto: auto,
|
242 | inherit: inherit,
|
243 | unset: unset,
|
244 | 5: 5px,
|
245 | )
|
246 | ),
|
247 | (
|
248 | auto: auto,
|
249 | inherit: inherit,
|
250 | unset: unset,
|
251 | 5: 5px,
|
252 | n5: -5px,
|
253 | ),
|
254 | // Test fails without this
|
255 | $inspect: true
|
256 | );
|
257 | }
|
258 |
|
259 | @include it('should skip creating negative mapping for classes with 0 value') {
|
260 | @include assert-equal(
|
261 | functions.get-negative-value-map(
|
262 | (
|
263 | 0: 0,
|
264 | zero: 0px,
|
265 | )
|
266 | ),
|
267 | (
|
268 | 0: 0,
|
269 | zero: 0px,
|
270 | )
|
271 | );
|
272 | }
|
273 | }
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | @include describe('strip-unit()') {
|
279 | @include it('should return number without unit for numerical inputs') {
|
280 | @include assert-equal(functions.strip-unit(42rem), 42);
|
281 | @include assert-equal(functions.strip-unit(42em), 42);
|
282 | @include assert-equal(functions.strip-unit(42px), 42);
|
283 | @include assert-equal(functions.strip-unit(42), 42);
|
284 | }
|
285 |
|
286 | @include it('should return same input if not numerical') {
|
287 | @include assert-equal(functions.strip-unit(auto), auto);
|
288 | }
|
289 | }
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | @include describe('map-multi-merge()') {
|
295 | @include it('should return merged map if we pass in multiple maps as inputs') {
|
296 | @include assert-equal(
|
297 | functions.map-multi-merge(
|
298 | (
|
299 | 1: 1,
|
300 | ),
|
301 | (
|
302 | 2: 2,
|
303 | 3: 3,
|
304 | ),
|
305 | (
|
306 | 4: 4,
|
307 | ),
|
308 | (
|
309 | 5: 5,
|
310 | )
|
311 | ),
|
312 | (
|
313 | 1: 1,
|
314 | 2: 2,
|
315 | 3: 3,
|
316 | 4: 4,
|
317 | 5: 5,
|
318 | )
|
319 | );
|
320 | }
|
321 | }
|
322 |
|
323 |
|
324 |
|
325 |
|
326 | @include describe('map-range()') {
|
327 | @include it('should return map with numbers only in between given start and end values') {
|
328 | @include assert-equal(
|
329 | functions.map-range(
|
330 | (
|
331 | 1: 42,
|
332 | 2: 42,
|
333 | 3: 42,
|
334 | 4: 42,
|
335 | 5: 42,
|
336 | 6: 42,
|
337 | 7: 42,
|
338 | 8: 42,
|
339 | ),
|
340 | 2,
|
341 | 6
|
342 | ),
|
343 | (
|
344 | 2: 42,
|
345 | 3: 42,
|
346 | 4: 42,
|
347 | 5: 42,
|
348 | )
|
349 | );
|
350 | }
|
351 | }
|