incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gordonsm...@apache.org
Subject svn commit: r1405244 - in /incubator/flex/falcon/trunk/compiler.tests: .classpath unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLScriptNodeTests.java unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLStyleNodeTests.java
Date Sat, 03 Nov 2012 00:39:07 GMT
Author: gordonsmith
Date: Sat Nov  3 00:39:07 2012
New Revision: 1405244

URL: http://svn.apache.org/viewvc?rev=1405244&view=rev
Log:
Falcon: Added nontrivial tests for parsing <Script> and <Style> tags.

This required guava.jar to be added to the Eclipse class path.

Added:
    incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLScriptNodeTests.java
  (with props)
    incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLStyleNodeTests.java
  (with props)
Modified:
    incubator/flex/falcon/trunk/compiler.tests/.classpath

Modified: incubator/flex/falcon/trunk/compiler.tests/.classpath
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/.classpath?rev=1405244&r1=1405243&r2=1405244&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/.classpath (original)
+++ incubator/flex/falcon/trunk/compiler.tests/.classpath Sat Nov  3 00:39:07 2012
@@ -6,5 +6,6 @@
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="/compiler/lib/commons-io.jar"/>
 	<classpathentry kind="src" path="/compiler"/>
+	<classpathentry kind="lib" path="/compiler/lib/guava.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLScriptNodeTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLScriptNodeTests.java?rev=1405244&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLScriptNodeTests.java
(added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLScriptNodeTests.java
Sat Nov  3 00:39:07 2012
@@ -0,0 +1,78 @@
+package org.apache.flex.compiler.internal.tree.mxml;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLScriptNode;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link MXMLScriptNode}.
+ * 
+ * @author Gordon Smith
+ */
+public class MXMLScriptNodeTests extends MXMLNodeBaseTests
+{
+	private static String PREFIX =
+	    "<d:Sprite xmlns:fx='http://ns.adobe.com/mxml/2009' xmlns:d='flash.display.*'>\n\t";
+				
+	private static String POSTFIX =
+		"\n</d:Sprite>";
+	    
+	private static String EOL = "\n\t";
+	
+    @Override
+    protected IMXMLFileNode getMXMLFileNode(String code)
+    {
+    	return super.getMXMLFileNode(PREFIX + code + POSTFIX);
+    }
+    
+	private IMXMLScriptNode getMXMLScriptNode(String code)
+	{
+		IMXMLFileNode fileNode = getMXMLFileNode(code);
+		IMXMLScriptNode node = (IMXMLScriptNode)findFirstDescendantOfType(fileNode, IMXMLScriptNode.class);
+		assertThat("getNodeID", node.getNodeID(), is(ASTNodeID.MXMLScriptID));
+		assertThat("getName", node.getName(), is("Script"));
+		return node;
+	}
+	
+	@Test
+	public void MXMLScriptNode_empty1()
+	{
+		String code = "<fx:Script/>";
+		IMXMLScriptNode node = getMXMLScriptNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(0));
+	}
+	
+	@Test
+	public void MXMLScriptNode_empty2()
+	{
+		String code = "<fx:Script></fx:Script>";
+		IMXMLScriptNode node = getMXMLScriptNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(0));
+	}
+	
+	@Test
+	public void MXMLScriptNode_empty3()
+	{
+		String code = "<fx:Script/> \t\r\n<fx:Script/>";
+		IMXMLScriptNode node = getMXMLScriptNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(0));
+	}
+	
+	@Test
+	public void MXMLScriptNode_var_and_function()
+	{
+		String code =
+			"<fx:Script>" + EOL +
+			"    private var i:int = 1;" + EOL +
+			"    private function f():void { };" + EOL +
+			"</fx:Script>";
+		IMXMLScriptNode node = getMXMLScriptNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(2));
+		assertThat("child 0", node.getChild(0).getNodeID(), is(ASTNodeID.VariableID));
+		assertThat("child 1", node.getChild(1).getNodeID(), is(ASTNodeID.FunctionID));
+	}
+}

Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLScriptNodeTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLStyleNodeTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLStyleNodeTests.java?rev=1405244&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLStyleNodeTests.java
(added)
+++ incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLStyleNodeTests.java
Sat Nov  3 00:39:07 2012
@@ -0,0 +1,85 @@
+package org.apache.flex.compiler.internal.tree.mxml;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.flex.compiler.css.ICSSDocument;
+import org.apache.flex.compiler.css.ICSSRule;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLStyleNode;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * JUnit tests for {@link MXMLStyleNode}.
+ * 
+ * @author Gordon Smith
+ */
+public class MXMLStyleNodeTests extends MXMLNodeBaseTests
+{
+	private static String PREFIX =
+	    "<d:Sprite xmlns:fx='http://ns.adobe.com/mxml/2009' xmlns:d='flash.display.*'>\n\t";
+				
+	private static String POSTFIX =
+		"\n</d:Sprite>";
+	    
+	private static String EOL = "\n\t";
+	
+    @Override
+    protected IMXMLFileNode getMXMLFileNode(String code)
+    {
+    	return super.getMXMLFileNode(PREFIX + code + POSTFIX);
+    }
+    
+	private IMXMLStyleNode getMXMLStyleNode(String code)
+	{
+		IMXMLFileNode fileNode = getMXMLFileNode(code);
+		IMXMLStyleNode node = (IMXMLStyleNode)findFirstDescendantOfType(fileNode, IMXMLStyleNode.class);
+		assertThat("getNodeID", node.getNodeID(), is(ASTNodeID.MXMLStyleID));
+		assertThat("getName", node.getName(), is("Style"));
+		return node;
+	}
+	
+	@Test
+	public void MXMLStyleNode_empty1()
+	{
+		String code = "<fx:Style/>";
+		IMXMLStyleNode node = getMXMLStyleNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(0));
+	}
+	
+	@Test
+	public void MXMLStyleNode_empty2()
+	{
+		String code = "<fx:Style></fx:Style>";
+		IMXMLStyleNode node = getMXMLStyleNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(0));
+	}
+	
+	@Test
+	public void MXMLStyleNode_empty3()
+	{
+		String code = "<fx:Style/> \t\r\n<fx:Style/>";
+		IMXMLStyleNode node = getMXMLStyleNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(0));
+	}
+	
+	@Test
+	public void MXMLStyleNode_two_rules()
+	{
+		String code =
+			"<fx:Style>" + EOL +
+			"    Button { font-size: 20; color: red }" + EOL +
+			"    CheckBox { font-size: 16 }" + EOL +
+			"</fx:Style>";
+		IMXMLStyleNode node = getMXMLStyleNode(code);
+		assertThat("getChildCount", node.getChildCount(), is(0));
+		ICSSDocument css = node.getCSSDocument(null);
+		ImmutableList<ICSSRule> rules = css.getRules();
+		assertThat("rules", rules.size(), is(2));
+		assertThat("rule 0 name", rules.get(0).getSelectorGroup().get(0).getElementName(), is("Button"));
+		assertThat("rule 1 name", rules.get(1).getSelectorGroup().get(0).getElementName(), is("CheckBox"));
+	}
+}

Propchange: incubator/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLStyleNodeTests.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message