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 ConvertConditionalsTest extends HintTestBase {
045:
046: public ConvertConditionalsTest(String testName) {
047: super (testName);
048: }
049:
050: public void testNoHint1() throws Exception {
051: findHints(this , new ConvertConditionals(),
052: "testfiles/conditionals.rb", null);
053: }
054:
055: public void testNoHint2() throws Exception {
056: findHints(this , new ConvertConditionals(),
057: "testfiles/conditionals2.rb",
058: "uri = env_pr^oxy ? URI.parse(env_proxy) : nil");
059: }
060:
061: public void testNoHint3() throws Exception {
062: findHints(this , new ConvertConditionals(),
063: "testfiles/conditionals2.rb",
064: "(uri =~ /.(https?|ftp|file):/) ? u^ri : \"http://#{uri}\"");
065: }
066:
067: public void testNoHint4() throws Exception {
068: findHints(this , new ConvertConditionals(),
069: "testfiles/emptycondition.rb", "if (^)");
070: }
071:
072: public void testNoHint5() throws Exception {
073: findHints(this , new ConvertConditionals(),
074: "testfiles/conditionals3.rb", "if (^x > 5)");
075: }
076:
077: public void testNoHint6() throws Exception {
078: findHints(this , new ConvertConditionals(),
079: "testfiles/conditionals3.rb",
080: "i^f jd >= commercial_to_jd");
081: }
082:
083: public void testNoHint7() throws Exception {
084: findHints(this , new ConvertConditionals(),
085: "testfiles/elsif.rb", "elsi^f !str.blank?");
086: }
087:
088: public void testNoHint8() throws Exception {
089: findHints(this , new ConvertConditionals(),
090: "testfiles/elsif.rb", "elsif !str.bla^nk?");
091: }
092:
093: public void testNoHint9() throws Exception {
094: findHints(this , new ConvertConditionals(),
095: "testfiles/elsif.rb", "if st^r != 'something'");
096: }
097:
098: public void testNoHint10() throws Exception {
099: findHints(this , new ConvertConditionals(),
100: "testfiles/emptybody.rb", "if !^x");
101: }
102:
103: public void testNoHint11() throws Exception {
104: findHints(this , new ConvertConditionals(),
105: "testfiles/emptybody.rb", "if !^y");
106: }
107:
108: public void testHint2() throws Exception {
109: findHints(this , new ConvertConditionals(),
110: "testfiles/conditionals.rb", "if tr^ue");
111: }
112:
113: public void testHint3() throws Exception {
114: findHints(this , new ConvertConditionals(),
115: "testfiles/conditionals.rb", "i^f x < 5");
116: }
117:
118: public void testHint4() throws Exception {
119: findHints(this , new ConvertConditionals(),
120: "testfiles/conditionals.rb", "i^f (x < 6)");
121: }
122:
123: public void testHint5() throws Exception {
124: findHints(this , new ConvertConditionals(),
125: "testfiles/conditionals.rb", "i^f !x");
126: }
127:
128: public void testHint6() throws Exception {
129: findHints(this , new ConvertConditionals(),
130: "testfiles/conditionals.rb", "i^f x < 8");
131: }
132:
133: public void testHint7() throws Exception {
134: findHints(this , new ConvertConditionals(),
135: "testfiles/conditionals.rb", "i^f x < 9");
136: }
137:
138: public void testHint8() throws Exception {
139: findHints(this , new ConvertConditionals(),
140: "testfiles/conditionals.rb", "^x < 11");
141: }
142:
143: public void testHint9() throws Exception {
144: findHints(this , new ConvertConditionals(),
145: "testfiles/conditionals.rb", "unl^ess x < 5");
146: }
147:
148: public void testHint10() throws Exception {
149: findHints(this , new ConvertConditionals(),
150: "testfiles/conditionals.rb", "un^less (x < 6)");
151: }
152:
153: public void testHint11() throws Exception {
154: findHints(this , new ConvertConditionals(),
155: "testfiles/conditionals.rb", "^x > 12");
156: }
157:
158: public void testHint12() throws Exception {
159: findHints(this , new ConvertConditionals(),
160: "testfiles/conditionals.rb", "i^f x < 12");
161: }
162:
163: public void testFix1() throws Exception {
164: applyHint(this , new ConvertConditionals(),
165: "testfiles/conditionals.rb", "if tr^ue",
166: "Change statement into a modifier");
167: }
168:
169: public void testFix2() throws Exception {
170: applyHint(this , new ConvertConditionals(),
171: "testfiles/conditionals.rb", "i^f x < 5",
172: "Change statement into a modifier");
173: }
174:
175: public void testFix3() throws Exception {
176: applyHint(this , new ConvertConditionals(),
177: "testfiles/conditionals.rb", "i^f (x < 6)",
178: "Change statement into a modifier");
179: }
180:
181: public void testFix4() throws Exception {
182: applyHint(this , new ConvertConditionals(),
183: "testfiles/conditionals.rb", "i^f !x",
184: "Change statement into a modifier");
185: }
186:
187: public void testFix5() throws Exception {
188: applyHint(this , new ConvertConditionals(),
189: "testfiles/conditionals.rb", "unl^ess x < 5",
190: "Change statement into a modifier");
191: }
192:
193: public void testFix6() throws Exception {
194: applyHint(this , new ConvertConditionals(),
195: "testfiles/conditionals.rb", "i^f x < 12",
196: "Change statement into a modifier");
197: }
198:
199: public void testFixPosError() throws Exception {
200: applyHint(this , new ConvertConditionals(),
201: "testfiles/position_errors.rb", "unl^ess !(x < 5)",
202: "Change statement into a modifier");
203: }
204: }
|