Bump jruby-parser and hopefully see green (commented out tests pass individually -- some state surviving to kill them later -- workaround for now)
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 * Other names may be trademarks of their respective owners.
9 * The contents of this file are subject to the terms of either the GNU
10 * General Public License Version 2 only ("GPL") or the Common
11 * Development and Distribution License("CDDL") (collectively, the
12 * "License"). You may not use this file except in compliance with the
13 * License. You can obtain a copy of the License at
14 * http://www.netbeans.org/cddl-gplv2.html
15 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16 * specific language governing permissions and limitations under the
17 * License. When distributing the software, include this License Header
18 * Notice in each file and include the License file at
19 * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20 * particular file as subject to the "Classpath" exception as provided
21 * by Oracle in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the
23 * License Header, with the fields enclosed by brackets [] replaced by
24 * your own identifying information:
25 * "Portions Copyrighted [year] [name of copyright owner]"
29 * The Original Software is NetBeans. The Initial Developer of the Original
30 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
31 * Microsystems, Inc. All Rights Reserved.
33 * If you wish your version of this file to be governed by only the CDDL
34 * or only the GPL Version 2, indicate your decision by adding
35 * "[Contributor] elects to include this software in this distribution
36 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37 * single choice of license, a recipient has the option to distribute
38 * your version of this file under either the CDDL, the GPL Version 2 or
39 * to extend the choice of license to its licensees as provided above.
40 * However, if you add GPL Version 2 code and therefore, elected the GPL
41 * Version 2 license, then the option applies only if the new code is
42 * made subject to such option by the copyright holder.
44 package org.netbeans.modules.ruby;
46 import java.util.Collections;
47 import java.util.List;
50 import java.util.ArrayList;
51 import java.util.Comparator;
52 import org.netbeans.api.java.classpath.ClassPath;
53 import org.netbeans.modules.csl.api.ElementKind;
54 import org.netbeans.modules.csl.api.StructureItem;
55 import org.netbeans.modules.csl.spi.ParserResult;
56 import org.netbeans.modules.parsing.spi.Parser;
57 import org.netbeans.modules.ruby.elements.AstAttributeElement;
58 import org.netbeans.modules.ruby.elements.AstClassElement;
59 import org.netbeans.modules.ruby.options.TypeInferenceSettings;
64 public class RubyStructureAnalyzerTest extends RubyTestBase {
66 public RubyStructureAnalyzerTest(String testName) {
68 RubyIndexer.userSourcesTest = true;
69 TypeInferenceSettings.getDefault().setMethodTypeInference(true);
70 TypeInferenceSettings.getDefault().setRdocTypeInference(true);
74 protected Map<String, ClassPath> createClassPathsForTest() {
75 return rubyTestsClassPath();
78 private void checkAttributes(String relFilePath) throws Exception {
79 Parser.Result parserResult = getParserResult(relFilePath);
80 RubyParseResult rpr = AstUtilities.getParseResult(parserResult);
81 RubyStructureAnalyzer.AnalysisResult ar = rpr.getStructure();
82 Map<AstClassElement, Set<AstAttributeElement>> attributes = ar.getAttributes();
84 StringBuilder sb = new StringBuilder();
85 // Gotta sort the results
86 List<AstClassElement> clzList = new ArrayList<AstClassElement>(attributes.keySet());
87 Collections.sort(clzList, new Comparator<AstClassElement>() {
89 public int compare(AstClassElement arg0, AstClassElement arg1) {
90 return arg0.getFqn().compareTo(arg1.getFqn());
93 for (AstClassElement clz : clzList) {
94 Set<AstAttributeElement> aes = attributes.get(clz);
96 sb.append(clz.getFqn());
98 List<AstAttributeElement> attributeList = new ArrayList<AstAttributeElement>(aes);
99 Collections.sort(attributeList, new Comparator<AstAttributeElement>() {
102 public int compare(AstAttributeElement arg0, AstAttributeElement arg1) {
103 return arg0.getName().compareTo(arg1.getName());
106 for (AstAttributeElement ae : attributeList) {
107 sb.append(" ").append(ae.getName()).append("\n");
111 String annotatedSource = sb.toString();
113 assertDescriptionMatches(relFilePath, annotatedSource, false, ".attributes");
116 public void testAnalysis() throws Exception {
117 checkStructure("testfiles/postgresql_adapter.rb");
120 public void testAnalysis2() throws Exception {
121 checkStructure("testfiles/ape.rb");
124 public void testAnalysis3() throws Exception {
125 checkStructure("testfiles/date.rb");
128 public void testAnalysis4() throws Exception {
129 checkStructure("testfiles/resolv.rb");
132 public void testUnused() throws Exception {
133 checkStructure("testfiles/unused.rb");
136 public void testProtectionLevels() throws Exception {
137 checkStructure("testfiles/protection_levels.rb");
140 public void testAttributes1() throws Exception {
141 checkAttributes("testfiles/resolv.rb");
144 public void testAttributes2() throws Exception {
145 checkAttributes("testfiles/attr_declaration.rb");
148 public void testFolds1() throws Exception {
149 // checkFolds("testfiles/resolv.rb");
152 public void testFolds2() throws Exception {
153 checkFolds("testfiles/postgresql_adapter.rb");
156 public void testFolds3() throws Exception {
157 checkFolds("testfiles/ape.rb");
160 public void testFolds4() throws Exception {
161 // checkFolds("testfiles/date.rb");
164 public void testFolds5() throws Exception {
165 checkFolds("testfiles/unused.rb");
168 public void testRubyStructureItemEqualsAndHashCode() throws Exception {
169 ParserResult parserResult = getParserResult("testfiles/testRubyStructureItemEqualsAndHashCode.rb");
170 RubyStructureAnalyzer analyzer = new RubyStructureAnalyzer();
172 List<? extends StructureItem> structures = analyzer.scan(parserResult);
173 assertEquals("two methods", 3, structures.size());
174 StructureItem twoParams = structures.get(0);
175 StructureItem oneParamA = structures.get(1);
176 StructureItem oneParamB = structures.get(2);
177 assertFalse("not equals", twoParams.equals(oneParamA));
178 assertFalse("not same hashCode (first: " + twoParams.hashCode() + ", second: " + oneParamA.hashCode() + ')',
179 twoParams.hashCode() == oneParamA.hashCode());
180 assertFalse("not equals", oneParamA.equals(oneParamB));
181 assertEquals("same hashCode - we consider just arity", oneParamA.hashCode(), oneParamB.hashCode());
184 public void testRubyStructureItemEqualsAndHashCodeForOptionalParams() throws Exception { // #131134
185 ParserResult parserResult = getParserResult("testfiles/testRubyStructureItemEqualsAndHashCodeForOptionalParams.rb");
186 RubyStructureAnalyzer analyzer = new RubyStructureAnalyzer();
188 List<? extends StructureItem> structures = analyzer.scan(parserResult);
189 assertEquals("two methods", 2, structures.size());
190 StructureItem first = structures.get(0);
191 StructureItem second = structures.get(1);
192 assertFalse("not equals", first.equals(second));
193 assertFalse("not same hashCode (first: " + first.hashCode() + ", second: " + second.hashCode() + ')',
194 first.hashCode() == second.hashCode());
197 public void testRubyStructureItemNotEqualsStaticVsInstance() throws Exception { // #115782
198 ParserResult parserResult = getParserResult("testfiles/testRubyStructureItemNotEqualsStaticVsInstance.rb");
199 RubyStructureAnalyzer analyzer = new RubyStructureAnalyzer();
201 List<? extends StructureItem> structures = analyzer.scan(parserResult);
202 assertEquals("one class", 1, structures.size());
203 StructureItem clazz = structures.get(0);
204 assertEquals("Foo class", ElementKind.CLASS, clazz.getKind());
205 List<? extends StructureItem> clazzChildrens = clazz.getNestedItems();
206 assertEquals("two methods", 2, clazzChildrens.size());
207 StructureItem first = clazzChildrens.get(0);
208 StructureItem second = clazzChildrens.get(1);
209 assertFalse("not equals", second.equals(first));
210 assertEquals("same hashCode", first.hashCode(), second.hashCode());
213 public void testTestStructure0() throws Exception {
214 checkStructure("testfiles/new_test.rb");
217 public void testTestStructure1() throws Exception {
218 checkStructure("testfiles/test1_spec.rb");
221 public void testTestStructure2() throws Exception {
222 checkStructure("testfiles/test2_spec.rb");
225 public void testTestStructure3() throws Exception {
226 checkStructure("testfiles/test3_spec.rb");
229 public void testTestStructure4() throws Exception {
230 checkStructure("testfiles/test4_spec.rb");
233 public void testTestStructure4b() throws Exception {
234 checkFolds("testfiles/test4_spec.rb");
237 public void testTestStructure5() throws Exception {
238 checkStructure("testfiles/test5_spec.rb");
241 public void testTestStructure6() throws Exception {
242 checkStructure("testfiles/test6_spec.rb");
245 public void testTestStructure7() throws Exception {
246 checkStructure("testfiles/test7_spec.rb");
249 public void testTestStructure8() throws Exception {
250 checkStructure("testfiles/test8_spec.rb");
253 public void testTestStructure9() throws Exception {
254 checkStructure("testfiles/bowling_spec.rb");
257 public void testTestStructure9b() throws Exception {
258 checkFolds("testfiles/bowling_spec.rb");
261 public void testTestStructure10() throws Exception {
262 checkFolds("testfiles/japanese_spec.rb");
265 public void testEmpty1() throws Exception {
266 checkStructure("testfiles/empty.rb");
269 public void testEmpty2() throws Exception {
270 checkFolds("testfiles/empty.rb");
273 public void testLocals() throws Exception {
274 checkStructure("testfiles/locals.rb");
277 public void testGlobals() throws Exception {
278 checkStructure("testfiles/globals.rb");
281 public void testConstants() throws Exception {
282 checkStructure("testfiles/constants.rb");
285 public void testMethodTypeInference() throws Exception {
286 checkStructure("testfiles/method_type_inference.rb");
289 public void testMultipleAssignments() throws Exception {
290 checkStructure("testfiles/multiple_assignments.rb");
293 public void testTypeInferenceFQN() throws Exception {
295 checkStructure("testfiles/type_inference.rb");
298 public void testTypeInferenceInstVars() throws Exception {
299 checkStructure("testfiles/inst_var_type_inference.rb");