From d0d1d9931037b48c624152ba4ef4ccc2239f2489 Mon Sep 17 00:00:00 2001 From: meri Date: Wed, 9 Apr 2014 13:59:50 +0200 Subject: [PATCH 1/3] Preparing unit tests for #186 (detached rulesets) --- .../github/sommeri/less4j/SimpleCssTest.java | 2 +- .../detached-ruleset-in-list.css | 3 + .../detached-ruleset-in-list.less | 8 + .../detached-rulesets-basics.css | 71 ++++++++ .../detached-rulesets-basics.less | 155 ++++++++++++++++++ .../detached-rulesets-incompatible.less | 11 ++ .../detached-rulesets-lessjs.css | 71 ++++++++ .../detached-rulesets-lessjs.less | 103 ++++++++++++ 8 files changed, 423 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.less create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.less create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-incompatible.less create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.less diff --git a/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java b/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java index 30cba7c1..e5a27935 100644 --- a/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java +++ b/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java @@ -19,7 +19,7 @@ * from the master branch. * */ -@Ignore +//@Ignore @RunWith(Parameterized.class) public class SimpleCssTest extends AbstractFileBasedTest { diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.css new file mode 100644 index 00000000..56a74cb1 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.css @@ -0,0 +1,3 @@ +selector { + property: 2; +} diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.less new file mode 100644 index 00000000..29dc0054 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-ruleset-in-list.less @@ -0,0 +1,8 @@ +@detached-ruleset1: { property: 1; }; +@detached-ruleset2: { property: 2; }; +@list: @detached-ruleset1 @detached-ruleset2; + +selector { + @set: extract(@list, 2); + @set(); +} \ 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 new file mode 100644 index 00000000..decc2c38 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.css @@ -0,0 +1,71 @@ +.selector { + background: green; +} +@media (min-width: 1200) { + .selector { + padding: 0; + } +} +.call-with-parentheses { + background: red; +} +.call-with-parentheses .selector { + background: green; +} +@media (min-width: 1200) { + .call-with-parentheses .selector { + padding: 0; + } +} +@media screen { + background: red; + + .selector { + background: green; + } +} +@media screen and (min-width: 1200) { + .selector { + padding: 0; + } +} +.mixin-with-arguments-enclosure .custom-mixin-argument { + custom: custom; +} +.see-caller use-place { + caller-variable: value; + property: default; + property: global default; +} +.see-caller use-place { + caller-variable: declaration; + variable: declaration; +} +.see-caller-caller use-place { + property: default; + property: global default; +} +.default { + property: default; +} +.custom { + property: custom; +} +.default { + property: global default; +} +.custom { + property: custom; +} +.caller { + property: caller; +} +.caller .default { + property: caller; +} +.caller .custom { + property: custom; +} +.caller { + value: in detached; +} 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 new file mode 100644 index 00000000..122d7aa4 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-basics.less @@ -0,0 +1,155 @@ +@one-rule: { background: red; }; +@ruleset: { .selector { background: green; } }; +@ruleset-second: { .selector { size: 2; } }; +@media: { @media (min-width: 1200) { .selector { padding: 0; }} }; + +@empty: {}; + +//call on top +@ruleset(); +@empty(); +@media(); + +//call from ruleset +.call-with-parentheses { + @empty(); + @one-rule(); + @ruleset(); + @media(); +} + +//call from media +@media screen { + @empty(); + @one-rule(); + @ruleset(); + @media(); +} + +//mixin arguments +.mixin-with-arguments-enclosure { + .mixin(@parameter) { + @parameter(); + } + + .custom-mixin-argument { + .mixin({custom: custom;}); + } +} + +//scope - see caller +.see-caller { + @detached-ruleset: { + caller-variable: @variable; + .mixin(); + }; + + use-place { + @detached-ruleset(); + + //define variable and mixin + @variable: value; + .mixin() { + position: caller; + } + } +} + +//scope - local win +.see-caller { + @detached-ruleset: { + caller-variable: @variable; + .mixin(); + }; + + @variable: declaration; + .mixin() { + variable: declaration; + } + + use-place { + @detached-ruleset(); + + //define variable and mixin + @variable: value; + .mixin() { + position: caller; + } + } +} +//scope - called mixin sees things from detached +.see-caller-caller { + @detached-ruleset: { + @variable: in detached; + .mixin(); + .in-detached() { + sees: me; + } + }; + + use-place { + @detached-ruleset(); + + //define variable and mixin + .mixin() { + position: @variable; + .in-detached(); + } + } +} + +//detached with mixin +@with-mixin-default: { + .mixin(@parameter: default) { + property: @parameter; + } + .default { + .mixin(); + } + .custom { + .mixin(custom); + } +}; +@with-mixin-default(); + +@global-default: global default; +@with-mixin-global-default: { + .mixin(@parameter: @global-default) { + property: @parameter; + } + .default { + .mixin(); + } + .custom { + .mixin(custom); + } +}; +@with-mixin-global-default(); + +@with-mixin-caller-default: { + .mixin(@parameter: @caller-default) { + property: @parameter; + } + .default { + .mixin(); + } + .custom { + .mixin(custom); + } +}; +.caller { + @caller-default: caller; + @with-mixin-caller-default(); +} +//unlock mixin see things defined in his scope first +@with-mixin-unlocking: { + .mixin() { + value: @value; + } + @value: in detached; +}; +.caller { + @value: caller; + @with-mixin-unlocking(); + .mixin(); +} diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-incompatible.less b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-incompatible.less new file mode 100644 index 00000000..9439f803 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-incompatible.less @@ -0,0 +1,11 @@ +.mixin(@parameter: {default: default;}) { + @parameter(); +} + +.default-mixin-argument { + .mixin(); +} + +.custom-mixin-argument { + .mixin({custom: custom;}); +} \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.css new file mode 100644 index 00000000..8d4be02b --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.css @@ -0,0 +1,71 @@ +.wrap-selector { + color: black; + one: 1px; + four: magic-frame; + visible-one: visible; + visible-two: visible; +} +.wrap-selector { + color: red; + visible-one: visible; + visible-two: visible; +} +.wrap-selector { + color: black; + background: white; + visible-one: visible; + visible-two: visible; +} +header { + background: blue; +} +@media screen and (min-width: 1200) { + header { + background: red; + } +} +html.lt-ie9 header { + background: red; +} +.wrap-selector { + test: extra-wrap; + visible-one: visible; + visible-two: visible; +} +.wrap-selector .wrap-selector { + test: wrapped-twice; + visible-one: visible; + visible-two: visible; +} +.wrap-selector { + test-func: 90; + test-arithmetic: 18px; + visible-one: visible; + visible-two: visible; +} +.without-mixins { + b: 1; +} +@media (orientation: portrait) and tv { + .my-selector { + background-color: black; + } +} +@media (orientation: portrait) and widescreen and print and tv { + .triple-wrapped-mq { + triple: true; + } +} +@media (orientation: portrait) and widescreen and tv { + .triple-wrapped-mq { + triple: true; + } +} +@media (orientation: portrait) and tv { + .triple-wrapped-mq { + triple: true; + } +} +.a { + test: test; +} 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 new file mode 100644 index 00000000..3c004c47 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-lessjs.less @@ -0,0 +1,103 @@ +@ruleset: { + color: black; + background: white; + }; + +@a: 1px; +.wrap-mixin(@ruleset) { + @a: hidden and if you see this in the output its a bug; + @b: visible; + @d: magic-frame; // same behaviour as mixin calls - falls back to this frame + .wrap-selector { + @c: visible; + @ruleset(); + visible-one: @b; + visible-two: @c; + } +}; + +.wrap-mixin({ + color: black; + one: @a; + @b: hidden and if you see this in the output its a bug; + @c: hidden and if you see this in the output its a bug; + four: @d; +}); + +.wrap-mixin(@ruleset: { + color: red; +}); + +.wrap-mixin(@ruleset); + +.desktop-and-old-ie(@rules) { + @media screen and (min-width: 1200) { @rules(); } + html.lt-ie9 & { @rules(); } +} + +header { + background: blue; + + .desktop-and-old-ie({ + background: red; + }); +} + +.wrap-mixin-calls-wrap(@ruleset) { + .wrap-mixin(@ruleset); +}; + +.wrap-mixin({ + test: extra-wrap; + .wrap-mixin-calls-wrap({ + test: wrapped-twice; + }); +}); + +.wrap-mixin({ + test-func: unit(90px); + test-arithmetic: unit((9+9), px); +}); +// without mixins +@ruleset-2: { + b: 1; +}; +.without-mixins { + @ruleset-2(); +} +@my-ruleset: { + .my-selector { + @media tv { + background-color: black; + } + } + }; +@media (orientation:portrait) { + @my-ruleset(); + .wrap-media-mixin({ + @media tv { + .triple-wrapped-mq { + triple: true; + } + } + }); +} +.wrap-media-mixin(@ruleset) { + @media widescreen { + @media print { + @ruleset(); + } + @ruleset(); + } + @ruleset(); +} +// unlocking mixins +@my-mixins: { + .mixin() { + test: test; + } +}; +@my-mixins(); +.a { + .mixin(); +} \ No newline at end of file From 0a2698265786cb9fd6b17ed88cb9ceffcec1852b Mon Sep 17 00:00:00 2001 From: meri Date: Wed, 9 Apr 2014 15:50:24 +0200 Subject: [PATCH 2/3] Added test class and errors test for #186 --- .../less4j/compiler/DetachedRulesetsTest.java | 23 ++++++++++++ .../detached-rulesets-errors.css | 1 + .../detached-rulesets-errors.err | 1 + .../detached-rulesets-errors.less | 36 +++++++++++++++++++ .../detached-rulesets-incompatible.css | 0 5 files changed, 61 insertions(+) create mode 100644 src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.css create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.err create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.less create mode 100644 src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-incompatible.css diff --git a/src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java b/src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java new file mode 100644 index 00000000..61313d64 --- /dev/null +++ b/src/test/java/com/github/sommeri/less4j/compiler/DetachedRulesetsTest.java @@ -0,0 +1,23 @@ +package com.github.sommeri.less4j.compiler; + +import java.io.File; +import java.util.Collection; + +import org.junit.Ignore; +import org.junit.runners.Parameterized.Parameters; + +@Ignore +public class DetachedRulesetsTest extends BasicFeaturesTest { + + private static final String standardCases = "src/test/resources/compile-basic-features/detached-rulesets/"; + + public DetachedRulesetsTest(File inputFile, File outputFile, File errorList, File mapdataFile, String testName) { + super(inputFile, outputFile, errorList, mapdataFile, testName); + } + + @Parameters(name="Less: {4}") + public static Collection allTestsParameters() { + return createTestFileUtils().loadTestFiles(standardCases); + } + +} diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.css new file mode 100644 index 00000000..30404ce4 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.css @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.err b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.err new file mode 100644 index 00000000..30404ce4 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.err @@ -0,0 +1 @@ +TODO \ 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 new file mode 100644 index 00000000..c5cbb566 --- /dev/null +++ b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-errors.less @@ -0,0 +1,36 @@ +@a: { + b: 1; +}; +//less.js detached-ruleset-1.less +.call-without-parentheses { + @a; +} + +//less.js detached-ruleset-2.less +.detached-as-property-value { + a: @a(); +} + +//less.js detached-ruleset-3.less +.brings-property-on-top {} +@a(); + +//less.js detached-ruleset-4.less +.warning-for-default(@a: { + b: 1; +}) { + @a(); //warning shall be enough for this one +} + +//less.js detached-ruleset-5.less +.mixin-variable-does-not-exists(@b) { + @a(); +} +.mixin-variable-does-not-exists({color: red;}); + +//less.js detached-ruleset-6.less +.variable-declaration-symbol-missing { + b: { + color: red; + }; +} diff --git a/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-incompatible.css b/src/test/resources/compile-basic-features/detached-rulesets/detached-rulesets-incompatible.css new file mode 100644 index 00000000..e69de29b From fa3ffeba1ae39f78b06f7ac0f59e16364d8a1431 Mon Sep 17 00:00:00 2001 From: meri Date: Thu, 10 Apr 2014 11:08:09 +0200 Subject: [PATCH 3/3] Added merge of interpolated properties test. --- .../com/github/sommeri/less4j/SimpleCssTest.java | 2 +- .../properties-merging-vs-interpolation.css | 6 ++++++ .../properties-merging-vs-interpolation.less | 12 ++++++++++++ src/test/resources/minitests/debug1.less | 16 +++++++++------- 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.css create mode 100644 src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.less diff --git a/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java b/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java index e5a27935..30cba7c1 100644 --- a/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java +++ b/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java @@ -19,7 +19,7 @@ * from the master branch. * */ -//@Ignore +@Ignore @RunWith(Parameterized.class) public class SimpleCssTest extends AbstractFileBasedTest { diff --git a/src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.css b/src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.css new file mode 100644 index 00000000..c28116d7 --- /dev/null +++ b/src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.css @@ -0,0 +1,6 @@ +.test { + -webkit-p: 1, 2, 3; + -moz-p: 1, 2, 3; + -ms-p: 1, 2, 3; + p: 1, 2, 3; +} diff --git a/src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.less b/src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.less new file mode 100644 index 00000000..a9226beb --- /dev/null +++ b/src/test/resources/compile-basic-features/expressions/properties-merging-vs-interpolation.less @@ -0,0 +1,12 @@ +.css3merge(@prop; @rest...){ + -webkit-@{prop}+: @rest; + -moz-@{prop}+: @rest; + -ms-@{prop}+: @rest; + @{prop}+: @rest; +} + +.test { + .css3merge(p, 1); + .css3merge(p, 2); + .css3merge(p, 3); +} \ No newline at end of file diff --git a/src/test/resources/minitests/debug1.less b/src/test/resources/minitests/debug1.less index 9d87756d..a9226beb 100644 --- a/src/test/resources/minitests/debug1.less +++ b/src/test/resources/minitests/debug1.less @@ -1,10 +1,12 @@ -@property: color; - -.widget(@detached) { - @detached(); +.css3merge(@prop; @rest...){ + -webkit-@{prop}+: @rest; + -moz-@{prop}+: @rest; + -ms-@{prop}+: @rest; + @{prop}+: @rest; } -ruleset { - @detached: { property: value; } - .widget(@detached); +.test { + .css3merge(p, 1); + .css3merge(p, 2); + .css3merge(p, 3); } \ No newline at end of file