From f0f84513f8efe533b6ee670a6f1a0c074387b2ec Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 13 Aug 2025 12:01:46 +0200 Subject: Make use of SASS modules --- test/_props.scss | 565 ++++++++++++++++++++++++++----------------------------- 1 file changed, 269 insertions(+), 296 deletions(-) (limited to 'test/_props.scss') 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 @@ @use '../src/props'; @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(props.validate($map-valid), true, 'Check valid map'); - @include assert-equal(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(props.store($map), null, 'Save default tree'); - @include assert-equal(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(props.store($map1), null, 'Save default tree'); - @include assert-equal(props.store($map2, 'test'), null, 'Save "test" tree'); - - @include props.namespace('ns') { - @include assert-equal(props.store($map3, 'namespaced'), null, 'Save "namespaced" tree'); - } - - @include assert-equal(props.get-static(--background), map-get($map1, --background), 'Get --background in default'); - @include assert-equal(props.get-static(--buttons --primary --background), map-get($map1, --buttons, --primary, --background), 'Get --buttons --primary --background in default'); - @include assert-equal(props.get-static(--box, $default: false), false, 'Get nonexistent in default'); - - @include assert-equal(props.get-static(--background, 'test'), map-get($map2, --background), 'Get --background in "test"'); - @include assert-equal(props.get-static(--buttons --primary --background, 'test'), map-get($map2, --buttons, --primary, --background), 'Get --buttons --primary --background in "test"'); - @include assert-equal(props.get-static(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); - - @include assert-equal(props.get-static(--background, 'namespaced', $default: false), false, 'Get --background in "namespaced"'); - @include assert-equal(props.get-static(--ns --background, 'namespaced'), map-get($map3, --background), 'Get --ns --background in "namespaced"'); - @include props.namespace('ns') { - @include assert-equal(props.get-static(--background, 'namespaced'), map-get($map3, --background), 'Get namespaced --background in "namespaced"'); - @include assert-equal(props.get-static(--buttons --primary --background, 'namespaced'), map-get($map3, --buttons, --primary, --background), 'Get namespaced --buttons --primary --background in "namespaced"'); - @include assert-equal(props.get-static(--box, 'namespaced', $default: false), false, 'Get namespaced nonexistent in "namespaced"'); - } - - @include assert-equal(props.clear(), null, 'Delete default tree'); - @include assert-equal(props.clear('test'), null, 'Delete "test" tree'); - @include assert-equal(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(props.store($map1), null, 'Save default tree'); - @include assert-equal(props.store($map2, $merge: true), null, 'Overwrite default tree'); - - @include assert-equal(props.get-static(), map.deep-merge($map1, $map2), 'After update, get whole map'); - @include assert-equal(props.get-static(--background), map-get($map2, --background), 'After update, get --background'); - @include assert-equal(props.get-static(--text), map-get($map2, --text), 'After update, get --text'); - @include assert-equal(props.get-static(--buttons --primary --text), map-get($map1, --buttons, --primary, --text), 'After update, get --buttons --primary --text'); - - @include assert-equal(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 props.store($map); - - @include output { - @include props.assign; - } - - @include expect { - --background: #{map-get($map, --background)}; - --text: #{map-get($map, --text)}; - --buttons--primary--background: #{map-get($map, --buttons, --primary, --background)}; - --buttons--primary--text: #{map-get($map, --buttons, --primary, --text)}; - --buttons--default--background: #{map-get($map, --buttons, --default, --background)}; - --buttons--default--text: #{map-get($map, --buttons, --default, --text)}; - } - - @include props.clear; - } - - @include assert('Filtered') { - @include props.store($map); - - @include output { - @include props.assign($skip: --buttons); - } - - @include expect { - --background: #{map-get($map, --background)}; - --text: #{map-get($map, --text)}; - } - - @include props.clear; - } - - @include assert('Namespaced') { - @include props.namespace('ns') { - @include props.store($map); - } - - @include output { - @include props.assign; - } - - @include expect { - --ns--background: #{map-get($map, --background)}; - --ns--text: #{map-get($map, --text)}; - --ns--buttons--primary--background: #{map-get($map, --buttons, --primary, --background)}; - --ns--buttons--primary--text: #{map-get($map, --buttons, --primary, --text)}; - --ns--buttons--default--background: #{map-get($map, --buttons, --default, --background)}; - --ns--buttons--default--text: #{map-get($map, --buttons, --default, --text)}; - } - - @include 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(props.store($map), null, 'Save default tree'); - - @include assert-equal(props.get(--background), var(--background), 'Get --background'); - @include assert-equal(props.get(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); - @include assert-equal(props.get(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default'); - @include props.namespace('buttons') { - @include assert-equal(props.get(--primary --text), var(--buttons--primary--text), 'Get via namespace "buttons" --primary --text'); - @include assert-equal(props.get(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default'); - } - @include assert-equal(props.get(--buttons), ( - --primary: ( - --background: var(--buttons--primary--background), - --text: var(--buttons--primary--text) - ), - --default: ( - --background: var(--buttons--default--background), - --text: var(--buttons--default--text) - ) - ), 'Get --buttons recursively'); - - @include assert-equal(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: props.ref($key: --background) - ), - --default: props.ref($key: --buttons --primary) - ) - ); - - @include assert-equal(props.store($map1), null, 'Save default tree'); - @include assert-equal(props.store($map2, 'second'), null, 'Save "second" tree'); - - @include assert-equal(props.get-static(--buttons --primary --background, 'second'), map-get($map1, --background), 'Get referenced value'); - @include assert-equal(props.get(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); - - @include assert-equal(props.get-static(--buttons --default, 'second'), map-get($map1, --buttons, --primary), 'Get referenced subtree, whole'); - @include assert-equal(props.get-static(--buttons --default --background, 'second'), map-get($map1, --buttons, --primary, --background), 'Get referenced subtree, inner value'); - @include assert-equal(props.get(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); - - @include assert('Native assignment') { - @include output { - @include props.assign('second'); - } - - @include expect { - --background: #{map-get($map2, --background)}; - --buttons--primary--background: #{map-get($map1, --background)}; - --buttons--default--background: #{map-get($map1, --buttons, --primary, --background)}; - --buttons--default--text: #{map-get($map1, --buttons, --primary, --text)}; - } - } - - @include assert-equal(props.clear(), null, 'Delete default tree'); - @include assert-equal(props.clear('second'), null, 'Delete "second" tree'); - } + @include it('Save / Delete') { + $map: ( + --background: #fff, + --text: #000, + --buttons: ( + --primary: ( + --background: #f00, + --text: #fff + ) + ) + ); + + @include assert-equal(props.store($map), null, 'Save default tree'); + @include assert-equal(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(props.store($map1), null, 'Save default tree'); + @include assert-equal(props.store($map2, 'test'), null, 'Save "test" tree'); + + @include props.namespace('ns') { + @include assert-equal(props.store($map3, 'namespaced'), null, 'Save "namespaced" tree'); + } + + @include assert-equal(props.get-static(--background), map.get($map1, --background), 'Get --background in default'); + @include assert-equal(props.get-static(--buttons --primary --background), map.get($map1, --buttons, --primary, --background), 'Get --buttons --primary --background in default'); + @include assert-equal(props.get-static(--box, $default: false), false, 'Get nonexistent in default'); + + @include assert-equal(props.get-static(--background, 'test'), map.get($map2, --background), 'Get --background in "test"'); + @include assert-equal(props.get-static(--buttons --primary --background, 'test'), map.get($map2, --buttons, --primary, --background), 'Get --buttons --primary --background in "test"'); + @include assert-equal(props.get-static(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); + + @include assert-equal(props.get-static(--background, 'namespaced', $default: false), false, 'Get --background in "namespaced"'); + @include assert-equal(props.get-static(--ns --background, 'namespaced'), map.get($map3, --background), 'Get --ns --background in "namespaced"'); + @include props.namespace('ns') { + @include assert-equal(props.get-static(--background, 'namespaced'), map.get($map3, --background), 'Get namespaced --background in "namespaced"'); + @include assert-equal(props.get-static(--buttons --primary --background, 'namespaced'), map.get($map3, --buttons, --primary, --background), 'Get namespaced --buttons --primary --background in "namespaced"'); + @include assert-equal(props.get-static(--box, 'namespaced', $default: false), false, 'Get namespaced nonexistent in "namespaced"'); + } + + @include assert-equal(props.clear(), null, 'Delete default tree'); + @include assert-equal(props.clear('test'), null, 'Delete "test" tree'); + @include assert-equal(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(props.store($map1), null, 'Save default tree'); + @include assert-equal(props.store($map2, $merge: true), null, 'Overwrite default tree'); + + @include assert-equal(props.get-static(), map.deep-merge($map1, $map2), 'After update, get whole map'); + @include assert-equal(props.get-static(--background), map.get($map2, --background), 'After update, get --background'); + @include assert-equal(props.get-static(--text), map.get($map2, --text), 'After update, get --text'); + @include assert-equal(props.get-static(--buttons --primary --text), map.get($map1, --buttons, --primary, --text), 'After update, get --buttons --primary --text'); + + @include assert-equal(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 props.store($map); + + @include output { + @include props.assign; + } + + @include expect { + --background: #{map.get($map, --background)}; + --text: #{map.get($map, --text)}; + --buttons--primary--background: #{map.get($map, --buttons, --primary, --background)}; + --buttons--primary--text: #{map.get($map, --buttons, --primary, --text)}; + --buttons--default--background: #{map.get($map, --buttons, --default, --background)}; + --buttons--default--text: #{map.get($map, --buttons, --default, --text)}; + } + + @include props.clear; + } + + @include assert('Filtered') { + @include props.store($map); + + @include output { + @include props.assign($skip: --buttons); + } + + @include expect { + --background: #{map.get($map, --background)}; + --text: #{map.get($map, --text)}; + } + + @include props.clear; + } + + @include assert('Namespaced') { + @include props.namespace('ns') { + @include props.store($map); + } + + @include output { + @include props.assign; + } + + @include expect { + --ns--background: #{map.get($map, --background)}; + --ns--text: #{map.get($map, --text)}; + --ns--buttons--primary--background: #{map.get($map, --buttons, --primary, --background)}; + --ns--buttons--primary--text: #{map.get($map, --buttons, --primary, --text)}; + --ns--buttons--default--background: #{map.get($map, --buttons, --default, --background)}; + --ns--buttons--default--text: #{map.get($map, --buttons, --default, --text)}; + } + + @include 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(props.store($map), null, 'Save default tree'); + + @include assert-equal(props.get(--background), var(--background), 'Get --background'); + @include assert-equal(props.get(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); + @include assert-equal(props.get(--buttons --secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get --buttons --secondary --text with default'); + @include props.namespace('buttons') { + @include assert-equal(props.get(--primary --text), var(--buttons--primary--text), 'Get via namespace "buttons" --primary --text'); + @include assert-equal(props.get(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default'); + } + @include assert-equal(props.get(--buttons), ( + --primary: ( + --background: var(--buttons--primary--background), + --text: var(--buttons--primary--text) + ), + --default: ( + --background: var(--buttons--default--background), + --text: var(--buttons--default--text) + ) + ), 'Get --buttons recursively'); + + @include assert-equal(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: props.ref($key: --background) + ), + --default: props.ref($key: --buttons --primary) + ) + ); + + @include assert-equal(props.store($map1), null, 'Save default tree'); + @include assert-equal(props.store($map2, 'second'), null, 'Save "second" tree'); + + @include assert-equal(props.get-static(--buttons --primary --background, 'second'), map.get($map1, --background), 'Get referenced value'); + @include assert-equal(props.get(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); + + @include assert-equal(props.get-static(--buttons --default, 'second'), map.get($map1, --buttons, --primary), 'Get referenced subtree, whole'); + @include assert-equal(props.get-static(--buttons --default --background, 'second'), map.get($map1, --buttons, --primary, --background), 'Get referenced subtree, inner value'); + @include assert-equal(props.get(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); + + @include assert('Native assignment') { + @include output { + @include props.assign('second'); + } + + @include expect { + --background: #{map.get($map2, --background)}; + --buttons--primary--background: #{map.get($map1, --background)}; + --buttons--default--background: #{map.get($map1, --buttons, --primary, --background)}; + --buttons--default--text: #{map.get($map1, --buttons, --primary, --text)}; + } + } + + @include assert-equal(props.clear(), null, 'Delete default tree'); + @include assert-equal(props.clear('second'), null, 'Delete "second" tree'); + } } -- cgit v1.2.3-70-g09d2