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
|
@use 'true' as *;
@use '../src/functions';
@include describe('functions') {
@include it('str-replace') {
$str: 'Hello world!';
@include assert-equal(functions.str-replace($str, 'world', 'neighbor'), 'Hello neighbor!', 'Replace "world" with "neighbor"');
@include assert-equal(functions.str-replace($str, 'neighbor', 'moon'), 'Hello world!', 'Replace "neighbor" with "moon"');
@include assert-equal(functions.str-replace($str, 'Hello', 'Bye'), 'Bye world!', 'Replace "Hello" with "Bye"');
}
@include it('list-slice') {
$list: 'this' 'is' 'a' 'list';
@include assert-equal(functions.list-slice($list, 2), 'is' 'a' 'list', 'Discard first item');
@include assert-equal(functions.list-slice($list, 1, 3), 'this' 'is' 'a', 'Keep first 3 items');
@include assert-equal(functions.list-slice($list, 2, 3), 'is' 'a', 'Extract list from index 2 to 3');
@include assert-equal(functions.list-slice($list, -1, -1), join((), 'list'), 'Keep last item');
@include assert-equal(functions.list-slice($list, -1, 1), 'list' 'this', 'Extract first and last item');
}
@include it('list-prepend') {
$list: 'this' 'is' 'a' 'list';
@include assert-equal(functions.list-prepend($list, 'and'), 'and' 'this' 'is' 'a' 'list', 'Prepend "and"');
@include assert-equal(functions.list-prepend($list, 2), 2 'this' 'is' 'a' 'list', 'Prepend 2');
}
@include it('quicksort') {
@include assert-equal(functions.quicksort(1 2 3 4 5), 1 2 3 4 5, 'Already sorted list of 5 items');
@include assert-equal(functions.quicksort(1 3 2), 1 2 3, 'Random list of 3 items');
@include assert-equal(functions.quicksort(6 3 7 3 8 1 4), 1 3 3 4 6 7 8, 'Random list of 7 items, one duplicate');
@include assert-equal(functions.quicksort(1 1 1 1), 1 1 1 1, 'List of 4 identical items');
}
@include it('map-get-default') {
$map: ('key': 'value', 'another': 'item');
@include assert-equal(functions.map-get-default($map, 'another', 0), map-get($map, 'another'), 'Get existing value');
@include assert-equal(functions.map-get-default($map, 'index', 'nothing'), 'nothing', 'Get missing value');
}
@include it('strip-unit') {
@include assert-true(unitless(functions.strip-unit(1em)), 'Remove unit from 1em');
@include assert-true(unitless(functions.strip-unit(2rem)), 'Remove unit from 2rem');
@include assert-true(unitless(functions.strip-unit(3px)), 'Remove unit from 3px');
@include assert-true(unitless(functions.strip-unit(4)), 'Remove unit from 4');
@include assert-true(unitless(functions.strip-unit(5pt)), 'Remove unit from 5pt');
}
@include it('px-to-rem') {
@include assert-equal(functions.px-to-rem(16px, 16px), 1rem, 'Convert 16px');
@include assert-equal(functions.px-to-rem(32px, 16px), 2rem, 'Convert 16px');
@include assert-equal(functions.px-to-rem(8px, 16px), 0.5rem, 'Convert 16px');
}
}
|