001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.ruby.hints;
043:
044: import org.netbeans.modules.ruby.hints.HintTestBase;
045:
046: /**
047: * @author Tor Norbye
048: */
049: public class ConvertBlockTypeTest extends HintTestBase {
050:
051: public ConvertBlockTypeTest(String testName) {
052: super (testName);
053: }
054:
055: public void testHint1() throws Exception {
056: findHints(this , new ConvertBlockType(),
057: "testfiles/convertblocks.rb", null);
058: }
059:
060: public void testHint2() throws Exception {
061: findHints(this , new ConvertBlockType(),
062: "testfiles/convertblocks.rb", "x.each { ^|foo|");
063: }
064:
065: public void testHint3() throws Exception {
066: findHints(this , new ConvertBlockType(),
067: "testfiles/convertblocks.rb", "x.each do ^|foo|");
068: }
069:
070: public void testHint4() throws Exception {
071: findHints(this , new ConvertBlockType(),
072: "testfiles/convertblocks.rb", "for i in 1..^10");
073: }
074:
075: public void testHint5() throws Exception {
076: findHints(this , new ConvertBlockType(),
077: "testfiles/convertblocks.rb", "pu^ts foo1");
078: }
079:
080: public void testHint7() throws Exception {
081: findHints(this , new ConvertBlockType(),
082: "testfiles/convertblocks4.rb",
083: "@scanner.set_prompt d^o");
084: }
085:
086: public void testHint8() throws Exception {
087: findHints(this , new ConvertBlockType(),
088: "testfiles/convertblocks4.rb",
089: "@context1.instance_eval d^o");
090: }
091:
092: public void testHint9() throws Exception {
093: findHints(this , new ConvertBlockType(),
094: "testfiles/convertblocks4.rb",
095: "@context4.instance_eval d^o");
096: }
097:
098: public void testHint10() throws Exception {
099: findHints(this , new ConvertBlockType(),
100: "testfiles/convertblocks4.rb",
101: "@context2.instance_eval {^");
102: }
103:
104: public void testHint11() throws Exception {
105: findHints(this , new ConvertBlockType(),
106: "testfiles/convertblocks4.rb",
107: "@context3.instance_eval {^");
108: }
109:
110: public void testFix1() throws Exception {
111: applyHint(this , new ConvertBlockType(),
112: "testfiles/convertblocks.rb", "x.each {^ |foo|",
113: "Convert {}-block to a do/end-block\n");
114: }
115:
116: public void testFix2() throws Exception {
117: applyHint(this , new ConvertBlockType(),
118: "testfiles/convertblocks.rb", "x.each do^ |foo|",
119: "Convert do/end-block to a {}-block\n");
120: }
121:
122: public void testHint6() throws Exception {
123: findHints(this , new ConvertBlockType(),
124: "testfiles/convertblocks2.rb", "x.each {^ |foo| ");
125: }
126:
127: public void testFix3() throws Exception {
128: applyHint(this , new ConvertBlockType(),
129: "testfiles/convertblocks2.rb", "x.each {^ |foo| ",
130: "Convert {}-block to a do/end-block\n");
131: }
132:
133: public void testFix4() throws Exception {
134: applyHint(this , new ConvertBlockType(),
135: "testfiles/convertblocks.rb", "x.each do^ |foo|",
136: "Convert do/end-block to a {}-block, and collapse to a single line");
137: }
138:
139: public void testOneLineHint1() throws Exception {
140: findHints(this , new ConvertBlockType(),
141: "testfiles/convertblocks3.rb", null);
142: }
143:
144: public void testOneLineHint2() throws Exception {
145: findHints(this , new ConvertBlockType(),
146: "testfiles/convertblocks3.rb",
147: "self.gsub!(pattern) do^ |c| h[c] end");
148: }
149:
150: public void testOneLineHint3() throws Exception {
151: findHints(this , new ConvertBlockType(),
152: "testfiles/convertblocks3.rb",
153: "self.gsub!(pattern) {^ |c| h[c] }");
154: }
155:
156: public void testOneLineHint4() throws Exception {
157: findHints(this , new ConvertBlockType(),
158: "testfiles/convertblocks3.rb",
159: "sort{^|a1, a2| a1[0].id2name <=> a2[0].id2name}");
160: }
161:
162: public void testOneLineHint5() throws Exception {
163: findHints(this , new ConvertBlockType(),
164: "testfiles/convertblocks3.rb",
165: "sort do^|a1, a2| a1[0].id2name <=> a2[0].id2name end");
166: }
167:
168: public void testOneLineHintFix2() throws Exception {
169: applyHint(this , new ConvertBlockType(),
170: "testfiles/convertblocks3.rb",
171: "self.gsub!(pattern) do^ |c| h[c] end",
172: "Convert do/end-block to");
173: }
174:
175: public void testOneLineHintFix3() throws Exception {
176: applyHint(this , new ConvertBlockType(),
177: "testfiles/convertblocks3.rb",
178: "self.gsub!(pattern) {^ |c| h[c] }",
179: "Convert {}-block to a do/end-block, and expand to multiple lines");
180: }
181:
182: public void testOneLineHintFix4() throws Exception {
183: applyHint(this , new ConvertBlockType(),
184: "testfiles/convertblocks3.rb",
185: "sort{^|a1, a2| a1[0].id2name <=> a2[0].id2name}",
186: "Convert {}-block to a do/end-block, and expand to multiple lines");
187: }
188:
189: public void testOneLineHintFix5() throws Exception {
190: applyHint(this , new ConvertBlockType(),
191: "testfiles/convertblocks3.rb",
192: "sort do^|a1, a2| a1[0].id2name <=> a2[0].id2name end",
193: "Convert do/end-block to");
194: }
195:
196: public void testHintFix1() throws Exception {
197: applyHint(this , new ConvertBlockType(),
198: "testfiles/convertblocks4.rb",
199: "@context1.instance_eval d^o",
200: "Convert do/end-block to a {}-block, and collapse to a single line");
201: }
202:
203: public void testHintFix2() throws Exception {
204: applyHint(this , new ConvertBlockType(),
205: "testfiles/convertblocks4.rb",
206: "@context1.instance_eval d^o",
207: "Convert do/end-block to a {}-block\n");
208: }
209:
210: public void testHintFix3() throws Exception {
211: applyHint(this , new ConvertBlockType(),
212: "testfiles/convertblocks4.rb",
213: "@context1.instance_eval d^o",
214: "Collapse multi-line block to a single line");
215: }
216:
217: public void testHintFix4() throws Exception {
218: applyHint(this , new ConvertBlockType(),
219: "testfiles/convertblocks4.rb",
220: "@context4.instance_eval d^o",
221: "Convert do/end-block to a {}-block\n");
222: }
223:
224: public void testHintFix5() throws Exception {
225: applyHint(this , new ConvertBlockType(),
226: "testfiles/convertblocks4.rb",
227: "@context4.instance_eval d^o",
228: "Expand single-line block to multiple lines");
229: }
230:
231: public void testHintFix6() throws Exception {
232: applyHint(this , new ConvertBlockType(),
233: "testfiles/convertblocks4.rb",
234: "@context2.instance_eval {^",
235: "Convert {}-block to a do/end-block\n");
236: }
237:
238: public void testHintFix7() throws Exception {
239: applyHint(this , new ConvertBlockType(),
240: "testfiles/convertblocks4.rb",
241: "@context2.instance_eval {^",
242: "Collapse multi-line block to a single line");
243: }
244:
245: public void testHintFix8() throws Exception {
246: applyHint(this , new ConvertBlockType(),
247: "testfiles/convertblocks4.rb",
248: "@context3.instance_eval {^",
249: "Convert {}-block to a do/end-block, and expand to multiple lines");
250: }
251:
252: public void testHintFix9() throws Exception {
253: applyHint(this , new ConvertBlockType(),
254: "testfiles/convertblocks4.rb",
255: "@context3.instance_eval {^",
256: "Convert {}-block to a do/end-block\n");
257: }
258:
259: public void testHintFix10() throws Exception {
260: applyHint(this , new ConvertBlockType(),
261: "testfiles/convertblocks4.rb",
262: "@context3.instance_eval {^",
263: "Expand single-line block to multiple lines");
264: }
265:
266: public void testHintFix11() throws Exception {
267: applyHint(this , new ConvertBlockType(),
268: "testfiles/convertblocks5.rb",
269: "[\"a\",\"b\",\"c\"].each do^ |word|",
270: "Convert do/end-block to a {}-block, and collapse to a single line");
271: }
272:
273: public void testHintFix12() throws Exception {
274: applyHint(
275: this ,
276: new ConvertBlockType(),
277: "testfiles/convertblocks5.rb",
278: "[1,2,4].each {^ |number| double = 2*number; tripple = 3*number; puts double,tripple }",
279: "Convert {}-block to a do/end-block, and expand to multiple lines");
280: }
281:
282: public void testHintFix13() throws Exception {
283: applyHint(this , new ConvertBlockType(),
284: "testfiles/convertblocks6.rb", "foo do^",
285: "Convert do/end-block to a {}-block, and collapse to a single line");
286: }
287:
288: public void testHintFix14() throws Exception {
289: applyHint(this , new ConvertBlockType(),
290: "testfiles/convertblocks6.rb", "foo do^",
291: "Collapse multi-line block to a single line");
292: }
293:
294: public void testHintFix15() throws Exception {
295: applyHint(this , new ConvertBlockType(),
296: "testfiles/convertblocks7.rb",
297: "b.create_menu :name => 'default_menu' do ^|d|",
298: //"b.create_menu :name => 'default_menu' do |d|^",
299: "Convert do/end-block to a {}-block\n");
300: }
301:
302: public void testHintFix16() throws Exception {
303: applyHint(this , new ConvertBlockType(),
304: "testfiles/convertblocks8.rb",
305: "args.each {^ |a| puts \"#{a}\\n\" }",
306: "Convert {}-block to a do/end-block, and expand to multiple lines");
307: }
308:
309: public void testHintFix17() throws Exception {
310: applyHint(
311: this ,
312: new ConvertBlockType(),
313: "testfiles/convertblocks8.rb",
314: "ss = vv.collect{^|kkk, vvv| \":#{kkk.id2name}=>#{vvv.inspect}\"}",
315: "Convert {}-block to a do/end-block, and expand to multiple lines");
316: }
317:
318: public void testHintFix18() throws Exception {
319: applyHint(this , new ConvertBlockType(),
320: "testfiles/convertblocks9.rb",
321: "create_table :posts d^o |t|",
322: "Convert do/end-block to a {}-block, and collapse to a single line");
323: }
324:
325: public void testHintFix19() throws Exception {
326: applyHint(this , new ConvertBlockType(),
327: "testfiles/convertblocks10.rb",
328: "{^|x| sleep 0.5; yield x}",
329: "Expand single-line block to multiple lines");
330: }
331:
332: public void testHintFix20() throws Exception {
333: applyHint(this , new ConvertBlockType(),
334: "testfiles/convertblocks5.rb", "en^d",
335: "Convert do/end-block to a {}-block, and collapse to a single line");
336: }
337:
338: public void testHintFix21() throws Exception {
339: applyHint(this , new ConvertBlockType(),
340: "testfiles/convertblocks6.rb", "en^d",
341: "Convert do/end-block to a {}-block, and collapse to a single line");
342: }
343:
344: public void testHintFix22() throws Exception {
345: applyHint(this , new ConvertBlockType(),
346: "testfiles/convertblocks.rb", "^}",
347: "Convert {}-block to a do/end-block\n");
348: }
349:
350: public void testHintFix23() throws Exception {
351: applyHint(this , new ConvertBlockType(),
352: "testfiles/convertblocks11.rb", "x.each do^ |foo|",
353: "Convert do/end-block to a {}-block, and collapse to a single line");
354: }
355: }
|