diff options
Diffstat (limited to 'test/_props.scss')
-rw-r--r-- | test/_props.scss | 282 |
1 files changed, 282 insertions, 0 deletions
diff --git a/test/_props.scss b/test/_props.scss new file mode 100644 index 0000000..4e0a5b4 --- /dev/null +++ b/test/_props.scss | |||
@@ -0,0 +1,282 @@ | |||
1 | // sass-lint:disable empty-args | ||
2 | |||
3 | @include describe('Property trees') { | ||
4 | @include it('Validate names') { | ||
5 | $map-valid: ( | ||
6 | --background: #fff, | ||
7 | --text: #000, | ||
8 | --buttons: ( | ||
9 | --primary: ( | ||
10 | --background: #f00, | ||
11 | --text: #fff | ||
12 | ) | ||
13 | ) | ||
14 | ); | ||
15 | |||
16 | $map-invalid: ( | ||
17 | --background: #fff, | ||
18 | --text: #000, | ||
19 | --buttons: ( | ||
20 | --primary: ( | ||
21 | background: #f00, | ||
22 | text: #fff | ||
23 | ) | ||
24 | ) | ||
25 | ); | ||
26 | |||
27 | @include assert-equal(iro-props-validate($map-valid), true, 'Check valid map'); | ||
28 | @include assert-equal(iro-props-validate($map-invalid), false, 'Check invalid map'); | ||
29 | } | ||
30 | |||
31 | @include it('Save / Delete') { | ||
32 | $map: ( | ||
33 | --background: #fff, | ||
34 | --text: #000, | ||
35 | --buttons: ( | ||
36 | --primary: ( | ||
37 | --background: #f00, | ||
38 | --text: #fff | ||
39 | ), | ||
40 | --default: ( | ||
41 | --background: #ddd, | ||
42 | --text: #000 | ||
43 | ) | ||
44 | ) | ||
45 | ); | ||
46 | |||
47 | @include assert-equal(iro-props-save($map), null, 'Save default tree'); | ||
48 | @include assert-equal(iro-props-delete(), null, 'Delete default tree'); | ||
49 | } | ||
50 | |||
51 | @include it('Read') { | ||
52 | $map1: ( | ||
53 | --background: #fff, | ||
54 | --text: #000, | ||
55 | --buttons: ( | ||
56 | --primary: ( | ||
57 | --background: #f00, | ||
58 | --text: #fff | ||
59 | ), | ||
60 | --default: ( | ||
61 | --background: #ddd, | ||
62 | --text: #000 | ||
63 | ) | ||
64 | ) | ||
65 | ); | ||
66 | |||
67 | $map2: ( | ||
68 | --background: #222, | ||
69 | --text: #fff, | ||
70 | --buttons: ( | ||
71 | --primary: ( | ||
72 | --background: #f00, | ||
73 | --text: #fff | ||
74 | ), | ||
75 | --default: ( | ||
76 | --background: #444, | ||
77 | --text: #fff | ||
78 | ) | ||
79 | ) | ||
80 | ); | ||
81 | |||
82 | @include assert-equal(iro-props-save($map1), null, 'Save default tree'); | ||
83 | @include assert-equal(iro-props-save($map2, 'test'), null, 'Save "test" tree'); | ||
84 | |||
85 | @include assert-equal(iro-props-get(--background), map-get($map1, --background), 'Get --background in default'); | ||
86 | @include assert-equal(iro-props-get(--buttons --primary --background), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get --buttons --primary --background in default'); | ||
87 | @include assert-equal(iro-props-get(--buttons --default --text), map-get(map-get(map-get($map1, --buttons), --default), --text), 'Get --buttons --default --text in default'); | ||
88 | @include assert-equal(iro-props-get(--box, $default: false), false, 'Get nonexistent in default'); | ||
89 | |||
90 | @include assert-equal(iro-props-get(--background, 'test'), map-get($map2, --background), 'Get --background in "test"'); | ||
91 | @include assert-equal(iro-props-get(--buttons --primary --background, 'test'), map-get(map-get(map-get($map2, --buttons), --primary), --background), 'Get --buttons --primary --background in "test"'); | ||
92 | @include assert-equal(iro-props-get(--buttons --default --text, 'test'), map-get(map-get(map-get($map2, --buttons), --default), --text), 'Get --buttons --default --text in "test"'); | ||
93 | @include assert-equal(iro-props-get(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); | ||
94 | |||
95 | @include assert-equal(iro-props-delete(), null, 'Delete default tree'); | ||
96 | @include assert-equal(iro-props-delete('test'), null, 'Delete "test" tree'); | ||
97 | } | ||
98 | |||
99 | @include it('Overwrite') { | ||
100 | $map1: ( | ||
101 | --background: #fff, | ||
102 | --text: #000, | ||
103 | --buttons: ( | ||
104 | --primary: ( | ||
105 | --background: #f00, | ||
106 | --text: #fff | ||
107 | ) | ||
108 | ) | ||
109 | ); | ||
110 | |||
111 | $map2: ( | ||
112 | --background: #eee, | ||
113 | --buttons: ( | ||
114 | --primary: ( | ||
115 | --background: #00f | ||
116 | ), | ||
117 | --default: ( | ||
118 | --background: #444, | ||
119 | --text: #fff | ||
120 | ) | ||
121 | ) | ||
122 | ); | ||
123 | |||
124 | @include assert-equal(iro-props-save($map1), null, 'Save default tree'); | ||
125 | |||
126 | @include assert-equal(iro-props-get(), $map1, 'Before update, get whole map'); | ||
127 | @include assert-equal(iro-props-get(--background), map-get($map1, --background), 'Before update, get --background'); | ||
128 | @include assert-equal(iro-props-get(--text), map-get($map1, --text), 'Before update, get --text'); | ||
129 | @include assert-equal(iro-props-get(--buttons --primary --background), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Before update, get --buttons --primary --background'); | ||
130 | @include assert-equal(iro-props-get(--buttons --default --text, $default: false), false, 'Before update, get --buttons --default --text (returns default)'); | ||
131 | |||
132 | @include assert-equal(iro-props-save($map2, $merge: true), null, 'Overwrite default tree'); | ||
133 | |||
134 | @include assert-equal(iro-props-get(), iro-map-merge-recursive($map1, $map2), 'After update, get whole map'); | ||
135 | @include assert-equal(iro-props-get(--background), map-get($map2, --background), 'After update, get --background'); | ||
136 | @include assert-equal(iro-props-get(--text), map-get($map1, --text), 'After update, get --text'); | ||
137 | @include assert-equal(iro-props-get(--buttons --primary --background), map-get(map-get(map-get($map2, --buttons), --primary), --background), 'After update, get --buttons --primary --background'); | ||
138 | @include assert-equal(iro-props-get(--buttons --default --text), map-get(map-get(map-get($map2, --buttons), --default), --text), 'After update, get --buttons --default --text'); | ||
139 | |||
140 | @include assert-equal(iro-props-delete(), null, 'Delete default tree'); | ||
141 | } | ||
142 | |||
143 | @include it('Native assignment') { | ||
144 | @include assert('Simple') { | ||
145 | $map: ( | ||
146 | --background: #fff, | ||
147 | --text: #000, | ||
148 | --buttons: ( | ||
149 | --primary: ( | ||
150 | --background: #f00, | ||
151 | --text: #fff | ||
152 | ), | ||
153 | --default: ( | ||
154 | --background: #ddd, | ||
155 | --text: #000 | ||
156 | ) | ||
157 | ) | ||
158 | ); | ||
159 | |||
160 | @include iro-props-save($map); | ||
161 | |||
162 | @include output { | ||
163 | @include iro-props-assign-native; | ||
164 | } | ||
165 | |||
166 | @include expect { | ||
167 | --background: #{map-get($map, --background)}; | ||
168 | --text: #{map-get($map, --text)}; | ||
169 | --buttons--primary--background: #{map-get(map-get(map-get($map, --buttons), --primary), --background)}; | ||
170 | --buttons--primary--text: #{map-get(map-get(map-get($map, --buttons), --primary), --text)}; | ||
171 | --buttons--default--background: #{map-get(map-get(map-get($map, --buttons), --default), --background)}; | ||
172 | --buttons--default--text: #{map-get(map-get(map-get($map, --buttons), --default), --text)}; | ||
173 | } | ||
174 | |||
175 | @include iro-props-delete; | ||
176 | } | ||
177 | |||
178 | @include assert('Filtered') { | ||
179 | $map: ( | ||
180 | --background: #fff, | ||
181 | --text: #000, | ||
182 | --buttons: ( | ||
183 | --primary: ( | ||
184 | --background: #f00, | ||
185 | --text: #fff | ||
186 | ), | ||
187 | --default: ( | ||
188 | --background: #ddd, | ||
189 | --text: #000 | ||
190 | ) | ||
191 | ) | ||
192 | ); | ||
193 | |||
194 | @include iro-props-save($map); | ||
195 | |||
196 | @include output { | ||
197 | @include iro-props-assign-native($skip: --buttons); | ||
198 | } | ||
199 | |||
200 | @include expect { | ||
201 | --background: #{map-get($map, --background)}; | ||
202 | --text: #{map-get($map, --text)}; | ||
203 | } | ||
204 | |||
205 | @include iro-props-delete; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | @include it('Native get') { | ||
210 | $map: ( | ||
211 | --background: #fff, | ||
212 | --text: #000, | ||
213 | --buttons: ( | ||
214 | --primary: ( | ||
215 | --background: #f00, | ||
216 | --text: #fff | ||
217 | ), | ||
218 | --default: ( | ||
219 | --background: #ddd, | ||
220 | --text: #000 | ||
221 | ) | ||
222 | ) | ||
223 | ); | ||
224 | |||
225 | @include assert-equal(iro-props-save($map), null, 'Save default tree'); | ||
226 | |||
227 | @include assert-equal(iro-props-get-native(--background), var(--background), 'Get --background'); | ||
228 | @include assert-equal(iro-props-get-native(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); | ||
229 | @include assert-equal(iro-props-get-native(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default'); | ||
230 | |||
231 | @include assert-equal(iro-props-delete(), null, 'Delete default tree'); | ||
232 | } | ||
233 | |||
234 | @include it('References') { | ||
235 | $map1: ( | ||
236 | --background: #fff, | ||
237 | --text: #000, | ||
238 | --buttons: ( | ||
239 | --primary: ( | ||
240 | --background: #f00, | ||
241 | --text: #fff | ||
242 | ) | ||
243 | ) | ||
244 | ); | ||
245 | |||
246 | $map2: ( | ||
247 | --background: #eee, | ||
248 | --buttons: ( | ||
249 | --primary: ( | ||
250 | --background: iro-props-ref($key: --background) | ||
251 | ), | ||
252 | --default: iro-props-ref($key: --buttons --primary) | ||
253 | ) | ||
254 | ); | ||
255 | |||
256 | @include assert-equal(iro-props-save($map1), null, 'Save default tree'); | ||
257 | @include assert-equal(iro-props-save($map2, 'second'), null, 'Save "second" tree'); | ||
258 | |||
259 | @include assert-equal(iro-props-get(--buttons --primary --background, 'second'), map-get($map1, --background), 'Get referenced value'); | ||
260 | @include assert-equal(iro-props-get-native(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); | ||
261 | |||
262 | @include assert-equal(iro-props-get(--buttons --default, 'second'), map-get(map-get($map1, --buttons), --primary), 'Get referenced subtree, whole'); | ||
263 | @include assert-equal(iro-props-get(--buttons --default --background, 'second'), map-get(map-get(map-get($map1, --buttons), --primary), --background), 'Get referenced subtree, inner value'); | ||
264 | @include assert-equal(iro-props-get-native(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); | ||
265 | |||
266 | @include assert('Native assignment') { | ||
267 | @include output { | ||
268 | @include iro-props-assign-native('second'); | ||
269 | } | ||
270 | |||
271 | @include expect { | ||
272 | --background: #{map-get($map2, --background)}; | ||
273 | --buttons--primary--background: #{map-get($map1, --background)}; | ||
274 | --buttons--default--background: #{map-get(map-get(map-get($map1, --buttons), --primary), --background)}; | ||
275 | --buttons--default--text: #{map-get(map-get(map-get($map1, --buttons), --primary), --text)}; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | @include assert-equal(iro-props-delete(), null, 'Delete default tree'); | ||
280 | @include assert-equal(iro-props-delete('second'), null, 'Delete "second" tree'); | ||
281 | } | ||
282 | } | ||