incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gordonsm...@apache.org
Subject svn commit: r1418562 - in /incubator/flex/falcon/trunk: compiler.tests/feature-tests/mxml/tags/ compiler/src/org/apache/flex/compiler/clients/problems/ compiler/src/org/apache/flex/compiler/internal/tree/mxml/
Date Sat, 08 Dec 2012 00:06:32 GMT
Author: gordonsmith
Date: Sat Dec  8 00:06:31 2012
New Revision: 1418562

URL: http://svn.apache.org/viewvc?rev=1418562&view=rev
Log:
Added basic feature tests for the <Object> tag.

One of the tests is marked @Ignore because it doesn't pass. Falcon understand <Object>
tags that have properties, like <Object a="1" b="2"/>, but it doesn't understand primitive
ones like <Object>abc</Object>.

One of the tests that now passes uncovered a bug in MXMLArrayNode which I fixed. The problem
was that a dynamic property like 'a' in <Object a="1" b="2"/> has no definition, because
it isn't declared anywhere.

Feature tests that fail due to compilation problems now show the problems.

Enhanced the getMXML() method of MXMLInstanceTagTestsBase so that you can inject more code
into the <Script> block, such as test functions that you want to use in asserts.


Added:
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLObjectTagTests.java
  (with props)
Modified:
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
    incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLInstanceTagTestsBase.java
    incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/clients/problems/ProblemQuery.java
    incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java?rev=1418562&r1=1418561&r2=1418562&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLFeatureTestsBase.java
Sat Dec  8 00:06:31 2012
@@ -26,8 +26,10 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.flex.compiler.clients.MXMLC;
+import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.utils.FilenameNormalization;
 
 /**
@@ -75,7 +77,14 @@ public class MXMLFeatureTestsBase
 		int exitCode = mxmlc.mainNoExit(args);
 		
 		// Check that there were no compilation problems.
-		assertThat(exitCode, is(0));
+		List<ICompilerProblem> problems = mxmlc.getProblems().getProblems();
+		StringBuilder sb = new StringBuilder("Unxpected compilation problems:\n");
+		for (ICompilerProblem problem : problems)
+		{
+			sb.append(problem.toString());
+			sb.append('\n');
+		}
+		assertThat(sb.toString(), exitCode, is(0));
 		
 		// Run the SWF in the standalone player amd wait until the SWF calls System.exit().
 		String swf = FilenameNormalization.normalize(tempMXMLFile.getAbsolutePath());

Modified: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLInstanceTagTestsBase.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLInstanceTagTestsBase.java?rev=1418562&r1=1418561&r2=1418562&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLInstanceTagTestsBase.java
(original)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLInstanceTagTestsBase.java
Sat Dec  8 00:06:31 2012
@@ -31,7 +31,7 @@ public class MXMLInstanceTagTestsBase ex
 	/**
 	 * Combines various code snippets to make a complete one-file MXML Sprite-based application.
 	 */
-    protected String getMXML(String[] declarations, String[] asserts)
+    protected String getMXML(String[] declarations, String[] scriptDeclarations, String[]
asserts)
     {
         String[] template = new String[]
         {
@@ -42,6 +42,7 @@ public class MXMLInstanceTagTestsBase ex
             "    </fx:Declarations>",
             "    <fx:Script>",
             "    <![CDATA[",
+            "        %2",
             "        private function assertEqual(message:String, actualValue:*, expectedValue:*):void",
             "        {",
             "            if (actualValue !== expectedValue)",
@@ -52,7 +53,7 @@ public class MXMLInstanceTagTestsBase ex
             "        }",
             "        private function enterFrameHandler(event:Event):void",
             "        {",
-            "            %2",
+            "            %3",
             "            System.exit(0);",
             "        }",
             "    ]]>",
@@ -61,7 +62,16 @@ public class MXMLInstanceTagTestsBase ex
         };
         String mxml = StringUtils.join(template, "\n");
         mxml = mxml.replace("%1", StringUtils.join(declarations, "\n        "));
-        mxml = mxml.replace("%2", StringUtils.join(asserts, "\n            "));
+        mxml = mxml.replace("%2", StringUtils.join(scriptDeclarations, "\n        "));
+        mxml = mxml.replace("%3", StringUtils.join(asserts, "\n            "));
         return mxml;
     }
+    
+	/**
+	 * Combines various code snippets to make a complete one-file MXML Sprite-based application.
+	 */
+    protected String getMXML(String[] declarations, String[] asserts)
+    {
+    	return getMXML(declarations, new String[0], asserts);
+    }
 }

Added: incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLObjectTagTests.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLObjectTagTests.java?rev=1418562&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLObjectTagTests.java
(added)
+++ incubator/flex/falcon/trunk/compiler.tests/feature-tests/mxml/tags/MXMLObjectTagTests.java
Sat Dec  8 00:06:31 2012
@@ -0,0 +1,293 @@
+/*
+ *
+ *  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.Ignore;
+import org.junit.Test;
+
+/**
+ * Feature tests for the MXML <Object> tag.
+ * 
+ * @author Gordon Smith
+ */
+public class MXMLObjectTagTests 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;",
+        "}"
+	};
+	
+    @Test
+    public void MXMLObjectTag_empty()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>",
+            "</fx:Object>"
+        };
+        String[] asserts = new String[]
+        {
+            "assertEqual('count(o1)', countProperties(o1), 0);",
+        };
+        String mxml = getMXML(declarations, scriptDeclarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Ignore
+    @Test
+    public void MXMLObjectTag_primitiveValues()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>false</fx:Object>",
+            "<fx:Object id='o2'>true</fx:Object>",
+            "<fx:Object id='o3'>123456</fx:Object>",
+            "<fx:Object id='o4'>0x123456</fx:Object>",
+            "<fx:Object id='o5'>#123456</fx:Object>",
+            "<fx:Object id='o6'>1.5</fx:Object>",
+            "<fx:Object id='o7'>1.5e3</fx:Object>",
+            "<fx:Object id='o8'>NaN</fx:Object>",
+            "<fx:Object id='o9'>Infinity</fx:Object>",
+            "<fx:Object id='o10'>abc</fx:Object>",
+        };
+        String[] asserts = new String[]
+        {
+            "assertEqual('o1', o1, 'false');",
+            "assertEqual('o2', o2, 'true');",
+            "assertEqual('o3', o3, '123456');",
+            "assertEqual('o4', o4, '0x123456');",
+            "assertEqual('o5', o5, '#123456');",
+            "assertEqual('o6', o6, '1.5');",
+            "assertEqual('o7', o7, '1.5e3');",
+            "assertEqual('o8', o8, 'NaN');",
+            "assertEqual('o9', o9, 'Infinity');",
+            "assertEqual('o10', o10, 'abc');",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLObjectTag_primitivePropertyValues1()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>",
+            "    <fx:a>",
+            "        <fx:Boolean>false</fx:Boolean>",
+            "    </fx:a>",
+            "    <fx:b>",
+            "        <fx:Boolean>true</fx:Boolean>",
+            "    </fx:b>",
+            "    <fx:c>",
+            "        <fx:int>123</fx:int>",
+            "    </fx:c>",
+            "    <fx:d>",
+            "        <fx:uint>3000000000</fx:uint>",
+            "    </fx:d>",
+            "    <fx:e>",
+            "        <fx:Number>1.5</fx:Number>",
+            "    </fx:e>",
+            "    <fx:f>",
+            "        <fx:String>abc</fx:String>",
+            "    </fx:f>",
+            "    <fx:g>",
+            "        <fx:Class>flash.display.Sprite</fx:Class>",
+            "    </fx:g>",
+            "</fx:Object>"
+        };
+        String[] asserts = new String[]
+        {
+            //"assertEqual('count(o1)', countProperties(o1), 7);",
+            "assertEqual('o1.a', o1.a, false);",
+            "assertEqual('o1.b', o1.b, true);",
+            "assertEqual('o1.c', o1.c, 123);",
+            "assertEqual('o1.d', o1.d, 3000000000);",
+            "assertEqual('o1.e', o1.e, 1.5);",
+            "assertEqual('o1.f', o1.f, 'abc');",
+            "assertEqual('o1.g', o1.g, Sprite);",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLObjectTag_primitivePropertyValues2()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>",
+            "    <fx:a>false</fx:a>",
+            "    <fx:b>true</fx:b>",
+            "    <fx:c>123</fx:c>",
+            "    <fx:d>3000000000</fx:d>",
+            "    <fx:e>1.5<</fx:e>",
+            "    <fx:f>abc</fx:f>",
+            "    <fx:g>flash.display.Sprite</fx:g>",
+             "</fx:Object>"
+        };
+        String[] asserts = new String[]
+        {
+            //"assertEqual('count(o1)', countProperties(o1), 7);",
+            "assertEqual('o1.a', o1.a, false);",
+            "assertEqual('o1.b', o1.b, true);",
+            "assertEqual('o1.c', o1.c, 123);",
+            "assertEqual('o1.d', o1.d, 3000000000);",
+            "assertEqual('o1.e', o1.e, 1.5);",
+            "assertEqual('o1.f', o1.f, 'abc');",
+            "assertEqual('o1.g', o1.g, 'flash.display.Sprite');",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLObjectTag_primitivePropertyValues3()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'",
+            "    a='false'",
+            "    b='true'",
+            "    c='123'",
+            "    d='3000000000'",
+            "    e='1.5'",
+            "    f='abc'",
+            "    g='flash.display.Sprite'/>"
+        };
+        String[] asserts = new String[]
+        {
+            //"assertEqual('count(o1)', countProperties(o1), 7);",
+            "assertEqual('o1.a', o1.a, false);",
+            "assertEqual('o1.b', o1.b, true);",
+            "assertEqual('o1.c', o1.c, 123);",
+            "assertEqual('o1.d', o1.d, 3000000000);",
+            "assertEqual('o1.e', o1.e, 1.5);",
+            "assertEqual('o1.f', o1.f, 'abc');",
+            "assertEqual('o1.g', o1.g, 'flash.display.Sprite');",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+    
+    @Test
+    public void MXMLObjectTag_arrayPropertyValue()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>",
+            "    <fx:a>",
+            "        <fx:Array>",
+            "            <fx:int>1</fx:int>",
+            "            <fx:int>2</fx:int>",
+            "        </fx:Array>",
+            "    </fx:a>",
+            "</fx:Object>"
+        };
+        String[] asserts = new String[]
+        {
+            //"assertEqual('count(o1)', countProperties(o1), 1);",
+            "assertEqual('o1.a is Array', o1.a is Array, true);",
+            "assertEqual('o1.a.length', o1.a.length, 2);",
+            "assertEqual('o1.a[0]', o1.a[0], 1);",
+            "assertEqual('o1.a[1]', o1.a[1], 2);",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+
+    @Test
+    public void MXMLObjectTag_vectorPropertyValue()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>",
+            "    <fx:a>",
+            "        <fx:Vector type='int'>",
+            "            <fx:int>1</fx:int>",
+            "            <fx:int>2</fx:int>",
+            "        </fx:Vector>",
+            "    </fx:a>",
+            "</fx:Object>"
+        };
+        String[] asserts = new String[]
+        {
+            //"assertEqual('count(o1)', countProperties(o1), 1);",
+            "assertEqual('o1.a is Vector.<int>', o1.a is Vector.<int>, true);",
+            "assertEqual('o1.a.length', o1.a.length, 2);",
+            "assertEqual('o1.a[0]', o1.a[0], 1);",
+            "assertEqual('o1.a[1]', o1.a[1], 2);",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+
+    @Test
+    public void MXMLObjectTag_objectPropertyValue()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>",
+            "    <fx:a>",
+            "        <fx:Object b='123'/>",
+            "    </fx:a>",
+            "</fx:Object>"
+        };
+        String[] asserts = new String[]
+        {
+            //"assertEqual('count(o1)', countProperties(o1), 1);",
+            //"assertEqual('count(o1.a)', count(o1.a), 1);",
+            "assertEqual('o1.a.b', o1.a.b, 123);",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+
+    @Test
+    public void MXMLObjectTag_instancePropertyValue()
+    {
+        String[] declarations = new String[]
+        {
+            "<fx:Object id='o1'>",
+            "    <fx:a>",
+            "        <d:Sprite name='abc'/>",
+            "    </fx:a>",
+            "</fx:Object>"
+        };
+        String[] asserts = new String[]
+        {
+            //"assertEqual('count(o1)', countProperties(o1), 1);",
+            "assertEqual('o1.a is Sprite', o1.a is Sprite, true);",
+            "assertEqual('o1.a.name', o1.a.name, 'abc');",
+        };
+        String mxml = getMXML(declarations, asserts);
+        compileAndRun(mxml);
+    }
+}

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

Modified: incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/clients/problems/ProblemQuery.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/clients/problems/ProblemQuery.java?rev=1418562&r1=1418561&r2=1418562&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/clients/problems/ProblemQuery.java
(original)
+++ incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/clients/problems/ProblemQuery.java
Sat Dec  8 00:06:31 2012
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.List;
 
 import org.apache.flex.compiler.config.ICompilerProblemSettings;
 import org.apache.flex.compiler.problems.AbstractSemanticProblem;
@@ -96,6 +97,14 @@ public class ProblemQuery
     private ICompilerProblemSettings problemSettings;
     
     /**
+     * Gets the list of compiler problems, with no filtering or sorting.
+     */
+    public List<ICompilerProblem> getProblems()
+    {
+        return problems;
+    }
+        
+    /**
      *  Enable or disable strict semantics mode diagnostics.
      *  @param isStrict - if true, strict semantics mode 
      *    diagnostics will appear in the filtered diagnostics.

Modified: incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java?rev=1418562&r1=1418561&r2=1418562&view=diff
==============================================================================
--- incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java
(original)
+++ incubator/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/tree/mxml/MXMLArrayNode.java
Sat Dec  8 00:06:31 2012
@@ -25,6 +25,7 @@ import java.util.List;
 
 import org.apache.flex.compiler.common.SourceLocation;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
+import org.apache.flex.compiler.constants.IASLanguageConstants.BuiltinType;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
@@ -105,8 +106,11 @@ class MXMLArrayNode extends MXMLInstance
             propertyName = ((IMXMLPropertySpecifierNode)parent).getName();
             IVariableDefinition propertyDefinition =
                     (IVariableDefinition)((IMXMLPropertySpecifierNode)parent).getDefinition();
+            // propertyDefinition will be null in the case of a property of an <Object>
tag
             FlexProject project = builder.getProject();
-            arrayElementType = propertyDefinition.getArrayElementType(project);
+            arrayElementType = propertyDefinition != null ?
+            		           propertyDefinition.getArrayElementType(project) :
+            		           IASLanguageConstants.Object;
         }
 
         super.initializeFromTag(builder, tag);



Mime
View raw message