From 4c9a427806b47b916849dbc98330fdbb469b659b Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 7 Feb 2022 12:28:59 +0100 Subject: Replace deep map functions with built-ins --- test/_props.scss | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'test/_props.scss') diff --git a/test/_props.scss b/test/_props.scss index 71d88c5..d8b550b 100644 --- a/test/_props.scss +++ b/test/_props.scss @@ -1,5 +1,6 @@ // sass-lint:disable empty-args +@use 'sass:map'; @use 'true' as *; @use '../src/functions'; @use '../src/props'; @@ -89,20 +90,20 @@ @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(map-get(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), 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(map-get(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, '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(map-get(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.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'); @@ -134,10 +135,10 @@ @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(), functions.map-merge-recursive($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(map-get(map-get($map1, --buttons), --primary), --text), 'After update, get --buttons --primary --text'); + @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'); } @@ -168,10 +169,10 @@ @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)}; + --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; @@ -204,10 +205,10 @@ @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)}; + --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; @@ -271,9 +272,9 @@ @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(map-get($map1, --buttons), --primary), 'Get referenced subtree, whole'); - @include assert-equal(props.get-static(--buttons --default --background, 'second'), map-get(map-get(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-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 { @@ -283,8 +284,8 @@ @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)}; + --buttons--default--background: #{map-get($map1, --buttons, --primary, --background)}; + --buttons--default--text: #{map-get($map1, --buttons, --primary, --text)}; } } -- cgit v1.3.1