junichi11 edited a comment on pull request #2616: URL: https://github.com/apache/netbeans/pull/2616#issuecomment-752340019
I've added unit tests for GotoDeclaration. Please feel free to use them if needed :) Only a few simple cases. <details> <summary>unit test patch</summary> ```patch diff --git a/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/nbproject/project.properties b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/nbproject/project.properties new file mode 100644 index 0000000000..765047da38 --- /dev/null +++ b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/nbproject/project.properties @@ -0,0 +1,24 @@ +# 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. + +config.folder=${file.reference.HTML5Application-config} +file.reference.HTML5Application-config=config +file.reference.HTML5Application-public_html=public_html +file.reference.HTML5Application-test=test +files.encoding=UTF-8 +site.root.folder=${file.reference.HTML5Application-public_html} +test.folder=${file.reference.HTML5Application-test} diff --git a/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/nbproject/project.xml b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/nbproject/project.xml new file mode 100644 index 0000000000..ea0901bce4 --- /dev/null +++ b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/nbproject/project.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.web.clientproject</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/clientside-project/1"> + <name>CSS Editor Test Project</name> + </data> + </configuration> +</project> diff --git a/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test.html b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test.html new file mode 100644 index 0000000000..4c5da0816f --- /dev/null +++ b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<!-- + + 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. + +--> +<html> + <head> + <meta charset="UTF-8"> + <title>GotoDeclaration Test</title> + <link rel="stylesheet" type="text/css" href="test1.css"> + <link rel="stylesheet" type="text/css" href="test2.css"> + </head> + <body> + <p class="classSelector1">test class</p> + <p class="classSelector3">test class</p> + <p id="yetAnotherId">test id</p> + </body> +</html> diff --git a/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test1.css b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test1.css new file mode 100644 index 0000000000..e38a5f14f8 --- /dev/null +++ b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test1.css @@ -0,0 +1,34 @@ +/* + 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. +*/ + +.classSelector1 { + +} + +.classSelector2 { + +} + +#dummyId { + +} + +#anotherId { + +} \ No newline at end of file diff --git a/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test2.css b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test2.css new file mode 100644 index 0000000000..6071c4ce60 --- /dev/null +++ b/ide/css.editor/test/unit/data/testfiles/gotodeclaration/simple/public_html/test2.css @@ -0,0 +1,42 @@ +/* + 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. +*/ + +.classSelector3 { + +} + +#dummyId2 { + +} + +#dummyId3 { + color: #F1F1F1; +} + +.anotherClassSelector { + +} + +h1 { + +} + +#yetAnotherId { + +} \ No newline at end of file diff --git a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/csl/CssGotoDeclarationTest.java b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/csl/CssGotoDeclarationTest.java new file mode 100644 index 0000000000..70c695a8df --- /dev/null +++ b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/csl/CssGotoDeclarationTest.java @@ -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. + */ +package org.netbeans.modules.css.editor.csl; + +import org.netbeans.modules.csl.spi.DefaultLanguageConfig; +import org.netbeans.modules.html.editor.gsf.HtmlLanguage; + +public class CssGotoDeclarationTest extends CssGotoDeclarationTestBase { + + public CssGotoDeclarationTest(String testName) { + super(testName, "simple"); + } + + @Override + protected DefaultLanguageConfig getPreferredLanguage() { + return new HtmlLanguage(); + } + + public void testClass_01() throws Exception { + checkDeclaration(getSourcesFolderName() + "/test.html", "<p class=\"classSelec^tor1\">test class</p>", ".^classSelector1 {"); + } + + public void testClass_02() throws Exception { + checkDeclaration(getSourcesFolderName() + "/test.html", "<p class=\"classSelec^tor3\">test class</p>", ".^classSelector3 {"); + } + + public void testId_01() throws Exception { + checkDeclaration(getSourcesFolderName() + "/test.html", "<p id=\"yetAnoth^erId\">test id</p>", "#^yetAnotherId {"); + } +} diff --git a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/csl/CssGotoDeclarationTestBase.java b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/csl/CssGotoDeclarationTestBase.java new file mode 100644 index 0000000000..f2f631846d --- /dev/null +++ b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/csl/CssGotoDeclarationTestBase.java @@ -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. + */ +package org.netbeans.modules.css.editor.csl; + +import java.util.Collections; +import java.util.Map; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.modules.css.editor.ProjectTestBase; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.filesystems.FileObject; + +public class CssGotoDeclarationTestBase extends ProjectTestBase { + + protected static final String BASE_TEST_FOLDER_PATH = "testfiles/gotodeclaration/"; + + public CssGotoDeclarationTestBase(String testName, String projectName) { + super(testName, BASE_TEST_FOLDER_PATH + projectName); + } + + @Override + protected Map<String, ClassPath> createClassPathsForTest() { + FileObject[] srcFolders = createSourceClassPathsForTest(); + return srcFolders != null ? Collections.singletonMap( + ClassPath.SOURCE, + ClassPathSupport.createClassPath(srcFolders) + ) : null; + } + + protected FileObject[] createSourceClassPathsForTest() { + return new FileObject[]{getTestFile(getSourcesFolderName())}; + } + +} ``` </details> ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
