]> source.dussan.org Git - vaadin-framework.git/commitdiff
Handle numbers in the same way if they do not have a unit (#12732)
authorArtur Signell <artur@vaadin.com>
Tue, 15 Oct 2013 19:50:47 +0000 (22:50 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 16 Oct 2013 09:32:54 +0000 (09:32 +0000)
Change-Id: Ic9dba337ffb209bf73ab427fa3a39e542e645c08

theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java
theme-compiler/tests/resources/automatic/css/functions/abs.css [new file with mode: 0644]
theme-compiler/tests/resources/automatic/css/functions/ceil.css [new file with mode: 0644]
theme-compiler/tests/resources/automatic/css/functions/floor.css [new file with mode: 0644]
theme-compiler/tests/resources/automatic/css/functions/round.css [new file with mode: 0644]
theme-compiler/tests/resources/automatic/scss/functions/abs.scss [new file with mode: 0644]
theme-compiler/tests/resources/automatic/scss/functions/ceil.scss [new file with mode: 0644]
theme-compiler/tests/resources/automatic/scss/functions/floor.scss [new file with mode: 0644]
theme-compiler/tests/resources/automatic/scss/functions/round.scss [new file with mode: 0644]

index 498e1a941b6cdc10025d9fbab28f692cd9ed759d..af94de0f467dce0487fbeff793b79afb42dc756a 100644 (file)
@@ -148,6 +148,22 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit,
         return f;
     }
 
+    /**
+     * Returns the float value as a string unless the value is an integer. In
+     * that case returns the integer value as a string.
+     * 
+     * @return a string representing the value, either with or without decimals
+     */
+    public String getFloatOrInteger() {
+        float f = getFloatValue();
+        int i = (int) f;
+        if ((i) == f) {
+            return i + "";
+        } else {
+            return f + "";
+        }
+    }
+
     public void setFloatValue(float f) {
         this.f = f;
         i = (int) f;
@@ -274,7 +290,7 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit,
             text = Integer.toString(getIntegerValue(), 10);
             break;
         case LexicalUnit.SAC_REAL:
-            text = getFloatValue() + "";
+            text = getFloatOrInteger();
             break;
         case LexicalUnit.SAC_EM:
         case SCSSLexicalUnit.SAC_LEM:
@@ -295,13 +311,7 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit,
         case LexicalUnit.SAC_HERTZ:
         case LexicalUnit.SAC_KILOHERTZ:
         case LexicalUnit.SAC_DIMENSION:
-            float f = getFloatValue();
-            int i = (int) f;
-            if ((i) == f) {
-                text = i + getDimensionUnitText();
-            } else {
-                text = f + getDimensionUnitText();
-            }
+            text = getFloatOrInteger() + getDimensionUnitText();
             break;
         case LexicalUnit.SAC_URI:
             text = "url(" + getStringValue() + ")";
diff --git a/theme-compiler/tests/resources/automatic/css/functions/abs.css b/theme-compiler/tests/resources/automatic/css/functions/abs.css
new file mode 100644 (file)
index 0000000..3c43804
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+       a: 0;
+       b: 12.51;
+       c: 1.1px;
+       d: 12;
+       e: 12px;
+       f: 12.9999;
+       g: 12.9999em;
+       h: 13.0001;
+       i: 13.0001%;
+}
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/css/functions/ceil.css b/theme-compiler/tests/resources/automatic/css/functions/ceil.css
new file mode 100644 (file)
index 0000000..9956ff3
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+       a: 0;
+       b: -12;
+       c: -1px;
+       d: 12;
+       e: 12px;
+       f: 13;
+       g: 13em;
+       h: 14;
+       i: 14%;
+}
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/css/functions/floor.css b/theme-compiler/tests/resources/automatic/css/functions/floor.css
new file mode 100644 (file)
index 0000000..f96e99d
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+       a: 0;
+       b: -13;
+       c: -2px;
+       d: 12;
+       e: 12px;
+       f: 12;
+       g: 12em;
+       h: 13;
+       i: 13%;
+}
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/css/functions/round.css b/theme-compiler/tests/resources/automatic/css/functions/round.css
new file mode 100644 (file)
index 0000000..72d9a85
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+       a: 0;
+       b: -13;
+       c: -1px;
+       d: 12;
+       e: 12px;
+       f: 13;
+       g: 13em;
+       h: 13;
+       i: 13%;
+}
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/functions/abs.scss b/theme-compiler/tests/resources/automatic/scss/functions/abs.scss
new file mode 100644 (file)
index 0000000..91946f0
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+a: abs(0);
+b: abs(-12.51);
+c: abs(-1.1px);
+d: abs(12);
+e: abs(12px);
+f: abs(12.9999);
+g: abs(12.9999em);
+h: abs(-13.0001);
+i: abs(-13.0001%);
+}
diff --git a/theme-compiler/tests/resources/automatic/scss/functions/ceil.scss b/theme-compiler/tests/resources/automatic/scss/functions/ceil.scss
new file mode 100644 (file)
index 0000000..ad7ceed
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+a: ceil(0);
+b: ceil(-12.51);
+c: ceil(-1.1px);
+d: ceil(12);
+e: ceil(12px);
+f: ceil(12.9999);
+g: ceil(12.9999em);
+h: ceil(13.000001);
+i: ceil(13.000001%);
+}
diff --git a/theme-compiler/tests/resources/automatic/scss/functions/floor.scss b/theme-compiler/tests/resources/automatic/scss/functions/floor.scss
new file mode 100644 (file)
index 0000000..a10f1b4
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+a: floor(0);
+b: floor(-12.51);
+c: floor(-1.1px);
+d: floor(12);
+e: floor(12px);
+f: floor(12.9999);
+g: floor(12.9999em);
+h: floor(13.000001);
+i: floor(13.000001%);
+}
diff --git a/theme-compiler/tests/resources/automatic/scss/functions/round.scss b/theme-compiler/tests/resources/automatic/scss/functions/round.scss
new file mode 100644 (file)
index 0000000..3f1fa06
--- /dev/null
@@ -0,0 +1,11 @@
+.foo {
+a: round(0);
+b: round(-12.51);
+c: round(-1.1px);
+d: round(12);
+e: round(12px);
+f: round(12.9999);
+g: round(12.9999em);
+h: round(13.000001);
+i: round(13.000001%);
+}