From 1e2f3b2073f216d5a587a63e050cd755e3df383c Mon Sep 17 00:00:00 2001 From: jurcovicovam Date: Fri, 20 Jun 2014 14:30:55 +0200 Subject: [PATCH] Added unit tests for detached rulesets. #186 --- .../less4j/compiler/DetachedRulesetsTest.java | 41 +++++++++++++++++++ .../detached-ruleset-in-list-own-scope.css | 4 ++ .../detached-ruleset-in-list-own-scope.less | 28 +++++++++++++ ...detached-ruleset-in-list-passed-around.css | 3 ++ ...etached-ruleset-in-list-passed-around.less | 18 ++++++++ .../detached-ruleset-in-lists-lists-scope.css | 3 ++ ...detached-ruleset-in-lists-lists-scope.less | 21 ++++++++++ .../detached-rulesets-basics.css | 29 +++++++++---- .../detached-rulesets-basics.less | 34 +++++++++++---- .../detached-rulesets-errors-additional.css | 4 ++ .../detached-rulesets-errors-additional.err | 2 + .../detached-rulesets-errors-additional.less | 4 ++ .../detached-rulesets-errors.less | 2 +- .../detached-rulesets-lessjs.less | 4 +- .../detached-rulesets-scoping.css | 3 ++ .../detached-rulesets-scoping.less | 15 +++++++ src/test/resources/minitests/debug1.css | 6 +-- src/test/resources/minitests/debug1.less | 28 +++++++++---- 18 files changed, 217 insertions(+), 32 deletions(-) create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.less create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.less create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.less create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.err create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.less diff --git a/src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java b/src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java index 91b84b2d..22a1bca1 100644 --- a/src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java +++ b/src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java @@ -38,7 +38,48 @@ interpolation: "@{detached}"; } +//*** should this work? **** +.mixin() { + @detached: { extreme: simplicity; }; +} +.selector { + @detached(); + .mixin(); +} +//********************************************88 +.mixin() { + @detached: { scope: @see-here; }; +} +.selector { + @see-here: yes; + .nested { + .mixin(); + @detached(); + } +} +//************************************************************ + .mixin() { + @detached: { scope-detached: @see-here; }; + .nested() { + scope-mixin: @see-here; + } +} +.definer-wrapper() { + @see-here: yes; + .mixin(); +} +.selector { + .definer-wrapper(); + @detached(); + .nested(); +} + +//********************************************88 + * test if it works from imported !!!!!!!!!!!!!!!!!!!! + * test if it works when variables copy detached forever !!!!!!!!!!!!!!!!!!!! + * test if it works from list correctly -- e.g. including various callers scopes + * test if @defaults works correctly -- e.g. including various callers scopes */ @Ignore diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.css new file mode 100644 index 00000000..7b70e36b --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.css @@ -0,0 +1,4 @@ +selector { + property-1: passing-through; + property-2: in-unlocker; +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.less new file mode 100644 index 00000000..a2dc69d9 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-own-scope.less @@ -0,0 +1,28 @@ +#namespace { + @variable: in-unlocker; + .unlocker { + @detached-ruleset2: { property-2: @variable; }; + } +} +#namespace > .unlocker(); + +@detached-ruleset1: { property-1: @variable; }; +@list: @detached-ruleset1 @detached-ruleset2; + +.mixin(@list) { + @detached1: extract(@list, 1); + @detached1(); + @detached2: extract(@list, 2); + @detached2(); +} + +.indirect-mixin(@list) { + @variable: passing-through; + .mixin(@list); +} + +selector { + @variable: in-caller; + .indirect-mixin(@list) +} + diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.css new file mode 100644 index 00000000..93fd5e8c --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.css @@ -0,0 +1,3 @@ +selector { + property: passing-through; +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.less new file mode 100644 index 00000000..397156f3 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list-passed-around.less @@ -0,0 +1,18 @@ +@detached-ruleset1: { property: 1; }; +@detached-ruleset2: { property: @variable; }; +@list: @detached-ruleset1 @detached-ruleset2; + +.mixin(@list) { + @detached: extract(@list, 2); + @detached(); +} + +.indirect-mixin(@list) { + @variable: passing-through; + .mixin(@list); +} + +selector { + @variable: in-caller; + .indirect-mixin(@list) +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.css new file mode 100644 index 00000000..e12277e6 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.css @@ -0,0 +1,3 @@ +selector { + property-1: in-list-unlocker; +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.less new file mode 100644 index 00000000..b63cfa97 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-lists-lists-scope.less @@ -0,0 +1,21 @@ +@detached-ruleset1: { property-1: @variable; }; +.list-namespacer { + @variable: in-list-unlocker; + .listUnlocker { + @list: @detached-ruleset1 something-else; + } +} + +.mixin(@list) { + @detached1: extract(@list, 1); + @detached1(); +} + +.indirect-mixin(@list) { + .mixin(@list); +} + +selector { + .list-namespacer > .listUnlocker(); + .indirect-mixin(@list) +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.css index d5a2b834..4a7ccdcf 100644 --- a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.css +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.css @@ -18,8 +18,6 @@ } } @media screen { - background: red; - .selector { background: green; } @@ -29,6 +27,19 @@ padding: 0; } } +@media screen { + .outer { + background: red; + } + .outer .selector { + background: green; + } +} +@media screen and (min-width: 1200) { + .outer .selector { + padding: 0; + } +} .mixin-with-arguments-enclosure .custom-mixin-argument { custom: custom; } @@ -37,7 +48,7 @@ property: default; property: global default; } -.see-caller use-place { +.see-caller-local-win use-place { caller-variable: declaration; variable: declaration; } @@ -57,18 +68,18 @@ .custom { property: custom; } -.caller { - property: caller; -} .caller .default { - property: caller; + property-in-caller: caller; } .caller .custom { - property: custom; + property-in-caller: custom; +} +.caller .default { + property-overwritten: overwritten; } .caller { value: in detached; } .selector-indirect { color: #aabbcc; -} \ No newline at end of file +} diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.less index cd63e737..967da71a 100644 --- a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.less +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.less @@ -1,29 +1,37 @@ @one-rule: { background: red; }; @ruleset: { .selector { background: green; } }; @ruleset-second: { .selector { size: 2; } }; -@media: { @media (min-width: 1200) { .selector { padding: 0; }} }; +@media-var: { @media (min-width: 1200) { .selector { padding: 0; }} }; @empty: {}; //call on top @ruleset(); @empty(); -@media(); +@media-var(); //call from ruleset .call-with-parentheses { @empty(); @one-rule(); @ruleset(); - @media(); + @media-var(); } //call from media @media screen { @empty(); - @one-rule(); @ruleset(); - @media(); + @media-var(); +} + +.outer { + @media screen { + @empty(); + @one-rule(); + @ruleset(); + @media-var(); + } } //mixin arguments @@ -56,7 +64,7 @@ } //scope - local win -.see-caller { +.see-caller-local-win { @detached-ruleset: { caller-variable: @variable; .mixin(); @@ -128,7 +136,7 @@ @with-mixin-caller-default: { .mixin(@parameter: @caller-default) { - property: @parameter; + property-in-caller: @parameter; } .default { .mixin(); @@ -137,9 +145,19 @@ .mixin(custom); } }; +@with-mixin-caller-default-overwritten: { + @caller-default:overwritten; + .mixin(@parameter: @caller-default) { + property-overwritten: @parameter; + } + .default { + .mixin(); + } +}; .caller { @caller-default: caller; @with-mixin-caller-default(); + @with-mixin-caller-default-overwritten(); } //unlock mixin see things defined in his scope first @@ -158,7 +176,7 @@ //detached returned from mixin .return-detached() { @color: #aabbcc; - @detached: {color: @color;} + @detached: {color: @color;}; } .selector-indirect { .return-detached(); diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.css new file mode 100644 index 00000000..13971524 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.css @@ -0,0 +1,4 @@ +//does not exists +.does-not-exists { + !#error#! +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.err b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.err new file mode 100644 index 00000000..3722711c --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.err @@ -0,0 +1,2 @@ +Errors produced by compilation of testCase +ERROR 3:2 Could not find detached ruleset for "@does-not-exists". \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.less new file mode 100644 index 00000000..4a0dbe91 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors-additional.less @@ -0,0 +1,4 @@ +//does not exists +.does-not-exists { + @does-not-exists(); +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.less index c5cbb566..d5c2d144 100644 --- a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.less +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.less @@ -33,4 +33,4 @@ b: { color: red; }; -} +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.less index 3c004c47..24f0fcfb 100644 --- a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.less +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.less @@ -14,7 +14,7 @@ visible-one: @b; visible-two: @c; } -}; +} .wrap-mixin({ color: black; @@ -45,7 +45,7 @@ header { .wrap-mixin-calls-wrap(@ruleset) { .wrap-mixin(@ruleset); -}; +} .wrap-mixin({ test: extra-wrap; diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.css index ccef8d19..2cf80e72 100644 --- a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.css +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.css @@ -3,4 +3,7 @@ } .selector-indirect { color: #ff0000; +} +.multiple-imports .selector { + scope: yes; } \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.less index 1628b966..524c5fd6 100644 --- a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.less +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-scoping.less @@ -1,3 +1,4 @@ +//can mixin find detached ruleset in callers scope? .whoReallyCalls(@detached) { @detached(); } @@ -25,3 +26,17 @@ @detached: { color: @color; }; } +//does it sees through multiple imports? +.multiple-imports { + .mixin() { + @detached: { scope: @see-here; }; + } + .definer-wrapper() { + @see-here: yes; + .mixin(); + } + .selector { + .definer-wrapper(); + @detached(); + } +} \ No newline at end of file diff --git a/src/test/resources/minitests/debug1.css b/src/test/resources/minitests/debug1.css index ba59e2a7..c196af3e 100644 --- a/src/test/resources/minitests/debug1.css +++ b/src/test/resources/minitests/debug1.css @@ -1,5 +1,3 @@ -@keyframes /* 1 */ sunrise { - h1 { - color: #ff00ff; - } +.wrap-selector { + visible-one: visible; } diff --git a/src/test/resources/minitests/debug1.less b/src/test/resources/minitests/debug1.less index 36d8a543..add78c9f 100644 --- a/src/test/resources/minitests/debug1.less +++ b/src/test/resources/minitests/debug1.less @@ -1,14 +1,26 @@ -.mixin() { - @imported: @lazy; - size: 1; +.wrap-mixin(@ruleset) { + @b: visible; + .wrap-selector { + @ruleset(); + visible-one: @b; + } } -.indirect() { - .mixin(); +.wrap-mixin({ + @b: hidden and if you see this in the output its a bug; +}); + +.ruleset-mixin() { + @b-mixin: hidden and if you see this in the output its a bug; } -.selector { - .indirect(); - @lazy: 4; +/* ******************************************************** */ +.wrap-mixin-mixin() { + @b-mixin: visible; + .wrap-selector { + .ruleset-mixin(); + visible-one: @b-mixin; + } } +.wrap-mixin-mixin(); \ No newline at end of file