aboutsummaryrefslogtreecommitdiffstats
path: root/test/_props.scss
blob: 021ed4c6d31cf069e84dea7104d65325deada4e5 (plain) (blame)
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// sass-lint:disable empty-args

@include describe('Property trees') {
    @include it('Validate names') {
        $map-valid: (
            --background: #fff,
            --text:       #000,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                )
            )
        );

        $map-invalid: (
            --background: #fff,
            --text:       #000,
            --buttons: (
                --primary: (
                    background: #f00,
                    text:       #fff
                )
            )
        );

        @include assert-equal(iro-props-validate($map-valid),   true,  'Check valid map');
        @include assert-equal(iro-props-validate($map-invalid), false, 'Check invalid map');
    }

    @include it('Save / Delete') {
        $map: (
            --background: #fff,
            --text:       #000,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                )
            )
        );

        @include assert-equal(iro-props-store($map), null, 'Save default tree');
        @include assert-equal(iro-props-clear(),     null, 'Delete default tree');
    }

    @include it('Read') {
        $map1: (
            --background: #fff,
            --text:       #000,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                )
            )
        );

        $map2: (
            --background: #222,
            --text:       #fff,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                )
            )
        );

        $map3: (
            --background: #666,
            --text:       #222,
            --buttons: (
                --primary: (
                    --background: #0f0,
                    --text:       #000
                )
            )
        );

        @include assert-equal(iro-props-store($map1),         null,  'Save default tree');
        @include assert-equal(iro-props-store($map2, 'test'), null,  'Save "test" tree');

        @include iro-props-namespace('ns') {
            @include assert-equal(iro-props-store($map3, 'namespaced'), null,  'Save "namespaced" tree');
        }

        @include assert-equal(iro-props-get-static(--background),                     map-get($map1, --background),                                         'Get --background in default');
        @include assert-equal(iro-props-get-static(--buttons --primary --background), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get --buttons --primary --background in default');
        @include assert-equal(iro-props-get-static(--box, $default: false),           false,                                                                'Get nonexistent in default');

        @include assert-equal(iro-props-get-static(--background, 'test'),                     map-get($map2, --background),                                         'Get --background in "test"');
        @include assert-equal(iro-props-get-static(--buttons --primary --background, 'test'), map-get(map-get(map-get($map2, --buttons), --primary), --background), 'Get --buttons --primary --background in "test"');
        @include assert-equal(iro-props-get-static(--box, 'test', $default: false),           false,                                                                'Get nonexistent in "test"');
        
        @include assert-equal(iro-props-get-static(--background,      'namespaced', $default: false), false,                        'Get --background in "namespaced"');
        @include assert-equal(iro-props-get-static(--ns --background, 'namespaced'),                  map-get($map3, --background), 'Get --ns --background in "namespaced"');
        @include iro-props-namespace('ns') {
            @include assert-equal(iro-props-get-static(--background, 'namespaced'),                     map-get($map3, --background),                                         'Get namespaced --background in "namespaced"');
            @include assert-equal(iro-props-get-static(--buttons --primary --background, 'namespaced'), map-get(map-get(map-get($map3, --buttons), --primary), --background), 'Get namespaced --buttons --primary --background in "namespaced"');
            @include assert-equal(iro-props-get-static(--box, 'namespaced', $default: false),           false,                                                                'Get namespaced nonexistent in "namespaced"');
        }

        @include assert-equal(iro-props-clear(),             null, 'Delete default tree');
        @include assert-equal(iro-props-clear('test'),       null, 'Delete "test" tree');
        @include assert-equal(iro-props-clear('namespaced'), null, 'Delete "namespaced" tree');
    }

    @include it('Overwrite') {
        $map1: (
            --background: #fff,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                )
            )
        );

        $map2: (
            --background: #eee,
            --text:       #000,
            --buttons: (
                --primary: (
                    --background: #00f
                )
            )
        );

        @include assert-equal(iro-props-store($map1),               null, 'Save default tree');
        @include assert-equal(iro-props-store($map2, $merge: true), null, 'Overwrite default tree');

        @include assert-equal(iro-props-get-static(),                           iro-map-merge-recursive($map1, $map2),                          'After update, get whole map');
        @include assert-equal(iro-props-get-static(--background),               map-get($map2, --background),                                   'After update, get --background');
        @include assert-equal(iro-props-get-static(--text),                     map-get($map2, --text),                                         'After update, get --text');
        @include assert-equal(iro-props-get-static(--buttons --primary --text), map-get(map-get(map-get($map1, --buttons), --primary), --text), 'After update, get --buttons --primary --text');

        @include assert-equal(iro-props-clear(), null, 'Delete default tree');
    }

    @include it('Native assignment') {
        $map: (
            --background: #fff,
            --text:       #000,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                ),
                --default: (
                    --background: #ddd,
                    --text:       #000
                )
            )
        );

        @include assert('Simple') {
            @include iro-props-store($map);

            @include output {
                @include iro-props-assign;
            }

            @include expect {
                --background:                   #{map-get($map, --background)};
                --text:                         #{map-get($map, --text)};
                --buttons--primary--background: #{map-get(map-get(map-get($map, --buttons), --primary), --background)};
                --buttons--primary--text:       #{map-get(map-get(map-get($map, --buttons), --primary), --text)};
                --buttons--default--background: #{map-get(map-get(map-get($map, --buttons), --default), --background)};
                --buttons--default--text:       #{map-get(map-get(map-get($map, --buttons), --default), --text)};
            }

            @include iro-props-clear;
        }

        @include assert('Filtered') {
            @include iro-props-store($map);

            @include output {
                @include iro-props-assign($skip: --buttons);
            }

            @include expect {
                --background: #{map-get($map, --background)};
                --text:       #{map-get($map, --text)};
            }

            @include iro-props-clear;
        }

        @include assert('Namespaced') {
            @include iro-props-namespace('ns') {
                @include iro-props-store($map);
            }

            @include output {
                @include iro-props-assign;
            }

            @include expect {
                --ns--background:                   #{map-get($map, --background)};
                --ns--text:                         #{map-get($map, --text)};
                --ns--buttons--primary--background: #{map-get(map-get(map-get($map, --buttons), --primary), --background)};
                --ns--buttons--primary--text:       #{map-get(map-get(map-get($map, --buttons), --primary), --text)};
                --ns--buttons--default--background: #{map-get(map-get(map-get($map, --buttons), --default), --background)};
                --ns--buttons--default--text:       #{map-get(map-get(map-get($map, --buttons), --default), --text)};
            }

            @include iro-props-clear;
        }
    }

    @include it('Native get') {
        $map: (
            --background: #fff,
            --text:       #000,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                ),
                --default: (
                    --background: #ddd,
                    --text:       #000
                )
            )
        );

        @include assert-equal(iro-props-store($map), null, 'Save default tree');

        @include assert-equal(iro-props-get(--background),                                  var(--background),                      'Get --background');
        @include assert-equal(iro-props-get(--buttons --primary --text),                    var(--buttons--primary--text),          'Get --buttons --primary --text');
        @include assert-equal(iro-props-get(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default');
        @include iro-props-namespace('buttons') {
            @include assert-equal(iro-props-get(--primary --text),                    var(--buttons--primary--text),          'Get via namespace "buttons" --primary --text');
            @include assert-equal(iro-props-get(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default');
        }

        @include assert-equal(iro-props-clear(), null, 'Delete default tree');
    }

    @include it('References') {
        $map1: (
            --background: #fff,
            --text:       #000,
            --buttons: (
                --primary: (
                    --background: #f00,
                    --text:       #fff
                )
            )
        );

        $map2: (
            --background: #eee,
            --buttons: (
                --primary: (
                    --background: iro-props-ref($key: --background)
                ),
                --default: iro-props-ref($key: --buttons --primary)
            )
        );

        @include assert-equal(iro-props-store($map1),           null, 'Save default tree');
        @include assert-equal(iro-props-store($map2, 'second'), null, 'Save "second" tree');

        @include assert-equal(iro-props-get-static(--buttons --primary --background, 'second'), map-get($map1, --background),        'Get referenced value');
        @include assert-equal(iro-props-get(--buttons --primary --background, 'second'),        var(--buttons--primary--background), 'Get referenced value, native');

        @include assert-equal(iro-props-get-static(--buttons --default, 'second'),              map-get(map-get($map1, --buttons), --primary),                        'Get referenced subtree, whole');
        @include assert-equal(iro-props-get-static(--buttons --default --background, 'second'), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get referenced subtree, inner value');
        @include assert-equal(iro-props-get(--buttons --default --background, 'second'),        var(--buttons--default--background),                                  'Get referenced subtree, native');
        
        @include assert('Native assignment') {
            @include output {
                @include iro-props-assign('second');
            }

            @include expect {
                --background:                   #{map-get($map2, --background)};
                --buttons--primary--background: #{map-get($map1, --background)};
                --buttons--default--background: #{map-get(map-get(map-get($map1, --buttons), --primary), --background)};
                --buttons--default--text:       #{map-get(map-get(map-get($map1, --buttons), --primary), --text)};
            }
        }

        @include assert-equal(iro-props-clear(),         null, 'Delete default tree');
        @include assert-equal(iro-props-clear('second'), null, 'Delete "second" tree');
    }
}