Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 21839200C82 for ; Sat, 22 Apr 2017 08:08:19 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 20736160B97; Sat, 22 Apr 2017 06:08:19 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1276E160BB5 for ; Sat, 22 Apr 2017 08:08:17 +0200 (CEST) Received: (qmail 84950 invoked by uid 500); 22 Apr 2017 06:08:17 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 84841 invoked by uid 99); 22 Apr 2017 06:08:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Apr 2017 06:08:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EAF08F49F5; Sat, 22 Apr 2017 06:08:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: paulk@apache.org To: commits@groovy.apache.org Date: Sat, 22 Apr 2017 06:08:17 -0000 Message-Id: In-Reply-To: <646eeffeeb46411a91cdb055bb8bcf5f@git.apache.org> References: <646eeffeeb46411a91cdb055bb8bcf5f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/6] groovy git commit: GROOVY-8117: Add test. archived-at: Sat, 22 Apr 2017 06:08:19 -0000 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 Authored: Sun Mar 12 03:47:51 2017 +0200 Committer: paulk 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( + "
All Implemented Interfaces and Traits:
\\s*" + + "
(Foo|FooImpl)
" + ).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()*\\((Foo|FooImpl) 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 srcList = new ArrayList(); 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 { +}