You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ft...@apache.org on 2015/07/07 20:14:27 UTC

[3/5] git commit: [flex-falcon] [refs/heads/add-CollectImportPass] - Add tests for the collect of the imports

Add tests for the collect of the imports


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/8809fad4
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/8809fad4
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/8809fad4

Branch: refs/heads/add-CollectImportPass
Commit: 8809fad46d7f3554a1bd1e0bb9ae434dde5bd565
Parents: e5cf1fe
Author: Frédéric THOMAS <we...@gmail.com>
Authored: Tue Jul 7 19:05:00 2015 +0100
Committer: Frédéric THOMAS <we...@gmail.com>
Committed: Tue Jul 7 19:05:00 2015 +0100

----------------------------------------------------------------------
 .../codegen/externals/TestCollectImports.java   | 221 +++++++++++++++++++
 .../imports/import_constructor_signatures.js    |  43 ++++
 .../imports/import_functions.js                 |  47 ++++
 .../imports/import_interfaces.js                |  49 ++++
 .../imports/import_method_signatures.js         |  71 ++++++
 .../imports/import_superclasses.js              |  46 ++++
 6 files changed, 477 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8809fad4/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
new file mode 100644
index 0000000..ad025c3
--- /dev/null
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestCollectImports.java
@@ -0,0 +1,221 @@
+/*
+ *
+ *  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.codegen.externals;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
+import org.apache.flex.compiler.internal.codegen.externals.reference.FunctionReference;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestCollectImports extends ExternalsTestBase
+{
+    private static final String IMPORTS_TEST_DIR = "imports/";
+
+    private Boolean excludeClass;
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> excludeClassYesNo()
+    {
+        return Arrays.asList(new Object[][] { { true }, { false } });
+    }
+
+    public TestCollectImports(final Boolean excludeClass)
+    {
+        this.excludeClass = excludeClass;
+    }
+
+    @Test
+    public void import_constructor_signatures() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("foo.Baz");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importConstructorSignature = model.getClassReference("ImportConstructorSignature");
+        assertNotNull(importConstructorSignature);
+
+        assertFalse(importConstructorSignature.hasImport("Number"));
+        assertFalse(importConstructorSignature.hasImport("foo.Qux"));
+
+        assertTrue(importConstructorSignature.hasImport("foo.Bar"));
+
+        if (excludeClass)
+        {
+            assertFalse(importConstructorSignature.hasImport("foo.Baz"));
+        }
+        else
+        {
+            assertTrue(importConstructorSignature.hasImport("foo.Baz"));
+        }
+    }
+
+    @Test
+    public void import_method_signatures() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("foo.Qux");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importMethodSignature = model.getClassReference("ImportMethodSignature");
+        assertNotNull(importMethodSignature);
+
+        assertFalse(importMethodSignature.hasImport("Number"));
+        assertFalse(importMethodSignature.hasImport("foo.Quux"));
+        assertFalse(importMethodSignature.hasImport("foo.Quuux"));
+
+        assertTrue(importMethodSignature.hasImport("foo.Bar"));
+        assertTrue(importMethodSignature.hasImport("foo.Baz"));
+
+        if (excludeClass)
+        {
+            assertFalse(importMethodSignature.hasImport("foo.Qux"));
+        }
+        else
+        {
+            assertTrue(importMethodSignature.hasImport("foo.Qux"));
+        }
+    }
+
+    @Test
+    public void import_interfaces() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("API.foo.Baz");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importInterfaces = model.getClassReference("ImportInterfaces");
+        assertNotNull(importInterfaces);
+
+        assertFalse(importInterfaces.hasImport("qux"));
+        assertTrue(importInterfaces.hasImport("API.Foo"));
+
+        ClassReference apiFoo = model.getClassReference("API.Foo");
+        assertNotNull(apiFoo);
+
+        assertFalse(apiFoo.hasImport("qux"));
+        assertFalse(apiFoo.hasImport("API.Bar"));
+
+        if (excludeClass)
+        {
+            assertFalse(apiFoo.hasImport("API.foo.Baz"));
+        }
+        else
+        {
+            assertTrue(apiFoo.hasImport("API.foo.Baz"));
+        }
+    }
+
+    @Test
+    public void import_superclasses() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("BASE.Foo");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        //client.emit();
+
+        ClassReference importSuperClass1 = model.getClassReference("ImportSuperClass1");
+        assertNotNull(importSuperClass1);
+
+        assertFalse(importSuperClass1.hasImport("qux"));
+
+        ClassReference importSuperClass2 = model.getClassReference("ImportSuperClass2");
+        assertNotNull(importSuperClass2);
+
+        if (excludeClass)
+        {
+            assertFalse(importSuperClass2.hasImport("BASE.Foo"));
+        }
+        else
+        {
+            assertTrue(importSuperClass2.hasImport("BASE.Foo"));
+        }
+
+        ClassReference foo = model.getClassReference("BASE.Foo");
+        assertNotNull(foo);
+
+        assertFalse(foo.hasImport("BASE.Bar"));
+    }
+
+    @Test
+    public void import_functions() throws Exception
+    {
+        if (excludeClass)
+        {
+            config.addClassExclude("foo.Qux");
+        }
+
+        assertCompileTestFileSuccess(IMPORTS_TEST_DIR);
+
+        client.emit();
+
+        FunctionReference importFunction = (FunctionReference) model.getFunctions().toArray()[0];
+        assertNotNull(importFunction);
+        assertTrue(importFunction.getQualifiedName().equals("ImportFunction"));
+
+        assertFalse(importFunction.hasImport("Quux"));
+
+        assertTrue(importFunction.hasImport("foo.Bar"));
+        assertTrue(importFunction.hasImport("foo.Baz"));
+
+        if (excludeClass)
+        {
+            assertFalse(importFunction.hasImport("foo.Qux"));
+        }
+        else
+        {
+            assertTrue(importFunction.hasImport("foo.Qux"));
+        }
+    }
+
+    @Override
+    protected void configure(ExternCConfiguration config) throws IOException
+    {
+        config.setASRoot(ExternalsTestUtils.AS_ROOT_DIR);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8809fad4/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js
new file mode 100644
index 0000000..9f80e7e
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_constructor_signatures.js
@@ -0,0 +1,43 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+
+/**
+ * @constructor
+ * @param {foo.Qux|foo.Bar} qux
+ * @param {foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ */
+ImportConstructorSignature = function(qux, bar, value, baz) {};
+
+/**
+ * @constructor
+ */
+foo.Bar = function() {};
+
+/**
+ * @constructor
+ */
+foo.Baz = function() {};
+
+/**
+ * @constructor
+ */
+foo.Qux = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8809fad4/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js
new file mode 100644
index 0000000..b6c170b
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_functions.js
@@ -0,0 +1,47 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+
+/**
+ * @param {foo.Bar} bar
+ * @param {foo.Baz} baz
+ * @param {Quux} quux
+ * @return {!foo.Qux}
+ */
+function ImportFunction(bar, baz, quux) {}
+
+/**
+ * @constructor
+ */
+Quux = function() {};
+
+/**
+ * @constructor
+ */
+foo.Bar = function() {};
+
+/**
+ * @constructor
+ */
+foo.Baz = function() {};
+
+/**
+ * @constructor
+ */
+foo.Qux = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8809fad4/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js
new file mode 100644
index 0000000..97a711f
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_interfaces.js
@@ -0,0 +1,49 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+/**
+ * @constructor
+ * @implements {Qux}
+ * @implements {API.Foo}
+ */
+ImportInterfaces = function() {};
+
+
+/**
+ * @interface
+ */
+Qux = function() {};
+
+/**
+ * @interface
+ * @extends {Qux}
+ * @extends {API.Bar}
+ * @extends {API.foo.Baz}
+ */
+API.Foo = function() {};
+
+/**
+ * @interface
+ */
+API.Bar = function() {};
+
+/**
+ * @interface
+ */
+API.foo.Baz = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8809fad4/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js
new file mode 100644
index 0000000..6524dc5
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_method_signatures.js
@@ -0,0 +1,71 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+/**
+ * @constructor
+ */
+ImportMethodSignature = function() {};
+
+/**
+ * @param {foo.Quux|foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ */
+ImportMethodSignature.myMethod = function(bar, value, baz) {};
+
+/**
+ * @param {foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ * @return {foo.Qux}
+ */
+ImportMethodSignature.prototype.myMethodWithReturnType = function(bar, value, baz) {};
+
+/**
+ * @param {foo.Bar} bar
+ * @param {number} value
+ * @param {foo.Baz?} baz
+ * @return {foo.Quuux|foo.Bar}
+ */
+ImportMethodSignature.myMethodWithUnionReturnType = function(bar, value, baz) {};
+
+/**
+ * @constructor
+ */
+foo.Bar = function() {};
+
+/**
+ * @constructor
+ */
+foo.Baz = function() {};
+
+/**
+ * @constructor
+ */
+foo.Qux = function() {};
+
+/**
+ * @constructor
+ */
+foo.Quux = function() {};
+
+/**
+ * @constructor
+ */
+foo.Quuux = function() {};

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8809fad4/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js
new file mode 100644
index 0000000..1a549d7
--- /dev/null
+++ b/compiler.jx.tests/test-files/externals_unit_tests/imports/import_superclasses.js
@@ -0,0 +1,46 @@
+/*
+ *
+ *  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.
+ *
+ */
+
+/**
+ * @constructor
+ * @extends {Qux}
+ */
+ImportSuperClass1 = function() {};
+
+/**
+ * @constructor
+ * @extends {BASE.Foo}
+ */
+ImportSuperClass2 = function() {};
+
+/**
+ * @constructor
+ */
+Qux = function() {};
+
+/**
+ * @constructor
+ * @extends {BASE.Bar}
+ */
+BASE.Foo = function() {};
+
+/**
+ * @constructor
+ */
+BASE.Bar = function() {};