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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.ruby.hints;
041:
042: import org.netbeans.modules.ruby.hints.HintTestBase;
043:
044: public class ConvertIfToUnlessTest extends HintTestBase {
045: public ConvertIfToUnlessTest(String testName) {
046: super (testName);
047: }
048:
049: public void testNoHint1() throws Exception {
050: findHints(this , new ConvertIfToUnless(),
051: "testfiles/reverseif.rb", null);
052: }
053:
054: public void testNoHint2() throws Exception {
055: findHints(this , new ConvertIfToUnless(),
056: "testfiles/conditionals2.rb",
057: "uri = env_pr^oxy ? URI.parse(env_proxy) : nil");
058: }
059:
060: public void testNoHint3() throws Exception {
061: findHints(this , new ConvertIfToUnless(),
062: "testfiles/conditionals2.rb",
063: "(uri =~ /.(https?|ftp|file):/) ? u^ri : \"http://#{uri}\"");
064: }
065:
066: public void testNoHint4() throws Exception {
067: findHints(this , new ConvertIfToUnless(),
068: "testfiles/conditionals2.rb",
069: "uri = env_pr^oxy ? URI.parse(env_proxy) : nil");
070: }
071:
072: public void testNoHint5() throws Exception {
073: findHints(this , new ConvertIfToUnless(),
074: "testfiles/conditionals2.rb",
075: "(uri =~ /.(https?|ftp|file):/) ? u^ri : \"http://#{uri}\"");
076: }
077:
078: public void testNoHint6() throws Exception {
079: findHints(this , new ConvertIfToUnless(),
080: "testfiles/emptycondition.rb", "if (^)");
081: }
082:
083: public void testNoHint7() throws Exception {
084: findHints(this , new ConvertIfToUnless(), "testfiles/elsif.rb",
085: "elsi^f !str.blank?");
086: }
087:
088: public void testNoHint8() throws Exception {
089: findHints(this , new ConvertIfToUnless(), "testfiles/elsif.rb",
090: "elsif !str.bla^nk?");
091: }
092:
093: public void testNoHint9() throws Exception {
094: findHints(this , new ConvertIfToUnless(), "testfiles/elsif.rb",
095: "if st^r != 'something'");
096: }
097:
098: // public void testNoHint10() throws Exception {
099: // findHints(this, new ConvertIfToUnless(), "testfiles/emptybody.rb",
100: // "if !^x");
101: // }
102: //
103: // public void testNoHint11() throws Exception {
104: // findHints(this, new ConvertIfToUnless(), "testfiles/emptybody.rb",
105: // "if !^y");
106: // }
107:
108: public void testHint2() throws Exception {
109: findHints(this , new ConvertIfToUnless(),
110: "testfiles/reverseif.rb", "if !tr^ue");
111: }
112:
113: public void testHint3() throws Exception {
114: findHints(this , new ConvertIfToUnless(),
115: "testfiles/reverseif.rb", "i^f x != 5");
116: }
117:
118: public void testHint4() throws Exception {
119: findHints(this , new ConvertIfToUnless(),
120: "testfiles/reverseif.rb", "i^f (x != 6)");
121: }
122:
123: public void testHint5() throws Exception {
124: findHints(this , new ConvertIfToUnless(),
125: "testfiles/reverseif.rb", "unl^ess !x");
126: }
127:
128: public void testHint6() throws Exception {
129: findHints(this , new ConvertIfToUnless(),
130: "testfiles/reverseif.rb", "i^f !(x < 8)");
131: }
132:
133: public void testHint7() throws Exception {
134: findHints(this , new ConvertIfToUnless(),
135: "testfiles/reverseif.rb", "i^f (x != 9)");
136: }
137:
138: public void testHint8() throws Exception {
139: findHints(this , new ConvertIfToUnless(),
140: "testfiles/reverseif.rb", "^x != 11");
141: }
142:
143: public void testHint10() throws Exception {
144: findHints(this , new ConvertIfToUnless(),
145: "testfiles/reverseif.rb", "un^less (x != 6)");
146: }
147:
148: public void testHint11() throws Exception {
149: findHints(this , new ConvertIfToUnless(),
150: "testfiles/reverseif.rb", "^x != 12");
151: }
152:
153: public void testFix1() throws Exception {
154: applyHint(this , new ConvertIfToUnless(),
155: "testfiles/reverseif.rb", "if !tr^ue",
156: "Change if into an unless statement and reverse condition logic");
157: }
158:
159: public void testFix2() throws Exception {
160: applyHint(this , new ConvertIfToUnless(),
161: "testfiles/reverseif.rb", "i^f x != 5",
162: "Change if into an unless statement and reverse condition logic");
163: }
164:
165: public void testFix3() throws Exception {
166: applyHint(this , new ConvertIfToUnless(),
167: "testfiles/reverseif.rb", "i^f (x != 6)",
168: "Change if into an unless statement and reverse condition logic");
169: }
170:
171: public void testFix4() throws Exception {
172: applyHint(this , new ConvertIfToUnless(),
173: "testfiles/reverseif.rb", "unless^ !x",
174: "Change unless into an if statement and reverse condition logic");
175: }
176:
177: public void testFix5() throws Exception {
178: applyHint(this , new ConvertIfToUnless(),
179: "testfiles/reverseif.rb", "i^f !(x < 8)",
180: "Change if into an unless statement and reverse condition logic");
181: }
182:
183: public void testFix6() throws Exception {
184: applyHint(this , new ConvertIfToUnless(),
185: "testfiles/reverseif.rb", "i^f (x != 9)",
186: "Change if into an unless statement and reverse condition logic");
187: }
188:
189: public void testFix7() throws Exception {
190: applyHint(this , new ConvertIfToUnless(),
191: "testfiles/reverseif.rb", "^x != 11",
192: "Change if into an unless statement and reverse condition logic");
193: }
194:
195: public void testFix8() throws Exception {
196: applyHint(this , new ConvertIfToUnless(),
197: "testfiles/reverseif.rb", "un^less (x != 6)",
198: "Change unless into an if statement and reverse condition logic");
199: }
200:
201: public void testFix9() throws Exception {
202: applyHint(this , new ConvertIfToUnless(),
203: "testfiles/reverseif.rb", "^x != 12",
204: "Change unless into an if statement and reverse condition logic");
205: }
206:
207: public void testFix10() throws Exception {
208: applyHint(this , new ConvertIfToUnless(),
209: "testfiles/reverseif.rb", "^x != 13",
210: "Change unless into an if statement and reverse condition logic");
211: }
212:
213: public void testFix11() throws Exception {
214: applyHint(this , new ConvertIfToUnless(),
215: "testfiles/reverseif.rb", "^x != 14",
216: "Change if into an unless statement and reverse condition logic");
217: }
218:
219: // public void testNoPositives() throws Exception {
220: // try {
221: // parseErrorsOk = true;
222: // Set<String> exceptions = new HashSet<String>();
223: //
224: //// // Known exceptions
225: // exceptions.add("remote_fetcher.rb");
226: //
227: // assertNoJRubyMatches(new ConvertIfToUnless(), exceptions);
228: //
229: // } finally {
230: // parseErrorsOk = false;
231: // }
232: // }
233:
234: }
|