incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gordonsm...@apache.org
Subject svn commit: r1425203 - in /incubator/flex/falcon/trunk: compiler.tests/feature-tests/mxml/tags/ compiler/src/org/apache/flex/compiler/internal/as/codegen/
Date Fri, 21 Dec 2012 23:57:23 GMT
Author: gordonsmith
Date: Fri Dec 21 23:57:23 2012
New Revision: 1425203

URL: http://svn.apache.org/viewvc?rev=1425203&view=rev
Log:
Falcon tests: Added some functional tests for the <XMLList> tag.

Added one test and fixed a bug related to <XML format="xml"> tag, which produces an
XMLNode. However, there is an XML namespace issue preventing the test from passing (because
when the tag gets converted into an XML string Falcon is adding empty namespace attributes
that the old compiler didn't) so this test is marked @Ignore.

Added:
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLListTagTests.java
  (with props)
Modified:
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLTagTests.java
    incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java

Added: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLListTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLListTagTests.java?rev=1425203&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLListTagTests.java
(added)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLListTagTests.java
Fri Dec 21 23:57:23 2012
@@ -0,0 +1,156 @@
+/*
+ *
+ *  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 mxml.tags;
+
+import org.junit.Test;
+
+/**
+ * Feature tests for the MXML {@code <XMLList>} tag.
+ * 
+ * @author Gordon Smith
+ */
+public class MXMLXMLListTagTests extends MXMLInstanceTagTestsBase
+{
+    @Test
+    public void MXMLXMLListTag_empty()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:XMLList id='x1'>",
+            "</fx:XMLList>"
+        };
+        String[] asserts = new String[]
+        {
+        	// An empty tag produces an XMLList with length 0.
+            "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+            "assertEqual('x1.length()', x1.length(), 0);",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLXMLListTag_oneEmptyTag()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:XMLList id='x1' xmlns=''>",
+            "    <aaa/>",
+            "</fx:XMLList>"
+        };
+        String[] asserts = new String[]
+        {
+            "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+            "assertEqual('x1.length()', x1.length(), 1);",
+            "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+            "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+            "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+            "assertEqual('x1[0].attributes().length()', x1[0].attributes().length(), 0);",
+            "assertEqual('x1[0].children().length()', x1[0].children().length(), 0);",
+
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLXMLListTag_twoEmptyTags()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:XMLList id='x1' xmlns=''>",
+            "    <aaa/>",
+            "    <aaa/>",
+            "</fx:XMLList>"
+        };
+        String[] asserts = new String[]
+        {
+            "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+            "assertEqual('x1.length()', x1.length(), 2);",
+            "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+            "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+            "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+            "assertEqual('x1[0].attribute().length()', x1[0].attributes().length(), 0);",
+            "assertEqual('x1[0].children().length()', x1[0].children().length(), 0);",
+            "assertEqual('x1[1].nodeKind()', x1[1].nodeKind(), 'element');",
+            "assertEqual('x1[1].localName()', x1[1].localName(), 'aaa');",
+            "assertEqual('x1[1].namespace().uri', x1[1].namespace().uri, '');",
+            "assertEqual('x1[1].attributes().length', x1[1].attributes().length(), 0);",
+            "assertEqual('x1[1].children().length()', x1[1].children().length(), 0);",
+
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLXMLListTag_oneTagWithAttributes()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:XMLList id='x1' xmlns=''>",
+            "    <aaa a='1' b='2'/>",
+            "</fx:XMLList>"
+        };
+        String[] asserts = new String[]
+        {
+            "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+            "assertEqual('x1.length()', x1.length(), 1);",
+            "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+            "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+            "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+            "assertEqual('x1[0].attributes().length()', x1[0].attributes().length(), 2);",
+            "assertEqual('x1[0].@a.toString()', x1[0].@a.toString(), '1');",
+            "assertEqual('x1[0].@b.toString()', x1[0].@b.toString(), '2');",
+            "assertEqual('x1[0].children().length()', x1[0].children().length(), 0);"
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLXMLListTag_oneTagWithChildren()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:XMLList id='x1' xmlns=''>",
+            "    <aaa>",
+            "       <bbb>xxx</bbb>",
+            "       <bbb>yyy</bbb>",
+            "    </aaa>",
+            "</fx:XMLList>"
+        };
+        String[] asserts = new String[]
+        {
+            "assertEqual('x1 is XMLList', x1 is XMLList, true);",
+            "assertEqual('x1.length()', x1.length(), 1);",
+            "assertEqual('x1[0].nodeKind()', x1[0].nodeKind(), 'element');",
+            "assertEqual('x1[0].localName()', x1[0].localName(), 'aaa');",
+            "assertEqual('x1[0].namespace().uri', x1[0].namespace().uri, '');",
+            "assertEqual('x1[0].attributes().length()', x1[0].attributes().length(), 0);",
+            "assertEqual('x1[0].children().length()', x1[0].children().length(), 2);",
+            "assertEqual('x1[0].bbb[0].toString()', x1[0].bbb[0].toString(), 'xxx');",
+            "assertEqual('x1[0].bbb[1].toString()', x1[0].bbb[1].toString(), 'yyy');"
+
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+}

Propchange: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLListTagTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLTagTests.java?rev=1425203&r1=1425202&r2=1425203&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLTagTests.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLXMLTagTests.java
Fri Dec 21 23:57:23 2012
@@ -19,6 +19,7 @@
 
 package mxml.tags;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -28,8 +29,27 @@ import org.junit.Test;
  */
 public class MXMLXMLTagTests extends MXMLInstanceTagTestsBase
 {
+	// This <Script> function is used by some of the asserts in the tests below
+	// to count the number of properties of an <Object>.
+	private static String[] scriptDeclarations = new String[]
+    {
+        "private function countProperties(o:Object):int",
+        "{",
+        "    var count:int = 0;",
+        "    for (var p:String in o)",
+        "    {",
+        "       count++;",
+        "    }",
+        "    return count;",
+        "}"
+	};
+	
+	//
+	// These tests are for XML tags with an implicit format="e4x" 
+	//
+	
     @Test
-    public void MXMLXMLTag_empty()
+    public void MXMLXMLTag_formatE4X_empty()
     {
         String[] declarations = new String[]
         {
@@ -45,7 +65,7 @@ public class MXMLXMLTagTests extends MXM
     }
 	
     @Test
-    public void MXMLXMLTag_emptyRootTag()
+    public void MXMLXMLTag_formatE4X_emptyRootTag()
     {
         String[] declarations = new String[]
         {
@@ -62,7 +82,7 @@ public class MXMLXMLTagTests extends MXM
     }
 	
     @Test
-    public void MXMLXMLTag_oneTagWithText()
+    public void MXMLXMLTag_formatE4X_oneTagWithText()
     {
         String[] declarations = new String[]
         {
@@ -82,7 +102,7 @@ public class MXMLXMLTagTests extends MXM
     }
 	
     @Test
-    public void MXMLXMLTag_oneTagWithAttributes()
+    public void MXMLXMLTag_formatE4X_oneTagWithAttributes()
     {
         String[] declarations = new String[]
         {
@@ -103,7 +123,7 @@ public class MXMLXMLTagTests extends MXM
     }
     	
     @Test
-    public void MXMLXMLTag_oneTagWithTwoChildTags()
+    public void MXMLXMLTag_formatE4X_oneTagWithTwoChildTags()
     {
         String[] declarations = new String[]
         {
@@ -125,4 +145,38 @@ public class MXMLXMLTagTests extends MXM
         String mxml = getMXML(declarations, asserts);
         compileAndRun(mxml);
     }
+    
+	//
+	// These tests are for XML tags with format="xml",
+    // which produce a tree of XMLNode objects.
+    // These tests have to be compiled against framework.swc
+    // in order to get the mx.utils.XMLUtils class.
+	//
+    
+    // This test seems to be failing because our xmlString is
+    // <root xmlns=""/>
+    // while the old compiler's was
+    // <root/>
+    @Ignore
+    @Test
+    public void MXMLXMLTag_formatXML_emptyRootTag()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:XML id='x1' xmlns='' format='xml'>",
+            "    <root/>",
+            "</fx:XML>"
+        };
+        String[] asserts = new String[]
+        {
+            "assertEqual('x1 is XMLNode', x1 is XMLNode, true);",
+            "trace(x1.localName === null);",
+            "assertEqual('x1.localName', x1.localName, 'root');",
+            "assertEqual('x1.namespaceURI', x1.namespaceURI, null);",
+            "assertEqual('countProperties(x1.attributes)', countProperties(x1.attributes),
0);",
+            "assertEqual('x1.childNodes.length', x1.childNodes.length, 0);"
+        };
+        String mxml = getMXML(declarations, scriptDeclarations, asserts);
+        compileAndRun(mxml, true, false, false, null);
+    }
 }

Modified: incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java?rev=1425203&r1=1425202&r2=1425203&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java
(original)
+++ incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java
Fri Dec 21 23:57:23 2012
@@ -4225,16 +4225,19 @@ public class MXMLClassDirectiveProcessor
         }
         else if (node.getXMLType() == IMXMLXMLNode.XML_TYPE.E4X)
         {
+            // new XML(xmlString);
             context.addInstruction(OP_findpropstrict, ABCGeneratingReducer.xmlType);
             context.addInstruction(OP_pushstring, xmlString);
             context.addInstruction(OP_constructprop, new Object[] { ABCGeneratingReducer.xmlType,
1 });
          }
         else if (node.getXMLType() == IMXMLXMLNode.XML_TYPE.OLDXML)
         {
+            // mx.utils.XMLUtil.createXMLDocument(xmlString).firstChild
             FlexProject flexProject = (FlexProject)getProject();
             context.addInstruction(OP_getlex, flexProject.getXMLUtilClassName());
             context.addInstruction(OP_pushstring, node.getXMLString());
             context.addInstruction(OP_callproperty, CREATE_XML_DOCUMENT_CALL_OPERANDS);
+            context.addInstruction(OP_getproperty, new Name("firstChild"));
         }
 
         // Traverse the children - these will be any MXMLBindingNode that were created for



Mime
View raw message