You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cz...@apache.org on 2012/11/30 02:43:15 UTC
svn commit: r1415473 -
/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/
Author: czadra
Date: Fri Nov 30 01:43:12 2012
New Revision: 1415473
URL: http://svn.apache.org/viewvc?rev=1415473&view=rev
Log:
added tests for CSSPropertyValue and sub classes
Added:
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSArrayPropertyValueTests.java (with props)
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSBaseTests.java (with props)
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSColorPropertyValueTests.java (with props)
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSFunctionCallPropertyValueTests.java (with props)
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSKeywordPropertyValueTests.java (with props)
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSNumberPropertyValueTests.java (with props)
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSPropertyValueTests.java (with props)
incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSStringPropertyValueTests.java (with props)
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSArrayPropertyValueTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSArrayPropertyValueTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSArrayPropertyValueTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSArrayPropertyValueTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,91 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.css;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSPropertyValue;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * JUnit tests for {@link CSSArrayPropertyValue}.
+ *
+ * @author Gordon Smith
+ */
+public class CSSArrayPropertyValueTests extends CSSPropertyValueTests {
+
+ private List<CSSArrayPropertyValue> getCSSArrayPropertyValues(String code) {
+ List<ICSSPropertyValue> propertyValues = getCSSPropertyValues(code);
+ List<CSSArrayPropertyValue> stringPropertyValues = new ArrayList<CSSArrayPropertyValue>();
+ for (ICSSPropertyValue icssPropertyValue : propertyValues) {
+ if(icssPropertyValue instanceof CSSArrayPropertyValue)
+ stringPropertyValues.add( (CSSArrayPropertyValue) icssPropertyValue );
+ }
+ return stringPropertyValues;
+ }
+
+ @Test
+ public void CSSArrayPropertyValue_quoted_text()
+ {
+ String code = " fillColor: #FFFFFF, #CCCCCC, #FFFFFF, #EEEEEE;";
+
+ List<CSSArrayPropertyValue> nodes = getCSSArrayPropertyValues(code);
+ assertThat("nodes size" , nodes.size(), is(1) );
+
+ CSSArrayPropertyValue propertyValue = nodes.get(0);
+ assertThat("getElements" , propertyValue.getElements().size(), is( 4) );
+
+
+ ImmutableList<? extends ICSSPropertyValue> elements = propertyValue.getElements();
+ assertThat("element 0" , ((CSSColorPropertyValue)elements.get(0)).getText() , is( "#FFFFFF" ) );
+ assertThat("element 1" , ((CSSColorPropertyValue)elements.get(1)).getText() , is( "#CCCCCC" ) );
+ assertThat("element 2" , ((CSSColorPropertyValue)elements.get(2)).getText() , is( "#FFFFFF" ) );
+ assertThat("element 3" , ((CSSColorPropertyValue)elements.get(3)).getText() , is( "#EEEEEE" ) );
+ }
+
+ @Test
+ public void CSSArrayPropertyValue_quoted_text1()
+ {
+ String code = " fillColor: #FFFFFF, 'String', Red, 0, Embed('image.gif'), bold; ";
+
+ List<CSSArrayPropertyValue> nodes = getCSSArrayPropertyValues(code);
+ assertThat("nodes size" , nodes.size(), is(1) );
+
+ CSSArrayPropertyValue propertyValue = nodes.get(0);
+ assertThat("getElements" , propertyValue.getElements().size(), is( 6 ) );
+
+ ImmutableList<? extends ICSSPropertyValue> elements = propertyValue.getElements();
+ assertThat("element 0" , ((CSSColorPropertyValue)elements.get(0)).getText() , is( "#FFFFFF" ) );
+ assertThat("element 1" , ((CSSStringPropertyValue)elements.get(1)).getValue() , is( "String" ) );
+ assertThat("element 2" , ((CSSColorPropertyValue)elements.get(2)).getText() , is( "Red" ) );
+ assertThat("element 3" , ((CSSNumberPropertyValue)elements.get(3)).getNumber() , is( (Number) new Float(0) ) );
+ assertThat("element 4" , ((CSSFunctionCallPropertyValue)elements.get(4)).name , is( CSSFunctionCallPropertyValue.EMBED ) );
+ assertThat("element 5" , ((CSSKeywordPropertyValue)elements.get(5)).getKeyword() , is( "bold" ) );
+
+ }
+
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSArrayPropertyValueTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSBaseTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSBaseTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSBaseTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSBaseTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,44 @@
+package org.apache.flex.compiler.internal.css;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSDocument;
+import org.apache.flex.compiler.internal.tree.mxml.MXMLNodeBaseTests;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLStyleNode;
+
+public class CSSBaseTests extends MXMLNodeBaseTests {
+
+ private static final String EOL = "\n\t\t";
+
+ private String getPrefix()
+ {
+ return "<d:Sprite xmlns:fx='http://ns.adobe.com/mxml/2009' xmlns:d='flash.display.*' xmlns:s='library://ns.adobe.com/flex/spark' xmlns:mx='library://ns.adobe.com/flex/mx'>\n" +
+ " <fx:Style>" + EOL +
+ " ";
+ }
+
+ private String getPostfix()
+ {
+ return EOL +
+ " </fx:Style>" + EOL +
+ "</d:Sprite>";
+ }
+
+
+ public ICSSDocument getCSSNodeBase(String code) {
+ final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+
+ IMXMLFileNode fileNode = super.getMXMLFileNode(getPrefix() + code + getPostfix());
+ IMXMLStyleNode styleNode = (IMXMLStyleNode) findFirstDescendantOfType(fileNode, IMXMLStyleNode.class);
+
+ assertNotNull("styleNode", styleNode );
+
+ return styleNode.getCSSDocument(problems);
+ }
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSBaseTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSColorPropertyValueTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSColorPropertyValueTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSColorPropertyValueTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSColorPropertyValueTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,115 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.css;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSPropertyValue;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link CSSColorPropertyValue}.
+ *
+ * @author Gordon Smith
+ */
+public class CSSColorPropertyValueTests extends CSSPropertyValueTests {
+
+ private List<CSSColorPropertyValue> getCSSColorPropertyValues(String code) {
+ List<ICSSPropertyValue> propertyValues = getCSSPropertyValues(code);
+ List<CSSColorPropertyValue> colorPropertyValues = new ArrayList<CSSColorPropertyValue>();
+ for (ICSSPropertyValue icssPropertyValue : propertyValues) {
+ if(icssPropertyValue instanceof CSSColorPropertyValue)
+ colorPropertyValues.add( (CSSColorPropertyValue) icssPropertyValue );
+ }
+ return colorPropertyValues;
+ }
+
+ @Test
+ public void CSSColorPropertyValue_textColor()
+ {
+ String code = " color: blue; ";
+
+ List<CSSColorPropertyValue> colorProperties = getCSSColorPropertyValues(code);
+ assertThat("colorProperties.size()" , colorProperties.size(), is(1) );
+
+ CSSColorPropertyValue colorPropertyValue = colorProperties.get(0);
+ assertThat("colorPropertyValue.getText()" , colorPropertyValue.getText(), is( "blue" ) );
+ assertThat("colorPropertyValue.getColorAsInt()" , colorPropertyValue.getColorAsInt(), is( 255 ) );
+ }
+
+ @Test
+ public void CSSColorPropertyValue_wrong_textColor()
+ {
+ String code = " color: xred; ";
+
+ List<CSSColorPropertyValue> colorProperties = getCSSColorPropertyValues(code);
+ assertThat("colorProperties.size()" , colorProperties.size(), is(0) );
+ }
+
+ @Test
+ public void CSSColorPropertyValue_textColor_upperCase()
+ {
+ String code = " color: RED; ";
+
+ List<CSSColorPropertyValue> colorProperties = getCSSColorPropertyValues(code);
+ assertThat("colorProperties.size()" , colorProperties.size(), is(1) );
+
+ CSSColorPropertyValue colorPropertyValue = colorProperties.get(0);
+ assertThat("colorPropertyValue.getText()" , colorPropertyValue.getText(), is( "RED" ) );
+ assertThat("colorPropertyValue.getColorAsInt()" , colorPropertyValue.getColorAsInt(), is( 16711680 ) );
+ }
+
+ @Test
+ public void CSSColorPropertyValue_hexColor()
+ {
+ String code = " color: #FF0000; ";
+
+ List<CSSColorPropertyValue> colorProperties = getCSSColorPropertyValues(code);
+ assertThat("colorProperties.size()" , colorProperties.size(), is(1) );
+
+ CSSColorPropertyValue colorPropertyValue = colorProperties.get(0);
+ assertThat("colorPropertyValue.getText()" , colorPropertyValue.getText(), is( "#FF0000" ) );
+ assertThat("colorPropertyValue.getColorAsInt()" , colorPropertyValue.getColorAsInt(), is( 16711680 ) );
+ }
+
+ @Test
+ public void CSSColorPropertyValue_wrong_hexColor()
+ {
+ String code = " color: FF0000; ";
+
+ List<CSSColorPropertyValue> colorProperties = getCSSColorPropertyValues(code);
+ assertThat("colorProperties.size()" , colorProperties.size(), is(0) );
+ }
+
+
+ @Test(expected = NumberFormatException.class)
+ public void CSSColorPropertyValue_wrong_hexColor2()
+ {
+ String code = " color: #FF00FG; ";
+
+ List<CSSColorPropertyValue> colorProperties = getCSSColorPropertyValues(code);
+ assertThat("colorProperties.size()" , colorProperties.size(), is(0) );
+ }
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSColorPropertyValueTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSFunctionCallPropertyValueTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSFunctionCallPropertyValueTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSFunctionCallPropertyValueTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSFunctionCallPropertyValueTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,93 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.css;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSPropertyValue;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link CSSFunctionCallPropertyValue}.
+ *
+ * @author Gordon Smith
+ */
+public class CSSFunctionCallPropertyValueTests extends CSSPropertyValueTests {
+
+ private List<CSSFunctionCallPropertyValue> getCSSFunctionCallPropertyValues(String code) {
+ List<ICSSPropertyValue> propertyValues = getCSSPropertyValues(code);
+ List<CSSFunctionCallPropertyValue> stringPropertyValues = new ArrayList<CSSFunctionCallPropertyValue>();
+ for (ICSSPropertyValue icssPropertyValue : propertyValues) {
+ if(icssPropertyValue instanceof CSSFunctionCallPropertyValue)
+ stringPropertyValues.add( (CSSFunctionCallPropertyValue) icssPropertyValue );
+ }
+ return stringPropertyValues;
+ }
+
+ @Test
+ public void CSSFunctionCallPropertyValue_embed()
+ {
+ String code = " overSkin: Embed(\"image.gif\");";
+
+ List<CSSFunctionCallPropertyValue> functionCallProperties = getCSSFunctionCallPropertyValues(code);
+ assertThat("functionCallProperties.size()" , functionCallProperties.size(), is(1) );
+
+ CSSFunctionCallPropertyValue functionCallPropertyValue = functionCallProperties.get(0);
+ assertThat("functionCallPropertyValue.name" , functionCallPropertyValue.name, is( CSSFunctionCallPropertyValue.EMBED ) );
+ assertThat("functionCallPropertyValue.rawArguments" , functionCallPropertyValue.rawArguments, is( "\"image.gif\"" ) );
+ }
+
+ @Test
+ public void CSSFunctionCallPropertyValue_propertyReference()
+ {
+ String code = " color: PropertyReference('colorValue');";
+
+ List<CSSFunctionCallPropertyValue> functionCallProperties = getCSSFunctionCallPropertyValues(code);
+ assertThat("functionCallProperties.size()" , functionCallProperties.size(), is(1) );
+
+ CSSFunctionCallPropertyValue functionCallPropertyValue = functionCallProperties.get(0);
+ assertThat("functionCallPropertyValue.name" , functionCallPropertyValue.name, is( CSSFunctionCallPropertyValue.PROPERTY_REFERENCE ) );
+ assertThat("functionCallPropertyValue.rawArguments" , functionCallPropertyValue.rawArguments, is( "'colorValue'" ) );
+ }
+
+ @Test
+ public void CSSFunctionCallPropertyValue_classReference()
+ {
+ String code = " overSkin: ClassReference('Label');";
+
+ List<CSSFunctionCallPropertyValue> functionCallProperties = getCSSFunctionCallPropertyValues(code);
+ assertThat("functionCallProperties.size()" , functionCallProperties.size(), is(1) );
+
+ CSSFunctionCallPropertyValue functionCallPropertyValue = functionCallProperties.get(0);
+ assertThat("functionCallPropertyValue.name" , functionCallPropertyValue.name, is( CSSFunctionCallPropertyValue.CLASS_REFERENCE ) );
+ assertThat("functionCallPropertyValue.rawArguments" , functionCallPropertyValue.rawArguments, is( "'Label'" ) );
+ }
+
+ @Test
+ public void CSSFunctionCallPropertyValue_static_getSingleArgumentFromRaw() {
+ assertThat("", CSSFunctionCallPropertyValue.getSingleArgumentFromRaw("\"Test\""), is("Test") );
+ assertThat("", CSSFunctionCallPropertyValue.getSingleArgumentFromRaw("'Test'"), is("Test") );
+ }
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSFunctionCallPropertyValueTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSKeywordPropertyValueTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSKeywordPropertyValueTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSKeywordPropertyValueTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSKeywordPropertyValueTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,69 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.css;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSPropertyValue;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link CSSKeywordPropertyValue}.
+ *
+ * @author Gordon Smith
+ */
+public class CSSKeywordPropertyValueTests extends CSSPropertyValueTests {
+
+ private List<CSSKeywordPropertyValue> getCSSKeywordPropertyValues(String code) {
+ List<ICSSPropertyValue> propertyValues = getCSSPropertyValues(code);
+ List<CSSKeywordPropertyValue> stringPropertyValues = new ArrayList<CSSKeywordPropertyValue>();
+ for (ICSSPropertyValue icssPropertyValue : propertyValues) {
+ if(icssPropertyValue instanceof CSSKeywordPropertyValue)
+ stringPropertyValues.add( (CSSKeywordPropertyValue) icssPropertyValue );
+ }
+ return stringPropertyValues;
+ }
+
+ @Test
+ public void CSSKeywordPropertyValue_keyword()
+ {
+ String code = " color: keyWord; ";
+
+ List<CSSKeywordPropertyValue> keywordProperties = getCSSKeywordPropertyValues(code);
+ assertThat("keywordProperties.size()" , keywordProperties.size(), is(1) );
+
+ CSSKeywordPropertyValue keywordPropertyValue = keywordProperties.get(0);
+ assertThat("keywordPropertyValue.getValue()" , keywordPropertyValue.getKeyword(), is( "keyWord" ) );
+ }
+
+ @Test
+ public void CSSKeywordPropertyValue_color_keyword()
+ {
+ String code = " color: orange; ";
+
+ List<CSSKeywordPropertyValue> keywordProperties = getCSSKeywordPropertyValues(code);
+ assertThat("keywordProperties.size()" , keywordProperties.size(), is(0) );
+ }
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSKeywordPropertyValueTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSNumberPropertyValueTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSNumberPropertyValueTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSNumberPropertyValueTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSNumberPropertyValueTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,166 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.css;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSPropertyValue;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link CSSNumberPropertyValue}.
+ *
+ * @author Gordon Smith
+ */
+public class CSSNumberPropertyValueTests extends CSSPropertyValueTests {
+
+ private List<CSSNumberPropertyValue> getCSSNumberPropertyValues(String code) {
+ List<ICSSPropertyValue> propertyValues = getCSSPropertyValues(code);
+ List<CSSNumberPropertyValue> stringPropertyValues = new ArrayList<CSSNumberPropertyValue>();
+ for (ICSSPropertyValue icssPropertyValue : propertyValues) {
+ if(icssPropertyValue instanceof CSSNumberPropertyValue)
+ stringPropertyValues.add( (CSSNumberPropertyValue) icssPropertyValue );
+ }
+ return stringPropertyValues;
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_number()
+ {
+ String code = " fontSize: 10; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue numberPropertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , numberPropertyValue.getUnit(), is( "" ) );
+ assertThat("numberPropertyValue.getNumber()" , numberPropertyValue.getNumber(), is( (Number) new Float(10) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_pixel_number()
+ {
+ String code = " fontSize: 10px; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue propertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , propertyValue.getUnit(), is( "px" ) );
+ assertThat("numberPropertyValue.getNumber()" , propertyValue.getNumber(), is( (Number) new Float(10) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_em_number()
+ {
+ String code = " fontSize: 10em; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue propertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , propertyValue.getUnit(), is( "em" ) );
+ assertThat("numberPropertyValue.getNumber()" , propertyValue.getNumber(), is( (Number) new Float(10) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_percentage_number()
+ {
+ String code = " fontSize: 10%; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue numberPropertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , numberPropertyValue.getUnit(), is( "%" ) );
+ assertThat("numberPropertyValue.getNumber()" , numberPropertyValue.getNumber(), is( (Number) new Float(10) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_negative_number()
+ {
+ String code = " left: -10; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue numberPropertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , numberPropertyValue.getUnit(), is( "" ) );
+ assertThat("numberPropertyValue.getNumber()" , numberPropertyValue.getNumber(), is( (Number) new Float(-10) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_positive_number()
+ {
+ String code = " left: +10; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue numberPropertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , numberPropertyValue.getUnit(), is( "" ) );
+ assertThat("numberPropertyValue.getNumber()" , numberPropertyValue.getNumber(), is( (Number) new Float(10) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_decimal_number()
+ {
+ String code = " left: .31; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue numberPropertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()()" , numberPropertyValue.getUnit(), is( "" ) );
+ assertThat("numberPropertyValue.getNumber()()" , numberPropertyValue.getNumber(), is( (Number) new Float(.31) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_positive_decimal_number()
+ {
+ String code = " left: +10.31; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue numberPropertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , numberPropertyValue.getUnit(), is( "" ) );
+ assertThat("numberPropertyValue.getNumber()" , numberPropertyValue.getNumber(), is( (Number) new Float(10.31) ) );
+ }
+
+ @Test
+ public void CSSNumberPropertyValue_negative_decimal_number()
+ {
+ String code = " left: -10.31; ";
+
+ List<CSSNumberPropertyValue> numberProperties = getCSSNumberPropertyValues(code);
+ assertThat("numberProperties.size()" , numberProperties.size(), is(1) );
+
+ CSSNumberPropertyValue numberPropertyValue = numberProperties.get(0);
+ assertThat("numberPropertyValue.getUnit()" , numberPropertyValue.getUnit(), is( "" ) );
+ assertThat("numberPropertyValue.getNumber()" , numberPropertyValue.getNumber(), is( (Number) new Float(-10.31) ) );
+ }
+
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSNumberPropertyValueTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSPropertyValueTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSPropertyValueTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSPropertyValueTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSPropertyValueTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,81 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.css;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSDocument;
+import org.apache.flex.compiler.css.ICSSProperty;
+import org.apache.flex.compiler.css.ICSSPropertyValue;
+import org.apache.flex.compiler.css.ICSSRule;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * JUnit tests for {@link CSSPropertyValue}.
+ *
+ * @author Gordon Smith
+ */
+public class CSSPropertyValueTests extends CSSBaseTests {
+
+ private static final String EOL = "\n\t\t";
+
+ protected String getPrefix()
+ {
+ return "s|Label {" + EOL;
+ }
+
+ protected String getPostfix()
+ {
+ return EOL +
+ "}";
+ }
+
+ @Override
+ public ICSSDocument getCSSNodeBase(String code) {
+ return super.getCSSNodeBase(getPrefix() + code + getPostfix());
+ }
+
+ private List<ICSSProperty> getCSSProperties(String code) {
+ ICSSDocument doc = getCSSNodeBase(code);
+
+ ImmutableList<ICSSRule> rules = doc.getRules();
+ List<ICSSProperty> properties = new ArrayList<ICSSProperty>();
+ for (ICSSRule icssRule : rules) {
+ properties.addAll( icssRule.getProperties() );
+ }
+
+ return properties;
+ }
+
+ protected List<ICSSPropertyValue> getCSSPropertyValues(String code) {
+ List<ICSSProperty> properties = getCSSProperties(code);
+
+ List<ICSSPropertyValue> propertyValues = new ArrayList<ICSSPropertyValue>();
+
+ for (ICSSProperty icssProperty : properties) {
+ propertyValues.add( icssProperty.getValue() );
+ }
+
+ return propertyValues;
+ }
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSPropertyValueTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSStringPropertyValueTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSStringPropertyValueTests.java?rev=1415473&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSStringPropertyValueTests.java (added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSStringPropertyValueTests.java Fri Nov 30 01:43:12 2012
@@ -0,0 +1,81 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.css;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.css.ICSSPropertyValue;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link CSSStringPropertyValue}.
+ *
+ * @author Gordon Smith
+ */
+public class CSSStringPropertyValueTests extends CSSPropertyValueTests {
+
+ private List<CSSStringPropertyValue> getCSSStringPropertyValues(String code) {
+ List<ICSSPropertyValue> propertyValues = getCSSPropertyValues(code);
+ List<CSSStringPropertyValue> stringPropertyValues = new ArrayList<CSSStringPropertyValue>();
+ for (ICSSPropertyValue icssPropertyValue : propertyValues) {
+ if(icssPropertyValue instanceof CSSStringPropertyValue)
+ stringPropertyValues.add( (CSSStringPropertyValue) icssPropertyValue );
+ }
+ return stringPropertyValues;
+ }
+
+ @Test
+ public void CSSStringPropertyValue_doubleQuoted_text()
+ {
+ String code = " fontFamily: \"Verdana\"; ";
+
+ List<CSSStringPropertyValue> stringProperties = getCSSStringPropertyValues(code);
+ assertThat("stringProperties.size()" , stringProperties.size(), is(1) );
+
+ CSSStringPropertyValue stringPropertyValue = stringProperties.get(0);
+ assertThat("stringPropertyValue.getValue()" , stringPropertyValue.getValue(), is( "Verdana" ) );
+ }
+
+ @Test
+ public void CSSStringPropertyValue_singleQuoted_text()
+ {
+ String code = " fontFamily: 'Verdana'; ";
+
+ List<CSSStringPropertyValue> stringProperties = getCSSStringPropertyValues(code);
+ assertThat("stringProperties.size()" , stringProperties.size(), is(1) );
+
+ CSSStringPropertyValue stringPropertyValue = stringProperties.get(0);
+ assertThat("stringPropertyValue.getValue()" , stringPropertyValue.getValue(), is( "Verdana" ) );
+ }
+
+ @Test
+ public void CSSStringPropertyValue_doubleQuoted_text2()
+ {
+ String code = " fontFamily: \"Ver'dana\"; ";
+
+ List<CSSStringPropertyValue> stringProperties = getCSSStringPropertyValues(code);
+ assertThat("stringProperties.size()" , stringProperties.size(), is(0) );
+ }
+
+}
Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/css/CSSStringPropertyValueTests.java
------------------------------------------------------------------------------
svn:eol-style = native