You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by go...@apache.org on 2013/01/11 22:44:11 UTC
svn commit: r1432297 - in
/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml:
MXMLComponentNodeTests.java MXMLDefinitionNodeTests.java
Author: gordonsmith
Date: Fri Jan 11 21:44:11 2013
New Revision: 1432297
URL: http://svn.apache.org/viewvc?rev=1432297&view=rev
Log:
Falcon: Added parsing unit tests for MXMLComponentNode (which represents a <Component> tag) and MXMLDefinitionNode (which represents a <Definition> tag).
Added:
flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLComponentNodeTests.java (with props)
flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLDefinitionNodeTests.java (with props)
Added: flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLComponentNodeTests.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLComponentNodeTests.java?rev=1432297&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLComponentNodeTests.java (added)
+++ flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLComponentNodeTests.java Fri Jan 11 21:44:11 2013
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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.tree.mxml;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.core.Is.is;
+
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLClassNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLComponentNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link MXMLComponentNode}.
+ *
+ * @author Gordon Smith
+ */
+public class MXMLComponentNodeTests extends MXMLInstanceNodeTests
+{
+ private static String EOL = "\n\t\t";
+
+ private IMXMLComponentNode getMXMLComponentNode(String code)
+ {
+ IMXMLFileNode fileNode = getMXMLFileNode(code);
+ IMXMLComponentNode node = (IMXMLComponentNode)findFirstDescendantOfType(fileNode, IMXMLComponentNode.class);
+ assertThat("getNodeID", node.getNodeID(), is(ASTNodeID.MXMLComponentID));
+ //assertThat("getName", node.getName(), is("Component"));
+ return node;
+ }
+
+ // Note: getClassName() always returns null for an IMXMLComponentNode.
+ // It is non-null in the case of an IFactoryNode that gets created
+ // for the value of a property of type IFactory.
+
+ @Test
+ public void MXMLComponentNode_empty1()
+ {
+ String code = "<fx:Component/>";
+ IMXMLComponentNode node = getMXMLComponentNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(0));
+ assertThat("getID", node.getID(), is((String)null));
+ assertThat("getClassNode", node.getClassNode(), is((IMXMLClassNode)null));
+ assertThat("getClassName", node.getClassName(), is((String)null));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is((IMXMLClassDefinitionNode)null));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition(), is((IClassDefinition)null));
+ }
+
+ @Test
+ public void MXMLComponentNode_empty2()
+ {
+ String code =
+ "<fx:Component>" + EOL +
+ "</fx:Component>";
+ IMXMLComponentNode node = getMXMLComponentNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(0));
+ assertThat("getID", node.getID(), is((String)null));
+ assertThat("getClassNode", node.getClassNode(), is((IMXMLClassNode)null));
+ assertThat("getClassName", node.getClassName(), is((String)null));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is((IMXMLClassDefinitionNode)null));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition(), is((IClassDefinition)null));
+ }
+
+ @Test
+ public void MXMLComponentNode_Sprite()
+ {
+ String code =
+ "<fx:Component>" + EOL +
+ " <d:Sprite/>" + EOL +
+ "</fx:Component>";
+ IMXMLComponentNode node = getMXMLComponentNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(1));
+ assertThat("getID", node.getID(), is((String)null));
+ assertThat("getClassNode", node.getClassNode(), is((IMXMLClassNode)null));
+ assertThat("getClassName", node.getClassName(), is((String)null));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is(node.getChild(0)));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition().isInstanceOf("flash.display.Sprite", project), is(true));
+ }
+
+ @Test
+ public void MXMLComponentNode_className_Sprite()
+ {
+ String code =
+ "<fx:Component className='MySprite'>" + EOL +
+ " <d:Sprite/>" + EOL +
+ "</fx:Component>";
+ IMXMLComponentNode node = getMXMLComponentNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(1));
+ assertThat("getID", node.getID(), is((String)null));
+ assertThat("getClassNode", node.getClassNode(), is((IMXMLClassNode)null));
+ assertThat("getClassName", node.getClassName(), is("MySprite"));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is(node.getChild(0)));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition().isInstanceOf("flash.display.Sprite", project), is(true));
+ }
+
+ @Test
+ public void MXMLComponentNode_id_Sprite()
+ {
+ String code =
+ "<fx:Component id='c1'>" + EOL +
+ " <d:Sprite/>" + EOL +
+ "</fx:Component>";
+ IMXMLComponentNode node = getMXMLComponentNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(1));
+ assertThat("getID", node.getID(), is("c1"));
+ assertThat("getClassNode", node.getClassNode(), is((IMXMLClassNode)null));
+ assertThat("getClassName", node.getClassName(), is((String)null));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is(node.getChild(0)));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition().isInstanceOf("flash.display.Sprite", project), is(true));
+ }
+
+ @Test
+ public void MXMLComponentNode_className_id_Sprite_width_height()
+ {
+ String code =
+ "<fx:Component id='c1' className='MySprite'>" + EOL +
+ " <d:Sprite width='100'>" + EOL +
+ " <d:height>100</d:height>" + EOL +
+ " </d:Sprite>" + EOL +
+ "</fx:Component>";
+ IMXMLComponentNode node = getMXMLComponentNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(1));
+ assertThat("getID", node.getID(), is("c1"));
+ assertThat("getClassNode", node.getClassNode(), is((IMXMLClassNode)null));
+ assertThat("getClassName", node.getClassName(), is("MySprite"));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is(node.getChild(0)));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition().isInstanceOf("flash.display.Sprite", project), is(true));
+ assertThat("getContainedClassDefinitionNode.getChildCount", node.getContainedClassDefinitionNode().getChildCount(), is(2));
+
+ }
+}
Propchange: flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLComponentNodeTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLDefinitionNodeTests.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLDefinitionNodeTests.java?rev=1432297&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLDefinitionNodeTests.java (added)
+++ flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLDefinitionNodeTests.java Fri Jan 11 21:44:11 2013
@@ -0,0 +1,143 @@
+/*
+ *
+ * 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.tree.mxml;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.core.Is.is;
+
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLDefinitionNode;
+import org.apache.flex.compiler.tree.mxml.IMXMLFileNode;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link MXMLDefinitionNode}.
+ *
+ * @author Gordon Smith
+ */
+public class MXMLDefinitionNodeTests extends MXMLNodeBaseTests
+{
+ private static String EOL = "\n\t\t";
+
+ protected 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:Library>\n" +
+ " ";
+ }
+
+ protected String getPostfix()
+ {
+ return "\n" +
+ " </fx:Library>\n" +
+ "</d:Sprite>";
+ }
+
+ @Override
+ protected IMXMLFileNode getMXMLFileNode(String code)
+ {
+ return super.getMXMLFileNode(getPrefix() + code + getPostfix());
+ }
+
+ private IMXMLDefinitionNode getMXMLDefinitionNode(String code)
+ {
+ IMXMLFileNode fileNode = getMXMLFileNode(code);
+ IMXMLDefinitionNode node = (IMXMLDefinitionNode)findFirstDescendantOfType(fileNode, IMXMLDefinitionNode.class);
+ assertThat("getNodeID", node.getNodeID(), is(ASTNodeID.MXMLDefinitionID));
+ assertThat("getName", node.getName(), is("Definition"));
+ return node;
+ }
+
+ // Note: getDefinitionName() always returns null for an IMXMLDefinitionNode.
+ // It is non-null in the case of an IFactoryNode that gets created
+ // for the value of a property of type IFactory.
+
+ @Test
+ public void MXMLDefinitionNode_empty1()
+ {
+ String code = "<fx:Definition/>";
+ IMXMLDefinitionNode node = getMXMLDefinitionNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(0));
+ assertThat("getName", node.getDefinitionName(), is((String)null));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is((IMXMLClassDefinitionNode)null));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition(), is((IClassDefinition)null));
+ }
+
+ @Test
+ public void MXMLDefinitionNode_empty2()
+ {
+ String code =
+ "<fx:Definition>" + EOL +
+ "</fx:Definition>";
+ IMXMLDefinitionNode node = getMXMLDefinitionNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(0));
+ assertThat("getDefinitionName", node.getDefinitionName(), is((String)null));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is((IMXMLClassDefinitionNode)null));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition(), is((IClassDefinition)null));
+ }
+
+ @Test
+ public void MXMLDefinitionNode_Sprite()
+ {
+ String code =
+ "<fx:Definition>" + EOL +
+ " <d:Sprite/>" + EOL +
+ "</fx:Definition>";
+ IMXMLDefinitionNode node = getMXMLDefinitionNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(1));
+ assertThat("getDefinitionName", node.getDefinitionName(), is((String)null));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is(node.getChild(0)));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition().isInstanceOf("flash.display.Sprite", project), is(true));
+ }
+
+ @Test
+ public void MXMLDefinitionNode_name_Sprite()
+ {
+ String code =
+ "<fx:Definition name='MySprite'>" + EOL +
+ " <d:Sprite/>" + EOL +
+ "</fx:Definition>";
+ IMXMLDefinitionNode node = getMXMLDefinitionNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(1));
+ assertThat("getDefinitionName", node.getDefinitionName(), is("MySprite"));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is(node.getChild(0)));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition().isInstanceOf("flash.display.Sprite", project), is(true));
+ }
+
+ @Test
+ public void MXMLDefinitionNode_name_Sprite_width_height()
+ {
+ String code =
+ "<fx:Definition name='MySprite'>" + EOL +
+ " <d:Sprite width='100'>" + EOL +
+ " <d:height>100</d:height>" + EOL +
+ " </d:Sprite>" + EOL +
+ "</fx:Definition>";
+ IMXMLDefinitionNode node = getMXMLDefinitionNode(code);
+ assertThat("getChildCount", node.getChildCount(), is(1));
+ assertThat("getDefinitionName", node.getDefinitionName(), is("MySprite"));
+ assertThat("getContainedClassDefinitionNode", node.getContainedClassDefinitionNode(), is(node.getChild(0)));
+ assertThat("getContainedClassDefinition", node.getContainedClassDefinition().isInstanceOf("flash.display.Sprite", project), is(true));
+ assertThat("getContainedClassDefinitionNode.getChildCount", node.getContainedClassDefinitionNode().getChildCount(), is(2));
+
+ }
+}
Propchange: flex/falcon/trunk/compiler.tests/unit-tests/org/apache/flex/compiler/internal/tree/mxml/MXMLDefinitionNodeTests.java
------------------------------------------------------------------------------
svn:eol-style = native