summaryrefslogtreecommitdiffstats
path: root/theme-compiler/tests
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-05-17 15:14:15 +0300
committerLeif Åstrand <leif@vaadin.com>2013-05-17 15:14:59 +0300
commit1205e87be7f306e6c307190ae6423ee64f1c7b17 (patch)
tree670858e0940b45b0b42fdb7d30bb2f07e356c443 /theme-compiler/tests
parenta52ceb96590333bbfcb7ddad4815c88c49ac97ab (diff)
parent9b6b735752e2f30bcdf6a521e031a8de22343bb0 (diff)
downloadvaadin-framework-1205e87be7f306e6c307190ae6423ee64f1c7b17.tar.gz
vaadin-framework-1205e87be7f306e6c307190ae6423ee64f1c7b17.zip
Merge commit 'a52ceb96590333' into 7.1
Conflicts: theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java Change-Id: I049a08a5d129b8072bf91554ca0eab0d44e537e3
Diffstat (limited to 'theme-compiler/tests')
-rw-r--r--theme-compiler/tests/resources/automatic/css/basic_arithmetics.css31
-rw-r--r--theme-compiler/tests/resources/automatic/css/mixin-content-directive-with-vars.css5
-rw-r--r--theme-compiler/tests/resources/automatic/css/mixin-content-directive.css20
-rw-r--r--theme-compiler/tests/resources/automatic/scss/basic_arithmetics.scss44
-rw-r--r--theme-compiler/tests/resources/automatic/scss/mixin-content-directive-with-vars.scss9
-rw-r--r--theme-compiler/tests/resources/automatic/scss/mixin-content-directive.scss40
-rw-r--r--theme-compiler/tests/src/com/vaadin/sass/internal/expression/ArithmeticExpressionEvaluatorTest.java125
-rw-r--r--theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java83
8 files changed, 357 insertions, 0 deletions
diff --git a/theme-compiler/tests/resources/automatic/css/basic_arithmetics.css b/theme-compiler/tests/resources/automatic/css/basic_arithmetics.css
new file mode 100644
index 0000000000..9fd33f2efe
--- /dev/null
+++ b/theme-compiler/tests/resources/automatic/css/basic_arithmetics.css
@@ -0,0 +1,31 @@
+.foo {
+ font: 10px / 8px;
+ font: 5px;
+ margin-left: 9px;
+}
+
+.foo {
+ size: 1;
+}
+
+.foo {
+ bar: 8;
+ bar: 8;
+ bar: 12;
+}
+
+.foo {
+ bar: 2 3;
+ bar: 5;
+ bar: 5;
+}
+
+.foo {
+ bar: 2 -3;
+ bar: -1;
+ bar: -1;
+}
+
+.foo {
+ bar: 14;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/css/mixin-content-directive-with-vars.css b/theme-compiler/tests/resources/automatic/css/mixin-content-directive-with-vars.css
new file mode 100644
index 0000000000..799d6ae90c
--- /dev/null
+++ b/theme-compiler/tests/resources/automatic/css/mixin-content-directive-with-vars.css
@@ -0,0 +1,5 @@
+.colors {
+ background-color: blue;
+ color: white;
+ border-color: blue;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/css/mixin-content-directive.css b/theme-compiler/tests/resources/automatic/css/mixin-content-directive.css
new file mode 100644
index 0000000000..07813d1c99
--- /dev/null
+++ b/theme-compiler/tests/resources/automatic/css/mixin-content-directive.css
@@ -0,0 +1,20 @@
+.foobar {
+ color: red;
+}
+
+.foobar {
+ background-color: blue;
+}
+
+* html #logo {
+ background-image: url(/logo.gif);
+}
+
+* html .link {
+ color: blue;
+}
+
+.foobar {
+ color: red;
+ color: red;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/basic_arithmetics.scss b/theme-compiler/tests/resources/automatic/scss/basic_arithmetics.scss
new file mode 100644
index 0000000000..cc913fe048
--- /dev/null
+++ b/theme-compiler/tests/resources/automatic/scss/basic_arithmetics.scss
@@ -0,0 +1,44 @@
+/*
+*supports:
+* 1. standard arithmetic operations (+, -, *, /, %)
+* 2. / is treated as css operator, unless one of its operands is variable or there is another binary arithmetic operator
+*limits:
+* 1. cannot mix arithmetic and css operations, e.g. "margin: 1px + 3px 2px" will fail
+* 2. space between add and minus operator and their following operand is mandatory. e.g. "1 + 2" is valid, "1+2" is not
+* 3. parenthesis is not supported now.
+*/
+
+$div: 10px;
+.foo {
+ font: 10px/8px; // Plain CSS, no division
+ font: $div/2; // Uses a variable, does division
+ margin-left: 5px + 8px/2px; //Uses +, does division
+}
+
+.foo{
+ size: 5 % 2; // modular
+}
+
+$mul: 2*4; //valid multiply in variable
+$mul1: 2 * 4; //valid multiply in variable
+.foo{
+ bar: $mul;
+ bar: $mul1;
+ bar: 3*4; //valid multiply in declaration
+}
+
+.foo {
+ bar: 2 +3; //'+' is regarded as an unary operator, because no space between '+' and '3'
+ bar: 2+ 3; //valid add expression
+ bar: 2 + 3; //beautiful valid add expression
+}
+
+.foo {
+ bar: 2 -3; //'-' is regarded as an unary operator, because no space between '-' and '3'
+ bar: 2 - 3; //beautiful valid minus expression
+ bar: 2- 3; //valid minus expression
+}
+
+.foo {
+ bar: 2 + 3 * 4; // combinations
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/mixin-content-directive-with-vars.scss b/theme-compiler/tests/resources/automatic/scss/mixin-content-directive-with-vars.scss
new file mode 100644
index 0000000000..e7e0c3b7e6
--- /dev/null
+++ b/theme-compiler/tests/resources/automatic/scss/mixin-content-directive-with-vars.scss
@@ -0,0 +1,9 @@
+$color: white;
+@mixin colors($color: blue) {
+ background-color: $color;
+ @content;
+ border-color: $color;
+}
+.colors {
+ @include colors { color: $color; }
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/mixin-content-directive.scss b/theme-compiler/tests/resources/automatic/scss/mixin-content-directive.scss
new file mode 100644
index 0000000000..71217cb814
--- /dev/null
+++ b/theme-compiler/tests/resources/automatic/scss/mixin-content-directive.scss
@@ -0,0 +1,40 @@
+@mixin my-mixin {
+ .foobar {
+ @content;
+ }
+}
+
+@include my-mixin {
+ color: red;
+}
+
+@include my-mixin {
+ background-color: blue;
+}
+
+@mixin apply-to-ie6-only {
+ * html {
+ @content;
+ }
+}
+@include apply-to-ie6-only {
+ #logo {
+ background-image: url(/logo.gif);
+ }
+}
+@include apply-to-ie6-only {
+ .link {
+ color: blue;
+ }
+}
+
+@mixin mixin-multi-contents {
+ .foobar {
+ @content;
+ @content;
+ }
+}
+
+@include mixin-multi-contents {
+ color: red;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/src/com/vaadin/sass/internal/expression/ArithmeticExpressionEvaluatorTest.java b/theme-compiler/tests/src/com/vaadin/sass/internal/expression/ArithmeticExpressionEvaluatorTest.java
new file mode 100644
index 0000000000..8978eb812e
--- /dev/null
+++ b/theme-compiler/tests/src/com/vaadin/sass/internal/expression/ArithmeticExpressionEvaluatorTest.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.sass.internal.expression;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.w3c.css.sac.LexicalUnit;
+
+import com.vaadin.sass.internal.expression.exception.IncompatibleUnitsException;
+import com.vaadin.sass.internal.parser.LexicalUnitImpl;
+
+public class ArithmeticExpressionEvaluatorTest {
+ private ArithmeticExpressionEvaluator evaluator = new ArithmeticExpressionEvaluator();
+
+ @Test
+ public void testPrecedenceSameAsAppearOrder() {
+ // 2 * 3 - 4 = 2
+ LexicalUnitImpl operand2 = LexicalUnitImpl.createInteger(0, 0, null, 2);
+ LexicalUnitImpl operatorMultiply = LexicalUnitImpl.createMultiply(0, 0,
+ operand2);
+ LexicalUnitImpl operand3 = LexicalUnitImpl.createInteger(0, 0,
+ operatorMultiply, 3);
+ LexicalUnitImpl operatorMinus = LexicalUnitImpl.createMinus(0, 0,
+ operand3);
+ LexicalUnitImpl operand4 = LexicalUnitImpl.createInteger(0, 0,
+ operatorMinus, 4);
+ LexicalUnitImpl result = evaluator.evaluate(operand2);
+ Assert.assertEquals(2, result.getIntegerValue());
+ }
+
+ @Test
+ public void testPrecedenceDifferFromAppearOrder() {
+ // 2 - 3 * 4 = -10
+ LexicalUnitImpl operand2 = LexicalUnitImpl.createInteger(0, 0, null, 2);
+ LexicalUnitImpl operatorMinus = LexicalUnitImpl.createMinus(0, 0,
+ operand2);
+ LexicalUnitImpl operand3 = LexicalUnitImpl.createInteger(0, 0,
+ operatorMinus, 3);
+ LexicalUnitImpl operatorMultiply = LexicalUnitImpl.createMultiply(0, 0,
+ operand3);
+ LexicalUnitImpl operand4 = LexicalUnitImpl.createInteger(0, 0,
+ operatorMultiply, 4);
+ LexicalUnitImpl result = evaluator.evaluate(operand2);
+ Assert.assertEquals(-10, result.getIntegerValue());
+ }
+
+ @Test(expected = IncompatibleUnitsException.class)
+ public void testIncompatibleUnit() {
+ // 2cm - 3px
+ LexicalUnitImpl operand2 = LexicalUnitImpl.createCM(0, 0, null, 2);
+ LexicalUnitImpl operatorMinus = LexicalUnitImpl.createMinus(0, 0,
+ operand2);
+ LexicalUnitImpl operand3 = LexicalUnitImpl.createPX(0, 0,
+ operatorMinus, 3);
+ evaluator.evaluate(operand2);
+ }
+
+ @Test
+ public void testMultiplyWithUnitInfirstOperand() {
+ // 2cm * 3 = 6cm
+ LexicalUnitImpl operand2cm = LexicalUnitImpl.createCM(0, 0, null, 2);
+ LexicalUnitImpl operatorMultiply = LexicalUnitImpl.createMultiply(0, 0,
+ operand2cm);
+ LexicalUnitImpl operand3 = LexicalUnitImpl.createInteger(0, 0,
+ operatorMultiply, 3);
+ LexicalUnitImpl result = evaluator.evaluate(operand2cm);
+ Assert.assertEquals(6, result.getIntegerValue());
+ Assert.assertEquals(LexicalUnit.SAC_CENTIMETER,
+ result.getLexicalUnitType());
+ }
+
+ @Test
+ public void testMultiplyWithUnitInSecondOperand() {
+ // 2 * 3cm = 6cm
+ LexicalUnitImpl operand2 = LexicalUnitImpl.createInteger(0, 0, null, 2);
+ LexicalUnitImpl operatorMultiply = LexicalUnitImpl.createMultiply(0, 0,
+ operand2);
+ LexicalUnitImpl operand3cm = LexicalUnitImpl.createCM(0, 0,
+ operatorMultiply, 3);
+ LexicalUnitImpl result = evaluator.evaluate(operand2);
+ Assert.assertEquals(6, result.getIntegerValue());
+ Assert.assertEquals(LexicalUnit.SAC_CENTIMETER,
+ result.getLexicalUnitType());
+ }
+
+ @Test
+ public void testDivideWithSameUnit() {
+ // 4cm / 2cm = 2
+ LexicalUnitImpl operand4cm = LexicalUnitImpl.createCM(0, 0, null, 4);
+ LexicalUnitImpl operatorDivide = LexicalUnitImpl.createSlash(0, 0,
+ operand4cm);
+ LexicalUnitImpl operand2cm = LexicalUnitImpl.createCM(0, 0,
+ operatorDivide, 2);
+ LexicalUnitImpl result = evaluator.evaluate(operand4cm);
+ Assert.assertEquals(2, result.getIntegerValue());
+ Assert.assertEquals(LexicalUnit.SAC_REAL, result.getLexicalUnitType());
+ }
+
+ @Test
+ public void testDivideDenominatorWithoutUnit() {
+ // 4cm / 2 = 2cm
+ LexicalUnitImpl operand4cm = LexicalUnitImpl.createCM(0, 0, null, 4);
+ LexicalUnitImpl operatorDivide = LexicalUnitImpl.createSlash(0, 0,
+ operand4cm);
+ LexicalUnitImpl operand2 = LexicalUnitImpl.createInteger(0, 0,
+ operatorDivide, 2);
+ LexicalUnitImpl result = evaluator.evaluate(operand4cm);
+ Assert.assertEquals(2, result.getIntegerValue());
+ Assert.assertEquals(LexicalUnit.SAC_CENTIMETER,
+ result.getLexicalUnitType());
+ }
+}
diff --git a/theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java b/theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java
new file mode 100644
index 0000000000..59b49888c2
--- /dev/null
+++ b/theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/**
+ *
+ */
+package com.vaadin.sass.resolvers;
+
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.lang.reflect.Method;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.sass.internal.resolver.VaadinResolver;
+
+public class VaadinResolverTest {
+
+ @Test
+ public void testPathNormalization() throws Exception {
+
+ VaadinResolver resolver = new VaadinResolver();
+
+ Method normalizeMethod = VaadinResolver.class.getDeclaredMethod(
+ "normalize", String.class);
+ normalizeMethod.setAccessible(true);
+
+ String identifier, result;
+
+ identifier = "a/b/../../../a b/b.scss";
+ result = (String) normalizeMethod.invoke(resolver, identifier);
+ Assert.assertEquals("../a b/b.scss", result);
+
+ identifier = "./a/b/../c/d/.././e.scss";
+ result = (String) normalizeMethod.invoke(resolver, identifier);
+ Assert.assertEquals("a/c/e.scss", result);
+
+ identifier = "/äåäåäääå/:;:;:;/???????/- -/e.scss";
+ result = (String) normalizeMethod.invoke(resolver, identifier);
+ Assert.assertEquals("/äåäåäääå/:;:;:;/???????/- -/e.scss", result);
+
+ identifier = ".";
+ result = (String) normalizeMethod.invoke(resolver, identifier);
+ Assert.assertEquals("", result);
+
+ identifier = "../..";
+ result = (String) normalizeMethod.invoke(resolver, identifier);
+ Assert.assertEquals("../..", result);
+
+ identifier = "./../a.scss";
+ result = (String) normalizeMethod.invoke(resolver, identifier);
+ Assert.assertEquals("../a.scss", result);
+ }
+
+}