You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/04/22 06:08:17 UTC

[2/6] groovy git commit: GROOVY-8117: Add test.

GROOVY-8117: Add test.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/092beef0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/092beef0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/092beef0

Branch: refs/heads/GROOVY_2_6_X
Commit: 092beef0d4bb6e2169d0dd8d368d9df71acd3347
Parents: 891211b
Author: Mikko V�rri <vm...@linuxbox.fi>
Authored: Sun Mar 12 03:47:51 2017 +0200
Committer: paulk <pa...@asert.com.au>
Committed: Sat Apr 22 16:07:38 2017 +1000

----------------------------------------------------------------------
 .../tools/groovydoc/GroovyDocToolTest.java      | 40 ++++++++++++++++++--
 .../groovydoc/testfiles/alias/FooAdapter.groovy | 32 ++++++++++++++++
 .../groovydoc/testfiles/alias/api/Foo.java      | 26 +++++++++++++
 .../groovydoc/testfiles/alias/lib/Foo.java      | 26 +++++++++++++
 4 files changed, 121 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
index 6b68ef4..7e31ca1 100644
--- a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/GroovyDocToolTest.java
@@ -21,9 +21,7 @@ package org.codehaus.groovy.tools.groovydoc;
 import groovy.util.GroovyTestCase;
 
 import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -658,6 +656,42 @@ public class GroovyDocToolTest extends GroovyTestCase {
         assertEquals("There has to be a reference to class ArrayList", "ArrayList", m.group(2));
     }
 
+    public void testImplementedInterfaceWithAlias() throws Exception {
+        // FooAdapter imports both api.Foo and lib.Foo, using "lib.Foo as FooImpl" to disambiguate.
+        // lib.Foo is imported later that api.Foo, so groovydoc tries to resolve to lib.Foo first.
+        htmlTool.add(Arrays.asList(
+                "org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java",
+                "org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy"
+        ));
+
+        final MockOutputTool output = new MockOutputTool();
+        htmlTool.renderToOutput(output, MOCK_DIR);
+        final String fooAdapterDoc = output.getText(MOCK_DIR + "/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.html");
+
+        // "Interfaces and Traits" section should show "Foo" as one of the implemented interfaces,
+        // and that should link to api/Foo.html, not to lib/Foo.html.
+        final Matcher interfacesAndTraits = Pattern.compile(
+                "<dt>All Implemented Interfaces and Traits:</dt>\\s*" +
+                "<dd><a href='[./]*/org/codehaus/groovy/tools/groovydoc/testfiles/alias/(api|lib)/Foo\\.html'>(Foo|FooImpl)</a></dd>"
+        ).matcher(fooAdapterDoc);
+
+        // Constructor is actually "FooAdapter(FooImpl foo)",
+        // but it should show "Foo" as the link text, not "FooImpl".
+        // The Foo parameter type should link to lib/Foo.html, not api/Foo.html.
+        final Matcher constructor = Pattern.compile(
+                "FooAdapter(</[a-z]+>)*\\(<a href='[./]*/org/codehaus/groovy/tools/groovydoc/testfiles/alias/(api|lib)/Foo.html'>(Foo|FooImpl)</a> foo\\)"
+        ).matcher(fooAdapterDoc);
+
+        assertTrue("Interfaces and Traits pattern should match for this test to make sense", interfacesAndTraits.find());
+        assertTrue("Constructor pattern should match for this test to make sense", constructor.find());
+
+        assertEquals("The implemented interface should link to api.Foo", "api", interfacesAndTraits.group(1));
+        assertEquals("The implemented interface link text should be Foo", "Foo", interfacesAndTraits.group(2));
+        assertEquals("The constructor parameter should link to lib.Foo", "lib", constructor.group(2));
+        assertEquals("The constructor parameter link text should be Foo", "Foo", constructor.group(3));
+    }
+
     public void testScript() throws Exception {
         List<String> srcList = new ArrayList<String>();
         srcList.add("org/codehaus/groovy/tools/groovydoc/testfiles/Script.groovy");

http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy
new file mode 100644
index 0000000..70da911
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/FooAdapter.groovy
@@ -0,0 +1,32 @@
+/*
+ *  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.codehaus.groovy.tools.groovydoc.testfiles.alias
+
+import org.codehaus.groovy.tools.groovydoc.testfiles.alias.api.Foo
+import org.codehaus.groovy.tools.groovydoc.testfiles.alias.lib.Foo as FooImpl
+
+/**
+ * An adapter class that makes an instance of
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.lib.Foo library Foo}
+ * appear to be an instance of
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.api.Foo API Foo}.
+ */
+class FooAdapter implements Foo {
+    FooAdapter(FooImpl foo) {}
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java
new file mode 100644
index 0000000..97d0bd3
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/api/Foo.java
@@ -0,0 +1,26 @@
+/*
+ *  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.codehaus.groovy.tools.groovydoc.testfiles.alias.api;
+
+/**
+ * A Foo type defined by some API, unrelated to the
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.lib.Foo library Foo}.
+ */
+public interface Foo {
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/092beef0/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java
new file mode 100644
index 0000000..05e2184
--- /dev/null
+++ b/subprojects/groovy-groovydoc/src/test/groovy/org/codehaus/groovy/tools/groovydoc/testfiles/alias/lib/Foo.java
@@ -0,0 +1,26 @@
+/*
+ *  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.codehaus.groovy.tools.groovydoc.testfiles.alias.lib;
+
+/**
+ * A Foo type defined by some library, unrelated to the
+ * {@link org.codehaus.groovy.tools.groovydoc.testfiles.alias.api.Foo API Foo}.
+ */
+public class Foo {
+}