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