From 8f2ce6e4491d630a35dca9612daedf95b4a2954b Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 17 Mar 2021 17:32:14 +0100 Subject: Added namespaces and shortcodes for property trees --- test/_props.scss | 166 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 87 insertions(+), 79 deletions(-) (limited to 'test') diff --git a/test/_props.scss b/test/_props.scss index 4e0a5b4..982fc2f 100644 --- a/test/_props.scss +++ b/test/_props.scss @@ -36,16 +36,12 @@ --primary: ( --background: #f00, --text: #fff - ), - --default: ( - --background: #ddd, - --text: #000 ) ) ); - @include assert-equal(iro-props-save($map), null, 'Save default tree'); - @include assert-equal(iro-props-delete(), null, 'Delete default tree'); + @include assert-equal(iro-props-store($map), null, 'Save default tree'); + @include assert-equal(iro-props-clear(), null, 'Delete default tree'); } @include it('Read') { @@ -56,10 +52,6 @@ --primary: ( --background: #f00, --text: #fff - ), - --default: ( - --background: #ddd, - --text: #000 ) ) ); @@ -71,35 +63,52 @@ --primary: ( --background: #f00, --text: #fff - ), - --default: ( - --background: #444, - --text: #fff ) ) ); - @include assert-equal(iro-props-save($map1), null, 'Save default tree'); - @include assert-equal(iro-props-save($map2, 'test'), null, 'Save "test" tree'); + $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(--background), map-get($map1, --background), 'Get --background in default'); @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'); - @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'); @include assert-equal(iro-props-get(--box, $default: false), false, 'Get nonexistent in default'); @include assert-equal(iro-props-get(--background, 'test'), map-get($map2, --background), 'Get --background in "test"'); @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"'); - @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"'); @include assert-equal(iro-props-get(--box, 'test', $default: false), false, 'Get nonexistent in "test"'); + + @include assert-equal(iro-props-get(--background, 'namespaced', $default: false), false, 'Get --background in "namespaced"'); + @include assert-equal(iro-props-get(--ns --background, 'namespaced'), map-get($map3, --background), 'Get --ns --background in "namespaced"'); + @include iro-props-namespace('ns') { + @include assert-equal(iro-props-get(--background, 'namespaced'), map-get($map3, --background), 'Get namespaced --background in "namespaced"'); + @include assert-equal(iro-props-get(--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(--box, 'namespaced', $default: false), false, 'Get namespaced nonexistent in "namespaced"'); + } - @include assert-equal(iro-props-delete(), null, 'Delete default tree'); - @include assert-equal(iro-props-delete('test'), null, 'Delete "test" tree'); + @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, - --text: #000, --buttons: ( --primary: ( --background: #f00, @@ -110,54 +119,43 @@ $map2: ( --background: #eee, + --text: #000, --buttons: ( --primary: ( --background: #00f - ), - --default: ( - --background: #444, - --text: #fff ) ) ); - @include assert-equal(iro-props-save($map1), null, 'Save default tree'); - - @include assert-equal(iro-props-get(), $map1, 'Before update, get whole map'); - @include assert-equal(iro-props-get(--background), map-get($map1, --background), 'Before update, get --background'); - @include assert-equal(iro-props-get(--text), map-get($map1, --text), 'Before update, get --text'); - @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'); - @include assert-equal(iro-props-get(--buttons --default --text, $default: false), false, 'Before update, get --buttons --default --text (returns default)'); - - @include assert-equal(iro-props-save($map2, $merge: true), null, 'Overwrite default tree'); + @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(), iro-map-merge-recursive($map1, $map2), 'After update, get whole map'); - @include assert-equal(iro-props-get(--background), map-get($map2, --background), 'After update, get --background'); - @include assert-equal(iro-props-get(--text), map-get($map1, --text), 'After update, get --text'); - @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'); - @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'); + @include assert-equal(iro-props-get(), iro-map-merge-recursive($map1, $map2), 'After update, get whole map'); + @include assert-equal(iro-props-get(--background), map-get($map2, --background), 'After update, get --background'); + @include assert-equal(iro-props-get(--text), map-get($map2, --text), 'After update, get --text'); + @include assert-equal(iro-props-get(--buttons --primary --text), map-get(map-get(map-get($map1, --buttons), --primary), --text), 'After update, get --buttons --primary --text'); - @include assert-equal(iro-props-delete(), null, 'Delete default tree'); + @include assert-equal(iro-props-clear(), null, 'Delete default tree'); } @include it('Native assignment') { - @include assert('Simple') { - $map: ( - --background: #fff, - --text: #000, - --buttons: ( - --primary: ( - --background: #f00, - --text: #fff - ), - --default: ( - --background: #ddd, - --text: #000 - ) + $map: ( + --background: #fff, + --text: #000, + --buttons: ( + --primary: ( + --background: #f00, + --text: #fff + ), + --default: ( + --background: #ddd, + --text: #000 ) - ); + ) + ); - @include iro-props-save($map); + @include assert('Simple') { + @include iro-props-store($map); @include output { @include iro-props-assign-native; @@ -172,26 +170,11 @@ --buttons--default--text: #{map-get(map-get(map-get($map, --buttons), --default), --text)}; } - @include iro-props-delete; + @include iro-props-clear; } @include assert('Filtered') { - $map: ( - --background: #fff, - --text: #000, - --buttons: ( - --primary: ( - --background: #f00, - --text: #fff - ), - --default: ( - --background: #ddd, - --text: #000 - ) - ) - ); - - @include iro-props-save($map); + @include iro-props-store($map); @include output { @include iro-props-assign-native($skip: --buttons); @@ -202,7 +185,28 @@ --text: #{map-get($map, --text)}; } - @include iro-props-delete; + @include iro-props-clear; + } + + @include assert('Namespaced') { + @include iro-props-namespace('ns') { + @include iro-props-store($map); + } + + @include output { + @include iro-props-assign-native; + } + + @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; } } @@ -222,13 +226,17 @@ ) ); - @include assert-equal(iro-props-save($map), null, 'Save default tree'); + @include assert-equal(iro-props-store($map), null, 'Save default tree'); @include assert-equal(iro-props-get-native(--background), var(--background), 'Get --background'); @include assert-equal(iro-props-get-native(--buttons --primary --text), var(--buttons--primary--text), 'Get --buttons --primary --text'); @include assert-equal(iro-props-get-native(--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-native(--primary --text), var(--buttons--primary--text), 'Get via namespace "buttons" --primary --text'); + @include assert-equal(iro-props-get-native(--secondary --text, $default: false), var(--buttons--secondary--text, false), 'Get via namespace "buttons" --secondary --text with default'); + } - @include assert-equal(iro-props-delete(), null, 'Delete default tree'); + @include assert-equal(iro-props-clear(), null, 'Delete default tree'); } @include it('References') { @@ -253,8 +261,8 @@ ) ); - @include assert-equal(iro-props-save($map1), null, 'Save default tree'); - @include assert-equal(iro-props-save($map2, 'second'), null, 'Save "second" tree'); + @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(--buttons --primary --background, 'second'), map-get($map1, --background), 'Get referenced value'); @include assert-equal(iro-props-get-native(--buttons --primary --background, 'second'), var(--buttons--primary--background), 'Get referenced value, native'); @@ -276,7 +284,7 @@ } } - @include assert-equal(iro-props-delete(), null, 'Delete default tree'); - @include assert-equal(iro-props-delete('second'), null, 'Delete "second" tree'); + @include assert-equal(iro-props-clear(), null, 'Delete default tree'); + @include assert-equal(iro-props-clear('second'), null, 'Delete "second" tree'); } } -- cgit v1.2.3-70-g09d2