From d07f664450ddaaebb44127a4bd057763d13d3f82 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sun, 1 Nov 2020 20:55:14 +0100 Subject: Init --- test/_props.scss | 282 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 test/_props.scss (limited to 'test/_props.scss') 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 @@ +// 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 + ), + --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 it('Read') { + $map1: ( + --background: #fff, + --text: #000, + --buttons: ( + --primary: ( + --background: #f00, + --text: #fff + ), + --default: ( + --background: #ddd, + --text: #000 + ) + ) + ); + + $map2: ( + --background: #222, + --text: #fff, + --buttons: ( + --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'); + + @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-delete(), null, 'Delete default tree'); + @include assert-equal(iro-props-delete('test'), null, 'Delete "test" tree'); + } + + @include it('Overwrite') { + $map1: ( + --background: #fff, + --text: #000, + --buttons: ( + --primary: ( + --background: #f00, + --text: #fff + ) + ) + ); + + $map2: ( + --background: #eee, + --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-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-delete(), 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 + ) + ) + ); + + @include iro-props-save($map); + + @include output { + @include iro-props-assign-native; + } + + @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-delete; + } + + @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 output { + @include iro-props-assign-native($skip: --buttons); + } + + @include expect { + --background: #{map-get($map, --background)}; + --text: #{map-get($map, --text)}; + } + + @include iro-props-delete; + } + } + + @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-save($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 assert-equal(iro-props-delete(), 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-save($map1), null, 'Save default tree'); + @include assert-equal(iro-props-save($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'); + + @include assert-equal(iro-props-get(--buttons --default, 'second'), map-get(map-get($map1, --buttons), --primary), 'Get referenced subtree, whole'); + @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'); + @include assert-equal(iro-props-get-native(--buttons --default --background, 'second'), var(--buttons--default--background), 'Get referenced subtree, native'); + + @include assert('Native assignment') { + @include output { + @include iro-props-assign-native('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-delete(), null, 'Delete default tree'); + @include assert-equal(iro-props-delete('second'), null, 'Delete "second" tree'); + } +} -- cgit v1.2.3-70-g09d2