From d07f664450ddaaebb44127a4bd057763d13d3f82 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sun, 1 Nov 2020 20:55:14 +0100 Subject: Init --- test/_bem.scss | 19 + test/_contexts.scss | 65 +++ test/_functions.scss | 103 +++++ test/_gradients.scss | 264 +++++++++++++ test/_harmony.scss | 249 ++++++++++++ test/_math.scss | 21 + test/_props.scss | 282 +++++++++++++ test/_responsive.scss | 9 + test/bem/_examples.scss | 224 +++++++++++ test/bem/_iro-bem-at-theme.scss | 55 +++ test/bem/_iro-bem-block.scss | 85 ++++ test/bem/_iro-bem-composed-of.scss | 149 +++++++ test/bem/_iro-bem-element.scss | 491 +++++++++++++++++++++++ test/bem/_iro-bem-modifier.scss | 654 +++++++++++++++++++++++++++++++ test/bem/_iro-bem-multi.scss | 591 ++++++++++++++++++++++++++++ test/bem/_iro-bem-next-twin-element.scss | 153 ++++++++ test/bem/_iro-bem-related-element.scss | 459 ++++++++++++++++++++++ test/bem/_iro-bem-state.scss | 177 +++++++++ test/bem/_iro-bem-suffix.scss | 94 +++++ test/test.js | 4 + test/test.scss | 16 + 21 files changed, 4164 insertions(+) create mode 100644 test/_bem.scss create mode 100644 test/_contexts.scss create mode 100644 test/_functions.scss create mode 100644 test/_gradients.scss create mode 100644 test/_harmony.scss create mode 100644 test/_math.scss create mode 100644 test/_props.scss create mode 100644 test/_responsive.scss create mode 100644 test/bem/_examples.scss create mode 100644 test/bem/_iro-bem-at-theme.scss create mode 100644 test/bem/_iro-bem-block.scss create mode 100644 test/bem/_iro-bem-composed-of.scss create mode 100644 test/bem/_iro-bem-element.scss create mode 100644 test/bem/_iro-bem-modifier.scss create mode 100644 test/bem/_iro-bem-multi.scss create mode 100644 test/bem/_iro-bem-next-twin-element.scss create mode 100644 test/bem/_iro-bem-related-element.scss create mode 100644 test/bem/_iro-bem-state.scss create mode 100644 test/bem/_iro-bem-suffix.scss create mode 100644 test/test.js create mode 100644 test/test.scss (limited to 'test') diff --git a/test/_bem.scss b/test/_bem.scss new file mode 100644 index 0000000..30ed131 --- /dev/null +++ b/test/_bem.scss @@ -0,0 +1,19 @@ +@include describe('BEM') { + // + // The following unit tests only test the BEM mixins. + // Since they are wrappers for the BEM functions, the latter are + // automatically covered. + // + + @import 'bem/iro-bem-block'; + @import 'bem/iro-bem-composed-of'; + @import 'bem/iro-bem-at-theme'; + @import 'bem/iro-bem-element'; + @import 'bem/iro-bem-related-element'; + @import 'bem/iro-bem-next-twin-element'; + @import 'bem/iro-bem-modifier'; + @import 'bem/iro-bem-suffix'; + @import 'bem/iro-bem-state'; + @import 'bem/iro-bem-multi'; + @import 'bem/examples'; +} diff --git a/test/_contexts.scss b/test/_contexts.scss new file mode 100644 index 0000000..1b0e602 --- /dev/null +++ b/test/_contexts.scss @@ -0,0 +1,65 @@ +@include describe('Contexts') { + @include it('Creating / deleting context stacks') { + @include assert-equal(iro-context-stack-create('test'), null, 'Check if context stack was created'); + @include assert-equal(iro-context-stack-delete('test'), null, 'Check if context stack was deleted'); + } + + @include it('Adding / removing contexts') { + @include assert-equal(iro-context-stack-create('test'), null, 'Check if context stack was created'); + + @include assert-equal(iro-context-push('test', 'ctx', 1234), 'ctx' 1234, 'Check if context 1 was pushed'); + @include assert-equal(iro-context-push('test', 'another', 'text'), 'another' 'text', 'Check if context 2 was pushed'); + @include assert-equal(iro-context-push('test', 'ctx', 56), 'ctx' 56, 'Check if context 3 was pushed'); + + @include assert-equal(iro-context-pop('test'), 'ctx' 56, 'Check if context 3 was popped'); + @include assert-equal(iro-context-pop('test'), 'another' 'text', 'Check if context 2 was popped'); + @include assert-equal(iro-context-pop('test'), 'ctx' 1234, 'Check if context 1 was popped'); + + @include assert-equal(iro-context-stack-delete('test'), null, 'Check if context stack was deleted'); + } + + @include it('Clearing / counting context stacks') { + @include assert-equal(iro-context-stack-create('test'), null, 'Check if context stack was created'); + + @include assert-equal(iro-context-push('test', 'ctx', 1234), 'ctx' 1234, 'Check if context 1 was pushed'); + @include assert-equal(iro-context-push('test', 'another', 'text'), 'another' 'text', 'Check if context 2 was pushed'); + @include assert-equal(iro-context-push('test', 'ctx', 56), 'ctx' 56, 'Check if context 3 was pushed'); + + @include assert-equal(iro-context-stack-count('test'), 3, 'Check if context stack contains 3 contexts'); + @include assert-equal(iro-context-pop('test'), 'ctx' 56, 'Check if context 3 was popped'); + @include assert-equal(iro-context-stack-count('test'), 2, 'Check if context stack contains 2 contexts'); + @include assert-equal(iro-context-stack-clear('test'), null, 'Check if context stack was cleared'); + @include assert-equal(iro-context-stack-count('test'), 0, 'Check if context stack contains no contexts'); + + @include assert-equal(iro-context-stack-delete('test'), null, 'Check if context stack was deleted'); + } + + @include it('Retrieving contexts') { + @include assert-equal(iro-context-stack-create('test'), null, 'Check if context stack was created'); + + @include assert-equal(iro-context-push('test', 'ctx', 1234), 'ctx' 1234, 'Check if context 1 was pushed'); + @include assert-equal(iro-context-push('test', 'another', 'text'), 'another' 'text', 'Check if context 2 was pushed'); + @include assert-equal(iro-context-push('test', 'ctx', 56), 'ctx' 56, 'Check if context 3 was pushed'); + + @include assert-equal(iro-context-get('test', 1), 'ctx' 56, 'Check if context at position 1 is context 3'); + @include assert-equal(iro-context-get('test', 'ctx'), 'ctx' 56, 'Check if latest context with id "ctx" is context 3'); + @include assert-equal(iro-context-get('test', 2), 'another' 'text', 'Check if latest context with id "another" is context 2'); + + @include assert-equal(iro-context-pop('test'), 'ctx' 56, 'Check if context 3 was popped'); + + @include assert-equal(iro-context-get('test', 1), 'another' 'text', 'Check if context at position 1 is context 2'); + @include assert-equal(iro-context-get('test', -1), 'ctx' 1234, 'Check if latest context with id "ctx" is context 1'); + + @include assert-equal(iro-context-push('test', 'more', 'string'), 'more' 'string', 'Check if context 4 was pushed'); + + @include assert-equal(iro-context-get('test', 1), 'more' 'string', 'Check if context at position 1 is context 4'); + @include assert-equal(iro-context-get('test', 'more'), 'more' 'string', 'Check if latest context with id "more" is context 4'); + + @include assert-equal(iro-context-pop('test'), 'more' 'string', 'Check if context 4 was popped'); + @include assert-equal(iro-context-pop('test'), 'another' 'text', 'Check if context 2 was popped'); + + @include assert-equal(iro-context-get('test', 1), iro-context-get('test', -1), 'Check if first and last context are context 1'); + + @include assert-equal(iro-context-stack-delete('test'), null, 'Check if context stack was deleted'); + } +} diff --git a/test/_functions.scss b/test/_functions.scss new file mode 100644 index 0000000..54e37c5 --- /dev/null +++ b/test/_functions.scss @@ -0,0 +1,103 @@ +@include describe('Functions') { + @include it('iro-str-replace') { + $str: 'Hello world!'; + + @include assert-equal(iro-str-replace($str, 'world', 'neighbor'), 'Hello neighbor!', 'Replace "world" with "neighbor"'); + @include assert-equal(iro-str-replace($str, 'neighbor', 'moon'), 'Hello world!', 'Replace "neighbor" with "moon"'); + @include assert-equal(iro-str-replace($str, 'Hello', 'Bye'), 'Bye world!', 'Replace "Hello" with "Bye"'); + } + + @include it('iro-list-slice') { + $list: 'this' 'is' 'a' 'list'; + + @include assert-equal(iro-list-slice($list, 2), 'is' 'a' 'list', 'Discard first item'); + @include assert-equal(iro-list-slice($list, 1, 3), 'this' 'is' 'a', 'Keep first 3 items'); + @include assert-equal(iro-list-slice($list, 2, 3), 'is' 'a', 'Extract list from index 2 to 3'); + @include assert-equal(iro-list-slice($list, -1, -1), join((), 'list'), 'Keep last item'); + @include assert-equal(iro-list-slice($list, -1, 1), 'list' 'this', 'Extract first and last item'); + } + + @include it('iro-list-prepend') { + $list: 'this' 'is' 'a' 'list'; + + @include assert-equal(iro-list-prepend($list, 'and'), 'and' 'this' 'is' 'a' 'list', 'Prepend "and"'); + @include assert-equal(iro-list-prepend($list, 2), 2 'this' 'is' 'a' 'list', 'Prepend 2'); + } + + @include it('iro-quicksort') { + @include assert-equal(iro-quicksort(1 2 3 4 5), 1 2 3 4 5, 'Already sorted list of 5 items'); + @include assert-equal(iro-quicksort(1 3 2), 1 2 3, 'Random list of 3 items'); + @include assert-equal(iro-quicksort(6 3 7 3 8 1 4), 1 3 3 4 6 7 8, 'Random list of 7 items, one duplicate'); + @include assert-equal(iro-quicksort(1 1 1 1), 1 1 1 1, 'List of 4 identical items'); + } + + @include it('iro-map-get-default') { + $map: ('key': 'value', 'another': 'item'); + + @include assert-equal(iro-map-get-default($map, 'another', 0), map-get($map, 'another'), 'Get existing value'); + @include assert-equal(iro-map-get-default($map, 'index', 'nothing'), 'nothing', 'Get missing value'); + } + + @include it('iro-map-get-deep') { + $map: ( + 'key': 'value', + 'sub': ( + 'item1': 1, + 'item2': 2, + 'subsub': ( + 'item1': 11, + 'item2': 12, + ) + ) + ); + + @include assert-equal(iro-map-get-deep($map, 'key'), map-get($map, 'key'), 'Get value in root level'); + @include assert-equal(iro-map-get-deep($map, 'sub' 'item1'), map-get(map-get($map, 'sub'), 'item1'), 'Get value in first level'); + @include assert-equal(iro-map-get-deep($map, 'sub' 'item2'), map-get(map-get($map, 'sub'), 'item2'), 'Get value in first level'); + @include assert-equal(iro-map-get-deep($map, 'sub' 'subsub' 'item1'), map-get(map-get(map-get($map, 'sub'), 'subsub'), 'item1'), 'Get value in second level'); + @include assert-equal(iro-map-get-deep($map, 'sub' 'subsub' 'item2'), map-get(map-get(map-get($map, 'sub'), 'subsub'), 'item2'), 'Get value in second level'); + } + + @include it('iro-map-merge-recursive') { + $map1: ( + 'key': 'value', + 'sub': ( + 'item1': 1, + 'item3': 2 + ) + ); + $map2: ( + 'another': 'item', + 'sub': ( + 'item1': 0, + 'item2': 1 + ) + ); + + $expected: ( + 'key': 'value', + 'another': 'item', + 'sub': ( + 'item1': 0, + 'item2': 1, + 'item3': 2 + ) + ); + + @include assert-equal(iro-map-merge-recursive($map1, $map2), $expected); + } + + @include it('iro-strip-unit') { + @include assert-true(unitless(iro-strip-unit(1em)), 'Remove unit from 1em'); + @include assert-true(unitless(iro-strip-unit(2rem)), 'Remove unit from 2rem'); + @include assert-true(unitless(iro-strip-unit(3px)), 'Remove unit from 3px'); + @include assert-true(unitless(iro-strip-unit(4)), 'Remove unit from 4'); + @include assert-true(unitless(iro-strip-unit(5pt)), 'Remove unit from 5pt'); + } + + @include it('iro-px-to-rem') { + @include assert-equal(iro-px-to-rem(16px, 16px), 1rem, 'Convert 16px'); + @include assert-equal(iro-px-to-rem(32px, 16px), 2rem, 'Convert 16px'); + @include assert-equal(iro-px-to-rem(8px, 16px), 0.5rem, 'Convert 16px'); + } +} diff --git a/test/_gradients.scss b/test/_gradients.scss new file mode 100644 index 0000000..c1145aa --- /dev/null +++ b/test/_gradients.scss @@ -0,0 +1,264 @@ +// sass-lint:disable no-color-literals zero-unit + +@include describe('Gradients') { + @include it('iro-easing-gradient') { + $gradient1: iro-easing-gradient( + linear, + to right, + #000, + ease-in-quad, + transparent + ); + + $expected1: linear-gradient( + to right, + #000 0, + mix(transparent, #000, iro-ease-in-quad(0.25) * 100%) 25%, + mix(transparent, #000, iro-ease-in-quad(0.5) * 100%) 50%, + mix(transparent, #000, iro-ease-in-quad(0.75) * 100%) 75%, + transparent 100% + ); + + @include assert-equal($gradient1, $expected1, 'Simple linear gradient'); + + // --------------------------------------------------------------------------- + + $gradient2: iro-easing-gradient( + radial, + 1em 2em at 50% 60%, + #000, + ease-out-cubic, + transparent + ); + + $expected2: radial-gradient( + 1em 2em at 50% 60%, + #000 0, + mix(transparent, #000, iro-ease-out-cubic(0.25) * 100%) 25%, + mix(transparent, #000, iro-ease-out-cubic(0.5) * 100%) 50%, + mix(transparent, #000, iro-ease-out-cubic(0.75) * 100%) 75%, + transparent 100% + ); + + @include assert-equal($gradient2, $expected2, 'Simple radial gradient'); + + // --------------------------------------------------------------------------- + + $gradient3: iro-easing-gradient( + linear, + to right, + #000 2em, + ease-in-quad, + transparent 10em + ); + + $expected3: linear-gradient( + to right, + #000 2em, + mix(transparent, #000, iro-ease-in-quad(0.25) * 100%) 4em, + mix(transparent, #000, iro-ease-in-quad(0.5) * 100%) 6em, + mix(transparent, #000, iro-ease-in-quad(0.75) * 100%) 8em, + transparent 10em + ); + + @include assert-equal($gradient3, $expected3, 'Linear gradient with positioned color stops'); + + // --------------------------------------------------------------------------- + + $gradient4: iro-easing-gradient( + linear, + to right, + #000 20%, + ease-in-quad, + transparent calc(20% + 10em) + ); + + $expected4: linear-gradient( + to right, + #000 20%, + mix(transparent, #000, iro-ease-in-quad(0.25) * 100%) calc(20% + (20% + 10em - 20%) * 0.25), + mix(transparent, #000, iro-ease-in-quad(0.5) * 100%) calc(20% + (20% + 10em - 20%) * 0.5), + mix(transparent, #000, iro-ease-in-quad(0.75) * 100%) calc(20% + (20% + 10em - 20%) * 0.75), + transparent calc(20% + 10em) + ); + + @include assert-equal($gradient4, $expected4, 'More advanced linear gradient with positioned color stops'); + + // --------------------------------------------------------------------------- + + $gradient5: iro-easing-gradient( + linear, + to right, + #000 2em, + #f00 7em, + ease-in-quad, + transparent 10em + ); + + $expected5: linear-gradient( + to right, + #000 2em, + #f00 7em, + mix(transparent, #f00, iro-ease-in-quad(0.25) * 100%) 7em + 3em * 0.25, + mix(transparent, #f00, iro-ease-in-quad(0.5) * 100%) 7em + 3em * 0.5, + mix(transparent, #f00, iro-ease-in-quad(0.75) * 100%) 7em + 3em * 0.75, + transparent 10em + ); + + @include assert-equal($gradient5, $expected5, 'Linear gradient with 3 positioned color stops, 1 easing transitions'); + + // --------------------------------------------------------------------------- + + $gradient6: iro-easing-gradient( + linear, + to right, + #000 2em, + ease-in-quad, + #f00 7em, + ease-in-quad, + transparent 10em + ); + + $expected6: linear-gradient( + to right, + #000 2em, + mix(#f00, #000, iro-ease-in-quad(0.25) * 100%) 2em + 5em * 0.25, + mix(#f00, #000, iro-ease-in-quad(0.5) * 100%) 2em + 5em * 0.5, + mix(#f00, #000, iro-ease-in-quad(0.75) * 100%) 2em + 5em * 0.75, + #f00 7em, + mix(transparent, #f00, iro-ease-in-quad(0.25) * 100%) 7em + 3em * 0.25, + mix(transparent, #f00, iro-ease-in-quad(0.5) * 100%) 7em + 3em * 0.5, + mix(transparent, #f00, iro-ease-in-quad(0.75) * 100%) 7em + 3em * 0.75, + transparent 10em + ); + + @include assert-equal($gradient6, $expected6, 'Linear gradient with 3 positioned color stops, 2 easing transitions'); + + // --------------------------------------------------------------------------- + + $gradient7: iro-easing-gradient( + linear, + to right, + #000 2em, + ease-in-quad, + #f00, + ease-in-quad, + transparent 10em + ); + + $expected7: linear-gradient( + to right, + #000 2em, + mix(#f00, #000, iro-ease-in-quad(0.25) * 100%) 2em + 4em * 0.25, + mix(#f00, #000, iro-ease-in-quad(0.5) * 100%) 2em + 4em * 0.5, + mix(#f00, #000, iro-ease-in-quad(0.75) * 100%) 2em + 4em * 0.75, + #f00 6em, + mix(transparent, #f00, iro-ease-in-quad(0.25) * 100%) 6em + 4em * 0.25, + mix(transparent, #f00, iro-ease-in-quad(0.5) * 100%) 6em + 4em * 0.5, + mix(transparent, #f00, iro-ease-in-quad(0.75) * 100%) 6em + 4em * 0.75, + transparent 10em + ); + + @include assert-equal($gradient7, $expected7, 'Linear gradient with 2 / 3 positioned color stops, 2 easing transitions'); + + // --------------------------------------------------------------------------- + + $gradient8: iro-easing-gradient( + linear, + to right, + #000, + ease-in-quad, + #f00, + ease-in-quad, + transparent + ); + + $expected8: linear-gradient( + to right, + #000 0, + mix(#f00, #000, iro-ease-in-quad(0.25) * 100%) 50% * 0.25, + mix(#f00, #000, iro-ease-in-quad(0.5) * 100%) 50% * 0.5, + mix(#f00, #000, iro-ease-in-quad(0.75) * 100%) 50% * 0.75, + #f00 50%, + mix(transparent, #f00, iro-ease-in-quad(0.25) * 100%) 50% + 50% * 0.25, + mix(transparent, #f00, iro-ease-in-quad(0.5) * 100%) 50% + 50% * 0.5, + mix(transparent, #f00, iro-ease-in-quad(0.75) * 100%) 50% + 50% * 0.75, + transparent 100% + ); + + @include assert-equal($gradient8, $expected8, 'Linear gradient with 0 / 3 positioned color stops, 2 easing transitions'); + + // --------------------------------------------------------------------------- + + $gradient9: iro-easing-gradient( + linear, + to right, + #000, + ease-in-quad, + #f00, + ease-in-quad, + transparent 20em + ); + + $expected9: linear-gradient( + to right, + #000 0, + mix(#f00, #000, iro-ease-in-quad(0.25) * 100%) 10em * 0.25, + mix(#f00, #000, iro-ease-in-quad(0.5) * 100%) 10em * 0.5, + mix(#f00, #000, iro-ease-in-quad(0.75) * 100%) 10em * 0.75, + #f00 10em, + mix(transparent, #f00, iro-ease-in-quad(0.25) * 100%) 10em + 10em * 0.25, + mix(transparent, #f00, iro-ease-in-quad(0.5) * 100%) 10em + 10em * 0.5, + mix(transparent, #f00, iro-ease-in-quad(0.75) * 100%) 10em + 10em * 0.75, + transparent 20em + ); + + @include assert-equal($gradient9, $expected9, 'Linear gradient with 1 / 3 positioned color stops, 2 easing transitions'); + + // --------------------------------------------------------------------------- + + $gradient10: iro-easing-gradient( + linear, + to right, + #000, + cubic-bezier 0.47 0 0.745 0.715, + transparent + ); + + $expected10: linear-gradient( + to right, + #000 0, + mix(transparent, #000, iro-cubic-bezier(0.47, 0, 0.745, 0.715, 0.25) * 100%) 25%, + mix(transparent, #000, iro-cubic-bezier(0.47, 0, 0.745, 0.715, 0.5) * 100%) 50%, + mix(transparent, #000, iro-cubic-bezier(0.47, 0, 0.745, 0.715, 0.75) * 100%) 75%, + transparent 100% + ); + + @include assert-equal($gradient10, $expected10, 'Simple linear gradient with custom cubic-bezier easing'); + + // --------------------------------------------------------------------------- + + $gradient11: iro-easing-gradient( + linear, + to right, + #000, + steps 4 jump-start, + transparent + ); + + $expected11: linear-gradient( + to right, + #000 0, + mix(transparent, #000, 0.25 * 100%) 0, + mix(transparent, #000, 0.25 * 100%) 25%, + mix(transparent, #000, 0.5 * 100%) 25%, + mix(transparent, #000, 0.5 * 100%) 50%, + mix(transparent, #000, 0.75 * 100%) 50%, + mix(transparent, #000, 0.75 * 100%) 75%, + transparent 75%, + transparent 100% + ); + + @include assert-equal($gradient11, $expected11, 'Simple linear gradient with custom steps easing'); + } +} diff --git a/test/_harmony.scss b/test/_harmony.scss new file mode 100644 index 0000000..25560f0 --- /dev/null +++ b/test/_harmony.scss @@ -0,0 +1,249 @@ +@function _limit-decimals($n) { + @return floor($n * 1000) / 1000; +} + +@include describe('Harmony') { + @include it('iro-harmony-modular-scale') { + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(0, 1em, 1.1)), 1em, 'Zero iterations, 1em base, 1.1 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(1, 1em, 1.1)), 1.1em, '1 iteration, 1em base, 1.1 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(2, 2px, 1.2)), 2.88px, '2 iterations, 2px base, 1.2 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(-1, 2rem, 2)), 1rem, '-1 iteration, 2rem base, 2 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(-2, 2rem, 2)), 0.5rem, '-2 iterations, 2rem base, 2 scale'); + + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(0, 1em 2em, 1.1)), 1em, 'Zero iterations, 1em 2em base, 1.1 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(1, 1em 2em, 1.1)), 1.026em, '1 iteration, 1em 2em base, 1.1 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(2, 1em 2em, 1.1)), 1.1em, '2 iterations, 1em 2em base, 1.1 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(-1, 1em 1.5em, 1.2)), 0.868em, '-1 iteration, 1em 2em base, 1.1 scale'); + @include assert-equal(_limit-decimals(iro-harmony-modular-scale(-2, 1em 1.5em, 1.2)), 0.833em, '-2 iterations, 1em 2em base, 1.1 scale'); + } + + @include it('iro-responsive-modular-scale') { + @include assert('Single-stranded, fluid') { + $ms: ( + 320px: (1rem, 1.1), + 640px: (1rem, 1.2) + ); + + $rem320px: iro-px-to-rem(320px); + $rem640px: iro-px-to-rem(640px); + $diff320px: iro-strip-unit($rem640px - $rem320px); + + @include output { + h3 { + @include iro-responsive-modular-scale(font-size, 0, $ms); + } + + h2 { + @include iro-responsive-modular-scale(font-size, 1, $ms); + } + + h1 { + @include iro-responsive-modular-scale(font-size, 2, $ms); + } + } + + @include expect { + h3 { + font-size: 1rem; + + @media (min-width: 320px) and (max-width: 640px) { + font-size: calc(1rem + 0 * ((100vw - #{$rem320px}) / #{$diff320px})); + } + + @media (min-width: 640px) { + font-size: 1rem; + } + } + + h2 { + font-size: 1.1rem; + + @media (min-width: 320px) and (max-width: 640px) { + font-size: calc(1.1rem + 0.1 * ((100vw - #{$rem320px}) / #{$diff320px})); + } + + @media (min-width: 640px) { + font-size: 1.2rem; + } + } + + h1 { + font-size: 1.21rem; + + @media (min-width: 320px) and (max-width: 640px) { + font-size: calc(1.21rem + 0.23 * ((100vw - #{$rem320px}) / #{$diff320px})); + } + + @media (min-width: 640px) { + font-size: 1.44rem; + } + } + } + } + + @include assert('Single-stranded, non-fluid') { + $ms: ( + 320px: (1rem, 1.1), + 640px: (1rem, 1.2) + ); + + $rem320px: iro-px-to-rem(320px); + $rem640px: iro-px-to-rem(640px); + $diff320px: iro-strip-unit($rem640px - $rem320px); + + @include output { + h3 { + @include iro-responsive-modular-scale(font-size, 0, $ms, false); + } + + h2 { + @include iro-responsive-modular-scale(font-size, 1, $ms, false); + } + + h1 { + @include iro-responsive-modular-scale(font-size, 2, $ms, false); + } + } + + @include expect { + h3 { + font-size: 1rem; + + @media (min-width: 640px) { + font-size: 1rem; + } + } + + h2 { + font-size: 1.1rem; + + @media (min-width: 640px) { + font-size: 1.2rem; + } + } + + h1 { + font-size: 1.21rem; + + @media (min-width: 640px) { + font-size: 1.44rem; + } + } + } + } + + @include assert('Double-stranded, fluid') { + $ms: ( + 320px: (1rem 2rem, 1.1), + 640px: (1rem 2rem, 1.2) + ); + + $rem320px: iro-px-to-rem(320px); + $rem640px: iro-px-to-rem(640px); + $diff320px: iro-strip-unit($rem640px - $rem320px); + + @include output { + h3 { + @include iro-responsive-modular-scale(font-size, 0, $ms); + } + + h2 { + @include iro-responsive-modular-scale(font-size, 1, $ms); + } + + h1 { + @include iro-responsive-modular-scale(font-size, 2, $ms); + } + } + + @include expect { + h3 { + font-size: 1rem; + + @media (min-width: 320px) and (max-width: 640px) { + font-size: calc(1rem + 0 * ((100vw - #{$rem320px}) / #{$diff320px})); + } + + @media (min-width: 640px) { + font-size: 1rem; + } + } + + h2 { + font-size: 1.0263162365rem; + + @media (min-width: 320px) and (max-width: 640px) { + font-size: calc(1.0263162365rem + 0.1310911709 * ((100vw - #{$rem320px}) / #{$diff320px})); + } + + @media (min-width: 640px) { + font-size: 1.1574074074rem; + } + } + + h1 { + font-size: 1.1rem; + + @media (min-width: 320px) and (max-width: 640px) { + font-size: calc(1.1rem + 0.1 * ((100vw - #{$rem320px}) / #{$diff320px})); + } + + @media (min-width: 640px) { + font-size: 1.2rem; + } + } + } + } + + @include assert('Double-stranded, non-fluid') { + $ms: ( + 320px: (1rem 2rem, 1.1), + 640px: (1rem 2rem, 1.2) + ); + + $rem320px: iro-px-to-rem(320px); + $rem640px: iro-px-to-rem(640px); + $diff320px: iro-strip-unit($rem640px - $rem320px); + + @include output { + h3 { + @include iro-responsive-modular-scale(font-size, 0, $ms, false); + } + + h2 { + @include iro-responsive-modular-scale(font-size, 1, $ms, false); + } + + h1 { + @include iro-responsive-modular-scale(font-size, 2, $ms, false); + } + } + + @include expect { + h3 { + font-size: 1rem; + + @media (min-width: 640px) { + font-size: 1rem; + } + } + + h2 { + font-size: 1.0263162365rem;; + + @media (min-width: 640px) { + font-size: 1.1574074074rem;; + } + } + + h1 { + font-size: 1.1rem; + + @media (min-width: 640px) { + font-size: 1.2rem; + } + } + } + } + } +} diff --git a/test/_math.scss b/test/_math.scss new file mode 100644 index 0000000..5f40499 --- /dev/null +++ b/test/_math.scss @@ -0,0 +1,21 @@ +// sass-lint:disable empty-args + +@include describe('Math') { + @include it('iro-math-pow') { + @include assert-equal(iro-math-pow(2, 2), 2 * 2, '2^2'); + @include assert-equal(iro-math-pow(2, 3), 2 * 2 * 2, '2^3'); + @include assert-equal(iro-math-pow(4, 3), 4 * 4 * 4, '4^3'); + @include assert-equal(iro-math-pow(3, -1), 1 / 3, '3^(-1)'); + @include assert-equal(iro-math-pow(4, -2), 1 / (4 * 4), '4^(-2)'); + @include assert-equal(iro-math-pow(3, 0), 1, '3^0'); + } + + @include it('iro-math-clamp') { + @include assert-equal(iro-math-clamp(0, 0, 10), 0, '0 in [0, 10]'); + @include assert-equal(iro-math-clamp(10, 0, 10), 10, '10 in [0, 10]'); + @include assert-equal(iro-math-clamp(20, 0, 10), 10, '20 in [0, 10]'); + @include assert-equal(iro-math-clamp(3, 10, 20), 10, '3 in [10, 20]'); + @include assert-equal(iro-math-clamp(-5, -30, -10), -10, '-5 in [-30, -10]'); + @include assert-equal(iro-math-clamp(-5, -30, -2), -5, '-5 in [-30, -2]'); + } +} 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'); + } +} diff --git a/test/_responsive.scss b/test/_responsive.scss new file mode 100644 index 0000000..cdda40c --- /dev/null +++ b/test/_responsive.scss @@ -0,0 +1,9 @@ +@include describe('Responsive') { + @include it('iro-responsive-fluid-calc') { + $rem600px: iro-px-to-rem(600px); + $rem800px: iro-px-to-rem(800px); + + @include assert-equal(iro-responsive-fluid-calc(2rem, 4rem, 600px, 800px), 'calc(2rem + 2 * ((100vw - #{$rem600px}) / #{iro-strip-unit($rem800px - $rem600px)}))', 'Responsive value from 2rem to 4rem over 600px to 800px'); + @include assert-equal(iro-responsive-fluid-calc(4px, 12px, 600px, 800px), 'calc(4px + 8 * ((100vw - 600px) / 200))', 'Responsive value from 4px to 12px over 600px to 800px'); + } +} diff --git a/test/bem/_examples.scss b/test/bem/_examples.scss new file mode 100644 index 0000000..243ee35 --- /dev/null +++ b/test/bem/_examples.scss @@ -0,0 +1,224 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations no-empty-rulesets + +// +// Included test cases: +// - /// 1 /// - Media object +// - /// 2 /// - Tabs +/// - /// 3 /// - Accordion +// + +@include it('Examples') { + @include assert('Media object') { /// 1 /// + @include output { + @include iro-bem-object('media') { + display: flex; + align-items: flex-start; + justify-content: flex-start; + + @include iro-bem-element('image') { + display: block; + flex: 0 0 auto; + order: 1; + overflow: hidden; + } + + @include iro-bem-element('body') { + order: 2; + } + + @include iro-bem-modifier('rtl') { + justify-content: flex-end; + + @include iro-bem-element('image') { + order: 2; + } + + @include iro-bem-element('body') { + order: 1; + } + } + } + } + + @include expect { + .o-media { + display: flex; + align-items: flex-start; + justify-content: flex-start; + } + + .o-media__image { + display: block; + flex: 0 0 auto; + order: 1; + overflow: hidden; + } + + .o-media__body { + order: 2; + } + + .o-media--rtl { + justify-content: flex-end; + + .o-media__image { + order: 2; + } + + .o-media__body { + order: 1; + } + } + } + } + + @include assert('Tabs') { /// 2 /// + @include output { + @include iro-bem-component('tabs') { + position: relative; + + @include iro-bem-element('tab') { + float: left; + } + + @include iro-bem-element('tabRadio') { + position: absolute; + top: -9999px; + left: -9999px; + + &:checked { + @include iro-bem-sibling-element('tabLabel') { + font-weight: bold; + } + + @include iro-bem-sibling-element('tabContent') { + display: block; + } + } + } + + @include iro-bem-element('tabLabel') { + cursor: pointer; + + &:hover, + &:active { + text-decoration: underline; + } + } + + @include iro-bem-element('tabContent') { + position: absolute; + left: 0; + display: none; + } + } + } + + @include expect { + .c-tabs { + position: relative; + } + + .c-tabs__tab { + float: left; + } + + .c-tabs__tabRadio { + position: absolute; + top: -9999px; + left: -9999px; + } + + .c-tabs__tabRadio:checked ~ .c-tabs__tabLabel { + font-weight: bold; + } + + .c-tabs__tabRadio:checked ~ .c-tabs__tabContent { + display: block; + } + + .c-tabs__tabLabel { + cursor: pointer; + } + + .c-tabs__tabLabel:hover, + .c-tabs__tabLabel:active { + text-decoration: underline; + } + + .c-tabs__tabContent { + position: absolute; + left: 0; + display: none; + } + } + } + + @include assert('Accordion') { /// 3 /// + @include output { + @include iro-bem-component('accordion') { + @include iro-bem-element('section') { + // nothing to do + } + + @include iro-bem-element('sectionCheckbox') { + position: absolute; + top: -9999px; + left: -9999px; + + &:checked { + @include iro-bem-sibling-element('sectionLabel') { + font-weight: bold; + } + + @include iro-bem-sibling-element('sectionContent') { + display: block; + } + } + } + + @include iro-bem-element('sectionLabel') { + cursor: pointer; + + &:hover, + &:active { + text-decoration: underline; + } + } + + @include iro-bem-element('sectionContent') { + display: none; + } + } + } + + @include expect { + .c-accordion__sectionCheckbox { + position: absolute; + top: -9999px; + left: -9999px; + } + + .c-accordion__sectionCheckbox:checked ~ .c-accordion__sectionLabel { + font-weight: bold; + } + + .c-accordion__sectionCheckbox:checked ~ .c-accordion__sectionContent { + display: block; + } + + .c-accordion__sectionLabel { + cursor: pointer; + } + + .c-accordion__sectionLabel:hover, + .c-accordion__sectionLabel:active { + text-decoration: underline; + } + + .c-accordion__sectionContent { + display: none; + } + } + } +} diff --git a/test/bem/_iro-bem-at-theme.scss b/test/bem/_iro-bem-at-theme.scss new file mode 100644 index 0000000..d2d0696 --- /dev/null +++ b/test/bem/_iro-bem-at-theme.scss @@ -0,0 +1,55 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - single theme +// - /// 2 /// - with sub-theme +// + +@include it('iro-bem-at-theme') { + @include assert('single theme') { /// 1 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-at-theme('theme') { + font-size: 2em; + } + } + } + + @include expect(false) { + .t-theme .something, + [class*=' t-'] .t-theme .something, + [class^='t-'] .t-theme .something { + font-size: 2em; + } + } + } + + @include assert('with sub-theme') { /// 2 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-at-theme('theme') { + font-size: 2em; + } + + @include iro-bem-at-theme('theme', 'subtheme') { + font-size: 3em; + } + } + } + + @include expect(false) { + .t-theme .something, + [class*=' t-'] .t-theme .something, + [class^='t-'] .t-theme .something { + font-size: 2em; + } + + .t-theme .t-subtheme .something, + [class*=' t-'] .t-theme .t-subtheme .something, + [class^='t-'] .t-theme .t-subtheme .something { + font-size: 3em; + } + } + } +} diff --git a/test/bem/_iro-bem-block.scss b/test/bem/_iro-bem-block.scss new file mode 100644 index 0000000..a93d803 --- /dev/null +++ b/test/bem/_iro-bem-block.scss @@ -0,0 +1,85 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - without namespace +// - /// 2 /// - with namespace +// - /// 3 /// - nested +// - /// 4 /// - within selector +// + +@include it('iro-bem-block') { + @include assert('without namespace') { /// 1 /// + @include output(false) { + @include iro-bem-block('something') { + font-size: 1em; + } + } + + @include expect(false) { + .something { + font-size: 1em; + } + } + } + + @each $ns in map-keys($iro-bem-namespaces) { + @include assert('with namespace "#{$ns}"') { /// 2 /// + @include output(false) { + @include iro-bem-block('something', $ns) { + font-size: 1em; + } + } + + @include expect(false) { + @if $ns != 'theme' { + .#{map-get($iro-bem-namespaces, $ns)}-something { + font-size: 1em; + } + } @else { + .t-something, + [class*=' t-'] .t-something, + [class^='t-'] .t-something { + font-size: 1em; + } + } + } + } + } + + @include assert('nested') { /// 3 /// + @include output(false) { + @include iro-bem-theme('theme') { + @include iro-bem-theme('subtheme') { + @include iro-bem-block('something') { + font-size: 2em; + } + } + } + } + + @include expect(false) { + .t-theme .t-subtheme .something, + [class*=' t-'] .t-theme .t-subtheme .something, + [class^='t-'] .t-theme .t-subtheme .something { + font-size: 2em; + } + } + } + + @include assert('within selector') { /// 4 /// + @include output(false) { + .sel { + @include iro-bem-block('something') { + font-size: 2em; + } + } + } + + @include expect(false) { + .sel .something { + font-size: 2em; + } + } + } +} diff --git a/test/bem/_iro-bem-composed-of.scss b/test/bem/_iro-bem-composed-of.scss new file mode 100644 index 0000000..e724eb8 --- /dev/null +++ b/test/bem/_iro-bem-composed-of.scss @@ -0,0 +1,149 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - without namespace, single +// - /// 2 /// - with namespace, single +// - /// 3 /// - without namespace, multiple +// - /// 4 /// - with namespace, multiple +// + +@include it('iro-bem-composed-of') { + @include assert('without namespace, single') { /// 1 /// + @include output(false) { + @include iro-bem-block('something') { + font-size: 1em; + } + + @include iro-bem-block('another') { + @include iro-bem-composed-of('something'); + + font-size: 2em; + } + } + + @include expect(false) { + .something { + font-size: 1em; + } + + .another { + font-size: 2em; + } + } + } + + @each $ns in map-keys($iro-bem-namespaces) { + @include assert('with namespace "#{$ns}", single') { /// 2 /// + @include output(false) { + @include iro-bem-block('something', $ns) { + font-size: 1em; + } + + @include iro-bem-block('another') { + @include iro-bem-composed-of('something' $ns); + + font-size: 2em; + } + } + + @include expect(false) { + @if $ns != 'theme' { + .#{map-get($iro-bem-namespaces, $ns)}-something { + font-size: 1em; + } + } @else { + .t-something, + [class*=' t-'] .t-something, + [class^='t-'] .t-something { + font-size: 1em; + } + } + + .another { + font-size: 2em; + } + } + } + } + + @include assert('without namespace, multiple') { /// 3 /// + @include output(false) { + @include iro-bem-block('something') { + font-size: 1em; + } + + @include iro-bem-block('somethingElse') { + font-size: 1em; + } + + @include iro-bem-block('another') { + @include iro-bem-composed-of('something', 'somethingElse'); + + font-size: 2em; + } + } + + @include expect(false) { + .something { + font-size: 1em; + } + + .somethingElse { + font-size: 1em; + } + + .another { + font-size: 2em; + } + } + } + + @each $ns in map-keys($iro-bem-namespaces) { + @include assert('with namespace "#{$ns}", multiple') { /// 4 /// + @include output(false) { + @include iro-bem-block('something', $ns) { + font-size: 1em; + } + + @include iro-bem-block('somethingElse', $ns) { + font-size: 1em; + } + + @include iro-bem-block('another') { + @include iro-bem-composed-of('something' $ns, 'somethingElse' $ns); + + font-size: 2em; + } + } + + @include expect(false) { + @if $ns != 'theme' { + .#{map-get($iro-bem-namespaces, $ns)}-something { + font-size: 1em; + } + + .#{map-get($iro-bem-namespaces, $ns)}-somethingElse { + font-size: 1em; + } + } @else { + .t-something, + [class*=' t-'] .t-something, + [class^='t-'] .t-something { + font-size: 1em; + } + + .t-somethingElse, + [class*=' t-'] .t-somethingElse, + [class^='t-'] .t-somethingElse { + font-size: 1em; + } + } + + .another { + font-size: 2em; + } + } + } + } +} diff --git a/test/bem/_iro-bem-element.scss b/test/bem/_iro-bem-element.scss new file mode 100644 index 0000000..f69f133 --- /dev/null +++ b/test/bem/_iro-bem-element.scss @@ -0,0 +1,491 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - single element +// - /// 2 /// - single element, manual selector in-between +// - /// 3 /// - single element, modifier in-between +// - /// 4 /// - single element, nested +// - /// 5 /// - single element, nested, manual selector in-between +// - /// 6 /// - single element, nested, modifier in-between +// - /// 7 /// - single element, in at-theme +// - /// 8 /// - multiple elements +// - /// 9 /// - multiple elements, manual selector in-between +// - /// 10 /// - multiple elements, modifier in-between +// - /// 11 /// - multiple elements, nested +// - /// 12 /// - multiple elements, nested, manual selector in-between +// - /// 13 /// - multiple elements, nested, modifier in-between +// - /// 14 /// - single element, in at-theme +// + +@include it('iro-bem-element') { + @include assert('single element') { /// 1 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + font-size: 2em; + } + } + } + + @include expect { + .something__child { + font-size: 2em; + } + } + } + + @include assert('single element, manual selector in-between') { /// 2 /// + @include output(false) { + @include iro-bem-block('something') { + &:hover { + @include iro-bem-element('child1') { + font-size: 2em; + } + } + + .test & { + @include iro-bem-element('child2') { + font-size: 2em; + } + } + } + } + + @include expect(false) { + .something:hover .something__child1 { + font-size: 2em; + } + + .test .something__child2 { + font-size: 2em; + } + } + } + + @include assert('single element, modifier in-between') { /// 3 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod') { + @include iro-bem-element('child') { + font-size: 2em; + } + } + } + } + + @include expect { + .something--mod .something__child { + font-size: 2em; + } + } + } + + @include assert('single element, nested') { /// 4 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + font-size: 2em; + + @include iro-bem-element('subchild') { + font-size: 3em; + } + } + } + } + + @include expect { + .something__child { + font-size: 2em; + } + + .something__child .something__subchild { + font-size: 3em; + } + } + } + + @include assert('single element, nested, manual selector in-between') { /// 5 /// + @include output(false) { + @include iro-bem-block('something') { + &:hover { + @include iro-bem-element('child1') { + font-size: 2em; + + @include iro-bem-element('subchild1') { + font-size: 3em; + } + } + } + + .test & { + @include iro-bem-element('child2') { + font-size: 2em; + + @include iro-bem-element('subchild2') { + font-size: 3em; + } + } + } + + @include iro-bem-element('child3') { + font-size: 2em; + + &:hover { + @include iro-bem-element('subchild3') { + font-size: 3em; + } + } + + .test & { + @include iro-bem-element('subchild4') { + font-size: 3em; + } + } + } + } + } + + @include expect(false) { + .something:hover .something__child1 { + font-size: 2em; + } + + .something:hover .something__child1 .something__subchild1 { + font-size: 3em; + } + + .test .something__child2 { + font-size: 2em; + } + + .test .something__child2 .something__subchild2 { + font-size: 3em; + } + + .something__child3 { + font-size: 2em; + } + + .something__child3:hover .something__subchild3 { + font-size: 3em; + } + + .test .something__child3 .something__subchild4 { + font-size: 3em; + } + } + } + + @include assert('single element, nested, modifier in-between') { /// 6 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod') { + @include iro-bem-element('child') { + font-size: 2em; + + @include iro-bem-element('subchild') { + font-size: 3em; + } + } + } + + @include iro-bem-element('child') { + font-size: 2em; + + @include iro-bem-modifier('mod') { + @include iro-bem-element('subchild') { + font-size: 3em; + } + } + } + } + } + + @include expect { + .something--mod .something__child { + font-size: 2em; + } + + .something--mod .something__child .something__subchild { + font-size: 3em; + } + + .something__child { + font-size: 2em; + } + + .something__child--mod .something__subchild { + font-size: 3em; + } + } + } + + @include assert('single element, in at-theme') { /// 7 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-at-theme('dark') { + @include iro-bem-element('child') { + font-size: 2em; + } + } + } + } + + @include expect(false) { + .t-dark .something__child, + [class*=' t-'] .t-dark .something__child, + [class^='t-'] .t-dark .something__child { + font-size: 2em; + } + } + } + + @include assert('multiple elements') { /// 8 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + font-size: 2em; + } + } + } + + @include expect { + .something__child1, + .something__child2 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, manual selector in-between') { /// 9 /// + @include output(false) { + @include iro-bem-block('something') { + &:hover { + @include iro-bem-element('child1', 'child2') { + font-size: 2em; + } + } + + .test & { + @include iro-bem-element('child3', 'child4') { + font-size: 2em; + } + } + } + } + + @include expect(false) { + .something:hover .something__child1, + .something:hover .something__child2 { + font-size: 2em; + } + + .test .something__child3, + .test .something__child4 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, modifier in-between') { /// 10 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod') { + @include iro-bem-element('child1', 'child2') { + font-size: 2em; + } + } + } + } + + @include expect { + .something--mod .something__child1, + .something--mod .something__child2 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, nested') { /// 11 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + font-size: 2em; + + @include iro-bem-element('subchild1') { + font-size: 3em; + } + } + + @include iro-bem-element('child3') { + font-size: 2em; + + @include iro-bem-element('subchild2', 'subchild3') { + font-size: 3em; + } + } + } + } + + @include expect { + .something__child1, + .something__child2 { + font-size: 2em; + } + + .something__child1 .something__subchild1, + .something__child2 .something__subchild1 { + font-size: 3em; + } + + .something__child3 { + font-size: 2em; + } + + .something__child3 .something__subchild2, + .something__child3 .something__subchild3 { + font-size: 3em; + } + } + } + + @include assert('multiple elements, nested, manual selector in-between') { /// 12 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + font-size: 2em; + + &:hover { + @include iro-bem-element('subchild1') { + font-size: 3em; + } + } + + .test & { + @include iro-bem-element('subchild2') { + font-size: 3em; + } + } + } + + @include iro-bem-element('child3') { + font-size: 2em; + + &:hover { + @include iro-bem-element('subchild3', 'subchild4') { + font-size: 3em; + } + } + + .test & { + @include iro-bem-element('subchild5', 'subchild6') { + font-size: 3em; + } + } + } + } + } + + @include expect(false) { + .something__child1, + .something__child2 { + font-size: 2em; + } + + .something__child1:hover .something__subchild1, + .something__child2:hover .something__subchild1 { + font-size: 3em; + } + + .test .something__child1 .something__subchild2, + .test .something__child2 .something__subchild2 { + font-size: 3em; + } + + .something__child3 { + font-size: 2em; + } + + .something__child3:hover .something__subchild3, + .something__child3:hover .something__subchild4 { + font-size: 3em; + } + + .test .something__child3 .something__subchild5, + .test .something__child3 .something__subchild6 { + font-size: 3em; + } + } + } + + @include assert('multiple elements, nested, modifier in-between') { /// 13 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + font-size: 2em; + + @include iro-bem-modifier('mod') { + @include iro-bem-element('subchild1') { + font-size: 3em; + } + } + } + + @include iro-bem-element('child3') { + font-size: 2em; + + @include iro-bem-modifier('mod') { + @include iro-bem-element('subchild2', 'subchild3') { + font-size: 3em; + } + } + } + } + } + + @include expect { + .something__child1, + .something__child2 { + font-size: 2em; + } + + .something__child1--mod .something__subchild1, + .something__child2--mod .something__subchild1 { + font-size: 3em; + } + + .something__child3 { + font-size: 2em; + } + + .something__child3--mod .something__subchild2, + .something__child3--mod .something__subchild3 { + font-size: 3em; + } + } + } + + @include assert('multiple elements, in at-theme') { /// 14 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-at-theme('dark') { + @include iro-bem-element('child1', 'child2') { + font-size: 2em; + } + } + } + } + + @include expect(false) { + .t-dark .something__child1, + [class*=' t-'] .t-dark .something__child1, + [class^='t-'] .t-dark .something__child1, + .t-dark .something__child2, + [class*=' t-'] .t-dark .something__child2, + [class^='t-'] .t-dark .something__child2 { + font-size: 2em; + } + } + } +} diff --git a/test/bem/_iro-bem-modifier.scss b/test/bem/_iro-bem-modifier.scss new file mode 100644 index 0000000..60e2fe4 --- /dev/null +++ b/test/bem/_iro-bem-modifier.scss @@ -0,0 +1,654 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - block modifier +// - /// 2 /// - block modifier, in at-theme +// - /// 3 /// - element modifier, single element +// - /// 4 /// - element modifier, multiple elements +// - /// 5 /// - element modifier, single related element +// - /// 6 /// - element modifier, multiple related elements +// - /// 7 /// - element modifier, single element, manual selector before +// - /// 8 /// - element modifier, multiple elements, manual selector before +// - /// 9 /// - element modifier, single related element, manual selector before +// - /// 10 /// - element modifier, multiple related elements, manual selector before +// - /// 11 /// - element modifier, in at-theme +// - /// 12 /// - nested block modifiers, extending +// - /// 13 /// - nested element modifiers, extending +// - /// 14 /// - block and element modifiers, single element +// - /// 15 /// - block and element modifiers, multiple elements +// + +@include it('iro-bem-modifier') { + @include assert('block modifier') { /// 1 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod') { + font-size: 1.5em; + + @include iro-bem-modifier('submod') { + font-size: 1.75em; + } + } + } + } + + @include expect { + .something--mod { + font-size: 1.5em; + } + + .something--mod.something--submod { + font-size: 1.75em; + } + } + } + + @include assert('block modifier, in at-theme') { /// 2 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-at-theme('dark') { + @include iro-bem-modifier('mod') { + font-size: 1.5em; + + @include iro-bem-modifier('submod') { + font-size: 1.75em; + } + } + } + } + } + + @include expect(false) { + .t-dark .something--mod, + [class*=' t-'] .t-dark .something--mod, + [class^='t-'] .t-dark .something--mod { + font-size: 1.5em; + } + + .t-dark .something--mod.something--submod, + [class*=' t-'] .t-dark .something--mod.something--submod, + [class^='t-'] .t-dark .something--mod.something--submod { + font-size: 1.75em; + } + } + } + + @include assert('element modifier, single element') { /// 3 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + } + + @include expect { + .something__child--mod { + font-size: 2.5em; + } + + .something__child--mod.something__child--submod { + font-size: 2.75em; + } + } + } + + @include assert('element modifier, multiple elements') { /// 4 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + } + + @include expect { + .something__child1--mod, + .something__child2--mod { + font-size: 2.5em; + } + + .something__child1--mod.something__child1--submod, + .something__child2--mod.something__child2--submod { + font-size: 2.75em; + } + } + } + + @include assert('element modifier, single related element') { /// 5 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1') { + @include iro-bem-next-element('child2') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + } + } + + @include expect { + .something__child1 + .something__child2--mod { + font-size: 2.5em; + } + + .something__child1 + .something__child2--mod.something__child2--submod { + font-size: 2.75em; + } + } + } + + @include assert('element modifier, multiple related elements') { /// 6 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1') { + @include iro-bem-next-element('child2', 'child3') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + } + } + + @include expect { + .something__child1 + .something__child2--mod, + .something__child1 + .something__child3--mod { + font-size: 2.5em; + } + + .something__child1 + .something__child2--mod.something__child2--submod, + .something__child1 + .something__child3--mod.something__child3--submod { + font-size: 2.75em; + } + } + } + + @include assert('element modifier, single element, manual selector before') { /// 7 /// + @include output(false) { + @include iro-bem-block('something') { + &:hover { + @include iro-bem-element('child1') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + + .test & { + @include iro-bem-element('child2') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + } + } + + @include expect(false) { + .something:hover .something__child1--mod { + font-size: 2.5em; + } + + .something:hover .something__child1--mod.something__child1--submod { + font-size: 2.75em; + } + + .test .something__child2--mod { + font-size: 2.5em; + } + + .test .something__child2--mod.something__child2--submod { + font-size: 2.75em; + } + } + } + + @include assert('element modifier, multiple elements, manual selector before') { /// 8 /// + @include output(false) { + @include iro-bem-block('something') { + &:hover { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + + .test & { + @include iro-bem-element('child3', 'child4') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + } + } + + @include expect(false) { + .something:hover .something__child1--mod, + .something:hover .something__child2--mod { + font-size: 2.5em; + } + + .something:hover .something__child1--mod.something__child1--submod, + .something:hover .something__child2--mod.something__child2--submod { + font-size: 2.75em; + } + + .test .something__child3--mod, + .test .something__child4--mod { + font-size: 2.5em; + } + + .test .something__child3--mod.something__child3--submod, + .test .something__child4--mod.something__child4--submod { + font-size: 2.75em; + } + } + } + + @include assert('element modifier, single related element, manual selector before') { /// 9 /// + @include output(false) { + @include iro-bem-block('something') { + &:hover { + @include iro-bem-element('child1') { + @include iro-bem-next-element('child2') { + @include iro-bem-modifier('mod1') { + font-size: 2.5em; + + @include iro-bem-modifier('submod1') { + font-size: 2.75em; + } + } + } + } + } + + .test & { + @include iro-bem-element('child3') { + @include iro-bem-next-element('child4') { + @include iro-bem-modifier('mod1') { + font-size: 2.5em; + + @include iro-bem-modifier('submod1') { + font-size: 2.75em; + } + } + } + } + } + + @include iro-bem-element('child5') { + &:hover { + @include iro-bem-next-element('child6') { + @include iro-bem-modifier('mod2') { + font-size: 2.5em; + + @include iro-bem-modifier('submod2') { + font-size: 2.75em; + } + } + } + } + + .test & { + @include iro-bem-next-element('child7') { + @include iro-bem-modifier('mod2') { + font-size: 2.5em; + + @include iro-bem-modifier('submod2') { + font-size: 2.75em; + } + } + } + } + } + } + } + + @include expect(false) { + .something:hover .something__child1 + .something__child2--mod1 { + font-size: 2.5em; + } + + .something:hover .something__child1 + .something__child2--mod1.something__child2--submod1 { + font-size: 2.75em; + } + + .test .something__child3 + .something__child4--mod1 { + font-size: 2.5em; + } + + .test .something__child3 + .something__child4--mod1.something__child4--submod1 { + font-size: 2.75em; + } + + .something__child5:hover + .something__child6--mod2 { + font-size: 2.5em; + } + + .something__child5:hover + .something__child6--mod2.something__child6--submod2 { + font-size: 2.75em; + } + + .test .something__child5 + .something__child7--mod2 { + font-size: 2.5em; + } + + .test .something__child5 + .something__child7--mod2.something__child7--submod2 { + font-size: 2.75em; + } + } + } + + @include assert('element modifier, multiple related elements, manual selector before') { /// 10 /// + @include output(false) { + @include iro-bem-block('something') { + &:hover { + @include iro-bem-element('child1') { + @include iro-bem-next-element('child2', 'child3') { + @include iro-bem-modifier('mod1') { + font-size: 2.5em; + + @include iro-bem-modifier('submod1') { + font-size: 2.75em; + } + } + } + } + } + + .test & { + @include iro-bem-element('child4') { + @include iro-bem-next-element('child5', 'child6') { + @include iro-bem-modifier('mod1') { + font-size: 2.5em; + + @include iro-bem-modifier('submod1') { + font-size: 2.75em; + } + } + } + } + } + + @include iro-bem-element('child7') { + &:hover { + @include iro-bem-next-element('child8', 'child9') { + @include iro-bem-modifier('mod2') { + font-size: 2.5em; + + @include iro-bem-modifier('submod2') { + font-size: 2.75em; + } + } + } + } + + .test & { + @include iro-bem-next-element('child10', 'child11') { + @include iro-bem-modifier('mod2') { + font-size: 2.5em; + + @include iro-bem-modifier('submod2') { + font-size: 2.75em; + } + } + } + } + } + } + } + + @include expect(false) { + .something:hover .something__child1 + .something__child2--mod1, + .something:hover .something__child1 + .something__child3--mod1 { + font-size: 2.5em; + } + + .something:hover .something__child1 + .something__child2--mod1.something__child2--submod1, + .something:hover .something__child1 + .something__child3--mod1.something__child3--submod1 { + font-size: 2.75em; + } + + .test .something__child4 + .something__child5--mod1, + .test .something__child4 + .something__child6--mod1 { + font-size: 2.5em; + } + + .test .something__child4 + .something__child5--mod1.something__child5--submod1, + .test .something__child4 + .something__child6--mod1.something__child6--submod1 { + font-size: 2.75em; + } + + .something__child7:hover + .something__child8--mod2, + .something__child7:hover + .something__child9--mod2 { + font-size: 2.5em; + } + + .something__child7:hover + .something__child8--mod2.something__child8--submod2, + .something__child7:hover + .something__child9--mod2.something__child9--submod2 { + font-size: 2.75em; + } + + .test .something__child7 + .something__child10--mod2, + .test .something__child7 + .something__child11--mod2 { + font-size: 2.5em; + } + + .test .something__child7 + .something__child10--mod2.something__child10--submod2, + .test .something__child7 + .something__child11--mod2.something__child11--submod2 { + font-size: 2.75em; + } + } + } + + /* + @include assert('element modifier, in at-theme') { /// 11 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-at-theme('dark') { + @include iro-bem-element('child') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod') { + font-size: 2.75em; + } + } + } + } + } + } + + @include expect(false) { + .t-dark .something__child--mod, + [class*=' t-'] .t-dark .something__child--mod, + [class^='t-'] .t-dark .something__child--mod { + font-size: 2.5em; + } + + .t-dark .something__child--mod.something__child--submod, + [class*=' t-'] .t-dark .something__child--mod.something__child--submod, + [class^='t-'] .t-dark .something__child--mod.something__child--submod { + font-size: 2.75em; + } + } + } + */ + + @include assert('nested block modifiers, extending') { /// 12 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod') { + font-size: 1.5em; + + @include iro-bem-modifier('submod' true) { + font-size: 1.75em; + } + } + } + } + + @include expect { + .something--mod { + font-size: 1.5em; + } + + .something--mod--submod { + font-size: 1.75em; + } + } + } + + @include assert('nested element modifiers, extending') { /// 13 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-modifier('mod') { + font-size: 2.5em; + + @include iro-bem-modifier('submod' true) { + font-size: 2.75em; + } + } + } + } + } + + @include expect { + .something__child--mod { + font-size: 2.5em; + } + + .something__child--mod--submod { + font-size: 2.75em; + } + } + } + + @include assert('block and element modifiers, single element') { /// 14 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod1') { + font-size: 1.5em; + + @include iro-bem-modifier('submod1') { + font-size: 1.75em; + } + + @include iro-bem-element('child') { + @include iro-bem-modifier('mod2') { + font-size: 2.5em; + + @include iro-bem-modifier('submod2') { + font-size: 2.75em; + } + } + } + } + } + } + + @include expect { + .something--mod1 { + font-size: 1.5em; + } + + .something--mod1.something--submod1 { + font-size: 1.75em; + } + + .something--mod1 .something__child--mod2 { + font-size: 2.5em; + } + + .something--mod1 .something__child--mod2.something__child--submod2 { + font-size: 2.75em; + } + } + } + + @include assert('block and element modifiers, multiple elements') { /// 15 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod1') { + font-size: 1.5em; + + @include iro-bem-modifier('submod') { + font-size: 1.75em; + } + + @include iro-bem-element('child1', 'child2') { + @include iro-bem-modifier('mod2') { + font-size: 2.5em; + + @include iro-bem-modifier('submod2') { + font-size: 2.75em; + } + } + } + } + } + } + + @include expect { + .something--mod1 { + font-size: 1.5em; + } + + .something--mod1.something--submod1 { + font-size: 1.75em; + } + + .something--mod1 .something__child1--mod2, + .something--mod1 .something__child2--mod2 { + font-size: 2.5em; + } + + .something--mod1 .something__child1--mod2.something__child1--submod2, + .something--mod1 .something__child2--mod2.something__child2--submod2 { + font-size: 2.75em; + } + } + } +} diff --git a/test/bem/_iro-bem-multi.scss b/test/bem/_iro-bem-multi.scss new file mode 100644 index 0000000..84bbca2 --- /dev/null +++ b/test/bem/_iro-bem-multi.scss @@ -0,0 +1,591 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - in root, 2 blocks +// - /// 2 /// - in root, 1 block, 1 manual selector +// - /// 3 /// - in block, 2 elements +// - /// 4 /// - in block, 1 element, 1 modifier +// - /// 5 /// - in block, 1 element, 1 extending modifier +// - /// 6 /// - in block, 1 element, 1 & selector +// - /// 7 /// - in block, 1 element, 1 manual selector +// - /// 8 /// - in element, 2 elements, 1 modifier +// - /// 9 /// - in element, 1 element, 1 & selector +// - /// 10 /// - in element in manual selector, 2 elements +// - /// 11 /// - in element in manual selector, 1 element, 1 & selector +// - /// 12 /// - in multiple elements, 2 elements, 1 modifier +// - /// 13 /// - in multiple elements, 1 element, 1 & selector +// - /// 14 /// - in related elements, 2 elements, 1 modifier +// - /// 15 /// - in related elements, 1 element, 1 & selector +// - /// 16 /// - in element, 2 related elements, 1 modifier +// - /// 17 /// - in element, 1 twin element, 1 modifier +// - /// 18 /// - in multiple elements, 1 twin element, 1 modifier +// + +@include it('iro-bem-state') { + @include assert('in root, 2 blocks') { /// 1 /// + @include output { + @include iro-bem-multi('component:' 'block1', 'object:' 'block2') { + font-size: 1em; + + @include iro-bem-element('child2') { + font-size: 2em; + } + } + } + + @include expect { + .c-block1 { + font-size: 1em; + } + + .c-block1__child2 { + font-size: 2em; + } + + .o-block2 { + font-size: 1em; + } + + .o-block2__child2 { + font-size: 2em; + } + } + } + + @include assert('in root, 1 block, 1 manual selector') { /// 2 /// + @include output { + @include iro-bem-multi('component:' 'block1', 'a:hover') { + font-size: 1em; + } + } + + @include expect { + .c-block1 { + font-size: 1em; + } + + a:hover { + font-size: 1em; + } + } + } + + @include assert('in block, 2 elements') { /// 3 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-multi('element:' 'child1' 'child2') { + font-size: 2em; + + @include iro-bem-modifier('mod') { + font-size: 2.5em; + } + } + } + } + + @include expect { + .something__child1, + .something__child2 { + font-size: 2em; + } + + .something__child1--mod, + .something__child2--mod { + font-size: 2.5em; + } + } + } + + @include assert('in block, 1 element, 1 modifier') { /// 4 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-multi('element:' 'child', 'modifier:' 'mod1') { + font-size: 2em; + + @include iro-bem-modifier('mod2') { + font-size: 2.5em; + } + } + } + } + + @include expect { + .something__child { + font-size: 2em; + } + + .something__child--mod2 { + font-size: 2.5em; + } + + .something--mod1 { + font-size: 2em; + } + + .something--mod1.something--mod2 { + font-size: 2.5em; + } + } + } + + @include assert('in block, 1 element, 1 extending modifier') { /// 5 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-multi('element:' 'child', 'modifier:' 'mod1') { + font-size: 2em; + + @include iro-bem-modifier('mod2' true) { + font-size: 2.5em; + } + } + } + } + + @include expect { + .something__child { + font-size: 2em; + } + + .something__child--mod2 { + font-size: 2.5em; + } + + .something--mod1 { + font-size: 2em; + } + + .something--mod1--mod2 { + font-size: 2.5em; + } + } + } + + @include assert('in block, 1 element, 1 & selector') { /// 6 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-multi('&', 'element:' 'child') { + font-size: 2em; + + @include iro-bem-modifier('mod') { + font-size: 2.5em; + } + } + } + } + + @include expect { + .something { + font-size: 2em; + } + + .something--mod { + font-size: 2.5em; + } + + .something__child { + font-size: 2em; + } + + .something__child--mod { + font-size: 2.5em; + } + } + } + + @include assert('in block, 1 element, 1 manual selector') { /// 7 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-multi('> a:hover', 'element:' 'child1') { + font-size: 2em; + + @include iro-bem-element('child2') { + font-size: 3em; + } + } + } + } + + @include expect { + .something > a:hover { + font-size: 2em; + } + + .something > a:hover .something__child2 { + font-size: 3em; + } + + .something__child1 { + font-size: 2em; + } + + .something__child1 .something__child2 { + font-size: 3em; + } + } + } + + @include assert('in element, 2 elements, 1 modifier') { /// 8 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-multi('element:' 'subchild1' 'subchild2', 'modifier:' 'mod1') { + font-size: 3em; + + @include iro-bem-modifier('mod2') { + font-size: 3.5em; + } + } + } + } + } + + @include expect { + .something__child .something__subchild1, + .something__child .something__subchild2 { + font-size: 3em; + } + + .something__child .something__subchild1--mod2, + .something__child .something__subchild2--mod2 { + font-size: 3.5em; + } + + .something__child--mod1 { + font-size: 3em; + } + + .something__child--mod1.something__child--mod2 { + font-size: 3.5em; + } + } + } + + @include assert('in element, 1 element, 1 & selector') { /// 9 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-multi('element:' 'subchild', '&') { + font-size: 3em; + + @include iro-bem-modifier('mod') { + font-size: 3.5em; + } + } + } + } + } + + @include expect { + .something__child .something__subchild { + font-size: 3em; + } + + .something__child .something__subchild--mod { + font-size: 3.5em; + } + + .something__child { + font-size: 3em; + } + + .something__child--mod { + font-size: 3.5em; + } + } + } + + @include assert('in element in manual selector, 2 elements') { /// 10 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + &:hover { + @include iro-bem-multi('element:' 'subchild1' 'subchild2') { + font-size: 3em; + + @include iro-bem-modifier('mod2') { + font-size: 3.5em; + } + } + } + } + } + } + + @include expect { + .something__child:hover .something__subchild1, + .something__child:hover .something__subchild2 { + font-size: 3em; + } + + .something__child:hover .something__subchild1--mod2, + .something__child:hover .something__subchild2--mod2 { + font-size: 3.5em; + } + } + } + + @include assert('in element in manual selector, 1 element, 1 & selector') { /// 11 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + &:hover { + @include iro-bem-multi('element:' 'subchild', '&') { + font-size: 3em; + } + } + } + } + } + + @include expect { + .something__child:hover .something__subchild { + font-size: 3em; + } + + .something__child:hover { + font-size: 3em; + } + } + } + + @include assert('in multiple elements, 2 elements, 1 modifier') { /// 12 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-multi('element:' 'subchild1' 'subchild2', 'modifier:' 'mod') { + font-size: 3em; + } + } + } + } + + @include expect { + .something__child1 .something__subchild1, + .something__child2 .something__subchild1, + .something__child1 .something__subchild2, + .something__child2 .something__subchild2 { + font-size: 3em; + } + + .something__child1--mod, + .something__child2--mod { + font-size: 3em; + } + } + } + + @include assert('in multiple elements, 1 element, 1 & selector') { /// 13 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-multi('element:' 'subchild', '&') { + font-size: 3em; + + @include iro-bem-modifier('mod') { + font-size: 3.5em; + } + } + } + } + } + + @include expect { + .something__child1 .something__subchild, + .something__child2 .something__subchild { + font-size: 3em; + } + + .something__child1 .something__subchild--mod, + .something__child2 .something__subchild--mod { + font-size: 3.5em; + } + + .something__child1, + .something__child2 { + font-size: 3em; + } + + .something__child1--mod, + .something__child2--mod { + font-size: 3.5em; + } + } + } + + @include assert('in related elements, 2 elements, 1 modifier') { /// 14 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1') { + @include iro-bem-next-element('child2', 'child3') { + @include iro-bem-multi('element:' 'subchild1' 'subchild2', 'modifier:' 'mod') { + font-size: 3em; + } + } + } + } + } + + @include expect { + .something__child1 + .something__child2 .something__subchild1, + .something__child1 + .something__child3 .something__subchild1, + .something__child1 + .something__child2 .something__subchild2, + .something__child1 + .something__child3 .something__subchild2 { + font-size: 3em; + } + + .something__child1 + .something__child2--mod, + .something__child1 + .something__child3--mod { + font-size: 3em; + } + } + } + + @include assert('in related elements, 1 element, 1 & selector') { /// 15 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1') { + @include iro-bem-next-element('child2', 'child3') { + @include iro-bem-multi('element:' 'subchild', '&') { + font-size: 4em; + + @include iro-bem-modifier('mod') { + font-size: 4.5em; + } + } + } + } + } + } + + @include expect { + .something__child1 + .something__child2 .something__subchild, + .something__child1 + .something__child3 .something__subchild { + font-size: 4em; + } + + .something__child1 + .something__child2 .something__subchild--mod, + .something__child1 + .something__child3 .something__subchild--mod { + font-size: 4.5em; + } + + .something__child1 + .something__child2, + .something__child1 + .something__child3 { + font-size: 4em; + } + + .something__child1 + .something__child2--mod, + .something__child1 + .something__child3--mod { + font-size: 4.5em; + } + } + } + + @include assert('in element, 2 related elements, 1 modifier') { /// 16 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1') { + @include iro-bem-multi('next-element:' 'child2' 'child3', 'modifier:' 'mod1') { + font-size: 3em; + + @include iro-bem-modifier('mod2') { + font-size: 3.5em; + } + } + } + } + } + + @include expect { + .something__child1 + .something__child2, + .something__child1 + .something__child3 { + font-size: 3em; + } + + .something__child1 + .something__child2--mod2, + .something__child1 + .something__child3--mod2 { + font-size: 3.5em; + } + + .something__child1--mod1 { + font-size: 3em; + } + + .something__child1--mod1.something__child1--mod2 { + font-size: 3.5em; + } + } + } + + @include assert('in element, 1 twin element, 1 modifier') { /// 17 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-multi('next-twin-element', 'modifier:' 'mod1') { + font-size: 3em; + + @include iro-bem-modifier('mod2') { + font-size: 3.5em; + } + } + } + } + } + + @include expect { + .something__child + .something__child { + font-size: 3em; + } + + .something__child + .something__child--mod2 { + font-size: 3.5em; + } + + .something__child--mod1 { + font-size: 3em; + } + + .something__child--mod1.something__child--mod2 { + font-size: 3.5em; + } + } + } + + @include assert('in multiple elements, 1 twin element, 1 modifier') { /// 18 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-multi('next-twin-element', 'modifier:' 'mod1') { + font-size: 3em; + + @include iro-bem-modifier('mod2') { + font-size: 3.5em; + } + } + } + } + } + + @include expect { + .something__child1 + .something__child1, + .something__child2 + .something__child2 { + font-size: 3em; + } + + .something__child1 + .something__child1--mod2, + .something__child2 + .something__child2--mod2 { + font-size: 3.5em; + } + + .something__child1--mod1, + .something__child2--mod1 { + font-size: 3em; + } + + .something__child1--mod1.something__child1--mod2, + .something__child2--mod1.something__child2--mod2 { + font-size: 3.5em; + } + } + } +} diff --git a/test/bem/_iro-bem-next-twin-element.scss b/test/bem/_iro-bem-next-twin-element.scss new file mode 100644 index 0000000..96fc3a9 --- /dev/null +++ b/test/bem/_iro-bem-next-twin-element.scss @@ -0,0 +1,153 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - single element +// - /// 2 /// - single element, manual selector in-between +// - /// 3 /// - single element, modifier in-between +// - /// 4 /// - multiple elements +// - /// 5 /// - multiple elements, manual selector in-between +// - /// 6 /// - multiple elements, modifier in-between +// + +@include it('iro-bem-next-twin-element') { + @include assert('single element') { /// 1 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-next-twin-element { + font-size: 2em; + } + } + } + } + + @include expect { + .something__child + .something__child { + font-size: 2em; + } + } + } + + @include assert('single element, manual selector in-between') { /// 2 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + &:hover { + @include iro-bem-next-twin-element { + font-size: 2em; + } + } + + .test & { + @include iro-bem-next-twin-element { + font-size: 2em; + } + } + } + } + } + + @include expect(false) { + .something__child:hover + .something__child { + font-size: 2em; + } + + .test .something__child + .something__child { + font-size: 2em; + } + } + } + + @include assert('single element, modifier in-between') { /// 3 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-modifier('mod') { + @include iro-bem-next-twin-element { + font-size: 2.5em; + } + } + } + } + } + + @include expect { + .something__child--mod + .something__child { + font-size: 2.5em; + } + } + } + + @include assert('multiple elements') { /// 4 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-next-twin-element { + font-size: 2em; + } + } + } + } + + @include expect { + .something__child1 + .something__child1, + .something__child2 + .something__child2 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, manual selector in-between') { /// 5 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + &:hover { + @include iro-bem-next-twin-element { + font-size: 2em; + } + } + + .test & { + @include iro-bem-next-twin-element { + font-size: 2em; + } + } + } + } + } + + @include expect(false) { + .something__child1:hover + .something__child1, + .something__child2:hover + .something__child2 { + font-size: 2em; + } + + .test .something__child1 + .something__child1, + .test .something__child2 + .something__child2 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, modifier in-between') { /// 6 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-modifier('mod') { + @include iro-bem-next-twin-element { + font-size: 2.5em; + } + } + } + } + } + + @include expect { + .something__child1--mod + .something__child1, + .something__child2--mod + .something__child2 { + font-size: 2.5em; + } + } + } +} diff --git a/test/bem/_iro-bem-related-element.scss b/test/bem/_iro-bem-related-element.scss new file mode 100644 index 0000000..b0c6b94 --- /dev/null +++ b/test/bem/_iro-bem-related-element.scss @@ -0,0 +1,459 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - single element, single related element +// - /// 2 /// - single element, single related element, manual selector in-between +// - /// 3 /// - single element, single related element, modifier in-between +// - /// 4 /// - single element, multiple related elements +// - /// 5 /// - single element, multiple related elements, manual selector in-between +// - /// 6 /// - single element, multiple related elements, modifier in-between +// - /// 7 /// - multiple elements, single related element +// - /// 8 /// - multiple elements, single related element, manual selector in-between +// - /// 9 /// - multiple elements, single related element, modifier in-between +// - /// 10 /// - multiple elements, multiple related elements +// - /// 11 /// - multiple elements, multiple related elements, manual selector in-between +// - /// 12 /// - multiple elements, multiple related elements, modifier in-between +// + +@include it('iro-bem-related-element') { + @include assert('single element, single related element') { /// 1 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-related-element('+', 'subchild1') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild2') { + font-size: 2em; + } + } + } + } + + @include expect { + .something__child + .something__subchild1 { + font-size: 2em; + } + + .something__child ~ .something__subchild2 { + font-size: 2em; + } + } + } + + @include assert('single element, single related element, manual selector in-between') { /// 2 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + &:hover { + @include iro-bem-related-element('+', 'subchild1') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild2') { + font-size: 2em; + } + } + + .test & { + @include iro-bem-related-element('+', 'subchild3') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild4') { + font-size: 2em; + } + } + } + } + } + + @include expect(false) { + .something__child:hover + .something__subchild1 { + font-size: 2em; + } + + .something__child:hover ~ .something__subchild2 { + font-size: 2em; + } + + .test .something__child + .something__subchild3 { + font-size: 2em; + } + + .test .something__child ~ .something__subchild4 { + font-size: 2em; + } + } + } + + @include assert('single element, single related element, modifier in-between') { /// 3 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-modifier('mod') { + @include iro-bem-related-element('+', 'subchild1') { + font-size: 2.5em; + } + + @include iro-bem-related-element('~', 'subchild2') { + font-size: 2.5em; + } + } + } + } + } + + @include expect { + .something__child--mod + .something__subchild1 { + font-size: 2.5em; + } + + .something__child--mod ~ .something__subchild2 { + font-size: 2.5em; + } + } + } + + @include assert('single element, multiple related elements') { /// 4 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-related-element('+', 'subchild1', 'subchild2') { + font-size: 2.5em; + } + + @include iro-bem-related-element('~', 'subchild3', 'subchild4') { + font-size: 2.5em; + } + } + } + } + + @include expect { + .something__child + .something__subchild1, + .something__child + .something__subchild2 { + font-size: 2.5em; + } + + .something__child ~ .something__subchild3, + .something__child ~ .something__subchild4 { + font-size: 2.5em; + } + } + } + + @include assert('single element, multiple related elements, manual selector in-between') { /// 5 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + &:hover { + @include iro-bem-related-element('+', 'subchild1', 'subchild2') { + font-size: 2.5em; + } + + @include iro-bem-related-element('~', 'subchild3', 'subchild4') { + font-size: 2.5em; + } + } + + .test & { + @include iro-bem-related-element('+', 'subchild5', 'subchild6') { + font-size: 2.5em; + } + + @include iro-bem-related-element('~', 'subchild7', 'subchild8') { + font-size: 2.5em; + } + } + } + } + } + + @include expect(false) { + .something__child:hover + .something__subchild1, + .something__child:hover + .something__subchild2 { + font-size: 2.5em; + } + + .something__child:hover ~ .something__subchild3, + .something__child:hover ~ .something__subchild4 { + font-size: 2.5em; + } + + .test .something__child + .something__subchild5, + .test .something__child + .something__subchild6 { + font-size: 2.5em; + } + + .test .something__child ~ .something__subchild7, + .test .something__child ~ .something__subchild8 { + font-size: 2.5em; + } + } + } + + @include assert('single element, multiple related elements, modifier in-between') { /// 6 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-modifier('mod') { + @include iro-bem-related-element('+', 'subchild1', 'subchild2') { + font-size: 2.5em; + } + + @include iro-bem-related-element('~', 'subchild3', 'subchild4') { + font-size: 2.5em; + } + } + } + } + } + + @include expect { + .something__child--mod + .something__subchild1, + .something__child--mod + .something__subchild2 { + font-size: 2.5em; + } + + .something__child--mod ~ .something__subchild3, + .something__child--mod ~ .something__subchild4 { + font-size: 2.5em; + } + } + } + + @include assert('multiple elements, single related element') { /// 7 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-related-element('+', 'subchild1') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild2') { + font-size: 2em; + } + } + } + } + + @include expect { + .something__child1 + .something__subchild1, + .something__child2 + .something__subchild1 { + font-size: 2em; + } + + .something__child1 ~ .something__subchild2, + .something__child2 ~ .something__subchild2 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, single related element, manual selector in-between') { /// 8 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + &:hover { + @include iro-bem-related-element('+', 'subchild1') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild2') { + font-size: 2em; + } + } + + .test & { + @include iro-bem-related-element('+', 'subchild3') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild4') { + font-size: 2em; + } + } + } + } + } + + @include expect(false) { + .something__child1:hover + .something__subchild1, + .something__child2:hover + .something__subchild1 { + font-size: 2em; + } + + .something__child1:hover ~ .something__subchild2, + .something__child2:hover ~ .something__subchild2 { + font-size: 2em; + } + + .test .something__child1 + .something__subchild3, + .test .something__child2 + .something__subchild3 { + font-size: 2em; + } + + .test .something__child1 ~ .something__subchild4, + .test .something__child2 ~ .something__subchild4 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, single related element, modifier in-between') { /// 9 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-modifier('mod') { + @include iro-bem-related-element('+', 'subchild1') { + font-size: 2.5em; + } + + @include iro-bem-related-element('~', 'subchild2') { + font-size: 2.5em; + } + } + } + } + } + + @include expect { + .something__child1--mod + .something__subchild1, + .something__child2--mod + .something__subchild1 { + font-size: 2.5em; + } + + .something__child1--mod ~ .something__subchild2, + .something__child2--mod ~ .something__subchild2 { + font-size: 2.5em; + } + } + } + + @include assert('multiple elements, multiple related elements') { /// 10 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-related-element('+', 'subchild1', 'subchild2') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild3', 'subchild4') { + font-size: 2em; + } + } + } + } + + @include expect { + .something__child1 + .something__subchild1, + .something__child2 + .something__subchild1, + .something__child1 + .something__subchild2, + .something__child2 + .something__subchild2 { + font-size: 2em; + } + + .something__child1 ~ .something__subchild3, + .something__child2 ~ .something__subchild3, + .something__child1 ~ .something__subchild4, + .something__child2 ~ .something__subchild4 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, multiple related elements, manual selector in-between') { /// 11 /// + @include output(false) { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + &:hover { + @include iro-bem-related-element('+', 'subchild1', 'subchild2') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild3', 'subchild4') { + font-size: 2em; + } + } + + .test & { + @include iro-bem-related-element('+', 'subchild5', 'subchild6') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild7', 'subchild8') { + font-size: 2em; + } + } + } + } + } + + @include expect(false) { + .something__child1:hover + .something__subchild1, + .something__child2:hover + .something__subchild1, + .something__child1:hover + .something__subchild2, + .something__child2:hover + .something__subchild2 { + font-size: 2em; + } + + .something__child1:hover ~ .something__subchild3, + .something__child2:hover ~ .something__subchild3, + .something__child1:hover ~ .something__subchild4, + .something__child2:hover ~ .something__subchild4 { + font-size: 2em; + } + + .test .something__child1 + .something__subchild5, + .test .something__child2 + .something__subchild5, + .test .something__child1 + .something__subchild6, + .test .something__child2 + .something__subchild6 { + font-size: 2em; + } + + .test .something__child1 ~ .something__subchild7, + .test .something__child2 ~ .something__subchild7, + .test .something__child1 ~ .something__subchild8, + .test .something__child2 ~ .something__subchild8 { + font-size: 2em; + } + } + } + + @include assert('multiple elements, multiple related elements, modifier in-between') { /// 12 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-modifier('mod') { + @include iro-bem-related-element('+', 'subchild1', 'subchild2') { + font-size: 2em; + } + + @include iro-bem-related-element('~', 'subchild3', 'subchild4') { + font-size: 2em; + } + } + } + } + } + + @include expect { + .something__child1--mod + .something__subchild1, + .something__child2--mod + .something__subchild1, + .something__child1--mod + .something__subchild2, + .something__child2--mod + .something__subchild2 { + font-size: 2em; + } + + .something__child1--mod ~ .something__subchild3, + .something__child2--mod ~ .something__subchild3, + .something__child1--mod ~ .something__subchild4, + .something__child2--mod ~ .something__subchild4 { + font-size: 2em; + } + } + } +} diff --git a/test/bem/_iro-bem-state.scss b/test/bem/_iro-bem-state.scss new file mode 100644 index 0000000..57eb233 --- /dev/null +++ b/test/bem/_iro-bem-state.scss @@ -0,0 +1,177 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - single block, single state +// - /// 2 /// - single element, single state +// - /// 3 /// - single block, multiple states +// - /// 4 /// - single element, multiple states +// - /// 5 /// - multiple elements, single state +// - /// 6 /// - multiple elements, multiple states +// + +@include it('iro-bem-state') { + @include assert('single block, single state') { /// 1 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-is('active') { + font-size: 1.25em; + } + + @include iro-bem-has('state') { + font-size: 1.75em; + } + } + } + + @include expect { + .something.is-active { + font-size: 1.25em; + } + + .something.has-state { + font-size: 1.75em; + } + } + } + + @include assert('single element, single state') { /// 2 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-is('active') { + font-size: 2.25em; + } + + @include iro-bem-has('state') { + font-size: 2.75em; + } + } + } + } + + @include expect { + .something__child.is-active { + font-size: 2.25em; + } + + .something__child.has-state { + font-size: 2.75em; + } + } + } + + @include assert('single block, multiple states') { /// 3 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-is('active', 'primary') { + font-size: 1.25em; + } + + @include iro-bem-has('state', 'indicator') { + font-size: 1.75em; + } + } + } + + @include expect { + .something.is-active, + .something.is-primary { + font-size: 1.25em; + } + + .something.has-state, + .something.has-indicator { + font-size: 1.75em; + } + } + } + + @include assert('single element, multiple states') { /// 4 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-is('active', 'primary') { + font-size: 2.25em; + } + + @include iro-bem-has('state', 'indicator') { + font-size: 2.75em; + } + } + } + } + + @include expect { + .something__child.is-active, + .something__child.is-primary { + font-size: 2.25em; + } + + .something__child.has-state, + .something__child.has-indicator { + font-size: 2.75em; + } + } + } + + @include assert('multiple elements, single state') { /// 5 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-is('active') { + font-size: 2.25em; + } + + @include iro-bem-has('state') { + font-size: 2.75em; + } + } + } + } + + @include expect { + .something__child1.is-active, + .something__child2.is-active { + font-size: 2.25em; + } + + .something__child1.has-state, + .something__child2.has-state { + font-size: 2.75em; + } + } + } + + @include assert('multiple elements, multiple states') { /// 6 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-is('active', 'primary') { + font-size: 2.25em; + } + + @include iro-bem-has('state', 'indicator') { + font-size: 2.75em; + } + } + } + } + + @include expect { + .something__child1.is-active, + .something__child2.is-active, + .something__child1.is-primary, + .something__child2.is-primary { + font-size: 2.25em; + } + + .something__child1.has-state, + .something__child2.has-state, + .something__child1.has-indicator, + .something__child2.has-indicator { + font-size: 2.75em; + } + } + } +} diff --git a/test/bem/_iro-bem-suffix.scss b/test/bem/_iro-bem-suffix.scss new file mode 100644 index 0000000..c6ca787 --- /dev/null +++ b/test/bem/_iro-bem-suffix.scss @@ -0,0 +1,94 @@ +// sass-lint:disable class-name-format force-element-nesting force-pseudo-nesting mixins-before-declarations + +// +// Included test cases: +// - /// 1 /// - block suffix +// - /// 2 /// - element suffix +// - /// 3 /// - modifier suffix +// - /// 4 /// - multiple element suffix +// + +@include it('iro-bem-suffix') { + @include assert('block suffix') { /// 1 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-suffix('sm') { + font-size: 1.5em; + } + } + } + + @include expect { + .something\@sm { + font-size: 1.5em; + } + } + } + + @include assert('element suffix') { /// 2 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child') { + @include iro-bem-suffix('sm') { + font-size: 2.5em; + } + } + } + } + + @include expect { + .something__child\@sm { + font-size: 2.5em; + } + } + } + + @include assert('modifier suffix') { /// 3 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-modifier('mod1') { + @include iro-bem-suffix('sm') { + font-size: 1.75em; + } + } + + @include iro-bem-element('child') { + @include iro-bem-modifier('mod2') { + @include iro-bem-suffix('sm') { + font-size: 2.75em; + } + } + } + } + } + + @include expect { + .something--mod1\@sm { + font-size: 1.75em; + } + + .something__child--mod2\@sm { + font-size: 2.75em; + } + } + } + + @include assert('multiple element suffix') { /// 4 /// + @include output { + @include iro-bem-block('something') { + @include iro-bem-element('child1', 'child2') { + @include iro-bem-suffix('sm') { + font-size: 2.5em; + } + } + } + } + + @include expect { + .something__child1\@sm, + .something__child2\@sm { + font-size: 2.5em; + } + } + } +} diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..94d16da --- /dev/null +++ b/test/test.js @@ -0,0 +1,4 @@ +const path = require("path"); +const sassTrue = require("sass-true"); + +sassTrue.runSass({ file: path.join(__dirname, "test.scss") }, { describe, it }); diff --git a/test/test.scss b/test/test.scss new file mode 100644 index 0000000..9e3cf6b --- /dev/null +++ b/test/test.scss @@ -0,0 +1,16 @@ +@import '../src/main'; + +@import 'true'; + +$iro-easing-gradient-steps: 4; + +@import 'functions'; +@import 'math'; +@import 'contexts'; +@import 'bem'; +@import 'responsive'; +@import 'harmony'; +@import 'gradients'; +@import 'props'; + +@include report; -- cgit v1.2.3-70-g09d2