From fb6339d0754981d667847be9633972b56f472e05 Mon Sep 17 00:00:00 2001 From: Haijian Wang Date: Wed, 13 Feb 2013 14:51:18 +0200 Subject: Sass replaces variables based on substring matches. (Tickets #10508, #10730) Change-Id: I7d3c5a74055e28e0e22fe6e496209d7d3c42b4af --- .../automatic/css/var-in-css-function.css | 4 ++ .../automatic/css/var-substring-match.css | 3 ++ .../automatic/scss/var-in-css-function.scss | 15 ++++++ .../automatic/scss/var-substring-match.scss | 8 ++++ .../vaadin/sass/internal/util/StringUtilTest.java | 53 ++++++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 theme-compiler/tests/resources/automatic/css/var-in-css-function.css create mode 100644 theme-compiler/tests/resources/automatic/css/var-substring-match.css create mode 100644 theme-compiler/tests/resources/automatic/scss/var-in-css-function.scss create mode 100644 theme-compiler/tests/resources/automatic/scss/var-substring-match.scss create mode 100644 theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java (limited to 'theme-compiler/tests') diff --git a/theme-compiler/tests/resources/automatic/css/var-in-css-function.css b/theme-compiler/tests/resources/automatic/css/var-in-css-function.css new file mode 100644 index 0000000000..07a921678d --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/var-in-css-function.css @@ -0,0 +1,4 @@ +.v-window-footer { + background: linear-gradient(bottom, hsl(110, 50%, 98%), hsl(110, 50%, 90%)); + abc: rgba(rgb(0, 255, 13), 0.85); +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/var-substring-match.css b/theme-compiler/tests/resources/automatic/css/var-substring-match.css new file mode 100644 index 0000000000..54c97eac63 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/var-substring-match.css @@ -0,0 +1,3 @@ +.foo { + font-size: 10px; +} \ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/scss/var-in-css-function.scss b/theme-compiler/tests/resources/automatic/scss/var-in-css-function.scss new file mode 100644 index 0000000000..72b371ba57 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/var-in-css-function.scss @@ -0,0 +1,15 @@ +$very_light: 98%; +$light: 90%; + +$hue1: 110; +$saturation1: 50%; +$very_light1: hsl($hue1, $saturation1, $very_light); +$light1: hsl($hue1, $saturation1, $light); + +$color: rgb(0, 255, 13); +.v-window-footer { + background: linear-gradient(bottom, $very_light1, $light1); + abc: rgba($color, .85); +} + + diff --git a/theme-compiler/tests/resources/automatic/scss/var-substring-match.scss b/theme-compiler/tests/resources/automatic/scss/var-substring-match.scss new file mode 100644 index 0000000000..5acfb799a1 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/var-substring-match.scss @@ -0,0 +1,8 @@ +@mixin mx($f: 10px) { + .foo { + font: { + size: $f; + } + } +} +@include mx; \ No newline at end of file diff --git a/theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java b/theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java new file mode 100644 index 0000000000..b05b0e9dcf --- /dev/null +++ b/theme-compiler/tests/src/com/vaadin/sass/internal/util/StringUtilTest.java @@ -0,0 +1,53 @@ +package com.vaadin.sass.internal.util; + +import org.junit.Assert; +import org.junit.Test; + +public class StringUtilTest { + + @Test + public void testContainsVariable() { + String sentence = "$var1 var2"; + String word = "var"; + Assert.assertFalse(StringUtil.containsVariable(sentence, word)); + + word = "var1"; + Assert.assertTrue(StringUtil.containsVariable(sentence, word)); + + String var2 = "var2"; + Assert.assertFalse(StringUtil.containsVariable(sentence, var2)); + } + + @Test + public void testContainsVariableWithDash() { + String sentence = "$var- var2"; + String word = "var"; + Assert.assertFalse(StringUtil.containsVariable(sentence, word)); + } + + @Test + public void testReplaceVariable() { + String sentence = "$var1 var2"; + String word = "var"; + String value = "abc"; + Assert.assertEquals(sentence, + StringUtil.replaceVariable(sentence, word, value)); + + word = "var1"; + Assert.assertEquals("abc var2", + StringUtil.replaceVariable(sentence, word, value)); + + String var2 = "var2"; + Assert.assertEquals(sentence, + StringUtil.replaceVariable(sentence, var2, value)); + } + + @Test + public void testReplaceVariableWithDash() { + String sentence = "$var- var2"; + String word = "var"; + String value = "abc"; + Assert.assertEquals(sentence, + StringUtil.replaceVariable(sentence, word, value)); + } +} -- cgit v1.2.3