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.lexer;
043:
044: import javax.swing.text.Document;
045: import junit.framework.TestCase;
046: import org.netbeans.modules.gsf.api.CompilationInfo;
047: import org.netbeans.modules.ruby.lexer.RubyTokenId;
048: import org.netbeans.modules.gsf.api.OffsetRange;
049: import org.netbeans.api.lexer.Token;
050: import org.netbeans.api.lexer.TokenHierarchy;
051: import org.netbeans.api.lexer.TokenId;
052: import org.netbeans.api.lexer.TokenSequence;
053: import org.netbeans.editor.BaseDocument;
054: import org.netbeans.modules.ruby.RubyTestBase;
055: import org.netbeans.modules.ruby.lexer.Call;
056:
057: /**
058: *
059: * @author Tor Norbye
060: */
061: public class LexUtilitiesTest extends RubyTestBase {
062:
063: public LexUtilitiesTest(String testName) {
064: super (testName);
065: }
066:
067: // public void testGetLexerOffset() {
068: // System.out.println("getLexerOffset");
069: // CompilationInfo info = null;
070: // int astOffset = 0;
071: // int expResult = 0;
072: // int result = LexUtilities.getLexerOffset(info, astOffset);
073: // assertEquals(expResult, result);
074: // fail("The test case is a prototype.");
075: // } /* Test of getLexerOffset method, of class LexUtilities. */
076: //
077: // public void testGetRubyTokenSequence() {
078: // System.out.println("getRubyTokenSequence");
079: // BaseDocument doc = null;
080: // int offset = 0;
081: // TokenSequence expResult = null;
082: // TokenSequence result = LexUtilities.getRubyTokenSequence(doc, offset);
083: // assertEquals(expResult, result);
084: // fail("The test case is a prototype.");
085: // } /* Test of getRubyTokenSequence method, of class LexUtilities. */
086: //
087: // public void testGetToken() {
088: // System.out.println("getToken");
089: // BaseDocument doc = null;
090: // int offset = 0;
091: // Token expResult = null;
092: // Token result = LexUtilities.getToken(doc, offset);
093: // assertEquals(expResult, result);
094: // fail("The test case is a prototype.");
095: // } /* Test of getToken method, of class LexUtilities. */
096: //
097: // public void testGetTokenChar() {
098: // System.out.println("getTokenChar");
099: // BaseDocument doc = null;
100: // int offset = 0;
101: // char expResult = ' ';
102: // char result = LexUtilities.getTokenChar(doc, offset);
103: // assertEquals(expResult, result);
104: // fail("The test case is a prototype.");
105: // } /* Test of getTokenChar method, of class LexUtilities. */
106: //
107: // public void testFindHeredocEnd() {
108: // System.out.println("findHeredocEnd");
109: // TokenSequence<? extends RubyTokenId> ts = null;
110: // Token<? extends RubyTokenId> startToken = null;
111: // OffsetRange expResult = null;
112: // OffsetRange result = LexUtilities.findHeredocEnd(ts, startToken);
113: // assertEquals(expResult, result);
114: // fail("The test case is a prototype.");
115: // } /* Test of findHeredocEnd method, of class LexUtilities. */
116: //
117: // public void testFindHeredocBegin() {
118: // System.out.println("findHeredocBegin");
119: // TokenSequence<? extends RubyTokenId> ts = null;
120: // Token<? extends RubyTokenId> endToken = null;
121: // OffsetRange expResult = null;
122: // OffsetRange result = LexUtilities.findHeredocBegin(ts, endToken);
123: // assertEquals(expResult, result);
124: // fail("The test case is a prototype.");
125: // } /* Test of findHeredocBegin method, of class LexUtilities. */
126: //
127: // public void testFindFwd() {
128: // System.out.println("findFwd");
129: // BaseDocument doc = null;
130: // TokenSequence<? extends RubyTokenId> ts = null;
131: // TokenId up = null;
132: // TokenId down = null;
133: // OffsetRange expResult = null;
134: // OffsetRange result = LexUtilities.findFwd(doc, ts, up, down);
135: // assertEquals(expResult, result);
136: // fail("The test case is a prototype.");
137: // } /* Test of findFwd method, of class LexUtilities. */
138: //
139: // public void testFindBwd() {
140: // System.out.println("findBwd");
141: // BaseDocument doc = null;
142: // TokenSequence<? extends RubyTokenId> ts = null;
143: // TokenId up = null;
144: // TokenId down = null;
145: // OffsetRange expResult = null;
146: // OffsetRange result = LexUtilities.findBwd(doc, ts, up, down);
147: // assertEquals(expResult, result);
148: // fail("The test case is a prototype.");
149: // } /* Test of findBwd method, of class LexUtilities. */
150: //
151: // public void testFindBegin() {
152: // System.out.println("findBegin");
153: // BaseDocument doc = null;
154: // TokenSequence<? extends RubyTokenId> ts = null;
155: // OffsetRange expResult = null;
156: // OffsetRange result = LexUtilities.findBegin(doc, ts);
157: // assertEquals(expResult, result);
158: // fail("The test case is a prototype.");
159: // } /* Test of findBegin method, of class LexUtilities. */
160: //
161: // public void testFindEnd() {
162: // System.out.println("findEnd");
163: // BaseDocument doc = null;
164: // TokenSequence<? extends RubyTokenId> ts = null;
165: // OffsetRange expResult = null;
166: // OffsetRange result = LexUtilities.findEnd(doc, ts);
167: // assertEquals(expResult, result);
168: // fail("The test case is a prototype.");
169: // } /* Test of findEnd method, of class LexUtilities. */
170: //
171: // public void testIsEndmatchingDo() {
172: // System.out.println("isEndmatchingDo");
173: // BaseDocument doc = null;
174: // int offset = 0;
175: // boolean expResult = false;
176: // boolean result = LexUtilities.isEndmatchingDo(doc, offset);
177: // assertEquals(expResult, result);
178: // fail("The test case is a prototype.");
179: // } /* Test of isEndmatchingDo method, of class LexUtilities. */
180: //
181: // public void testIsBeginToken() {
182: // System.out.println("isBeginToken");
183: // TokenId id = null;
184: // BaseDocument doc = null;
185: // int offset = 0;
186: // boolean expResult = false;
187: // boolean result = LexUtilities.isBeginToken(id, doc, offset);
188: // assertEquals(expResult, result);
189: // fail("The test case is a prototype.");
190: // } /* Test of isBeginToken method, of class LexUtilities. */
191: //
192: // public void testIsIndentToken() {
193: // System.out.println("isIndentToken");
194: // TokenId id = null;
195: // boolean expResult = false;
196: // boolean result = LexUtilities.isIndentToken(id);
197: // assertEquals(expResult, result);
198: // fail("The test case is a prototype.");
199: // } /* Test of isIndentToken method, of class LexUtilities. */
200: //
201: // public void testGetBeginEndLineBalance() {
202: // System.out.println("getBeginEndLineBalance");
203: // BaseDocument doc = null;
204: // int offset = 0;
205: // int expResult = 0;
206: // int result = LexUtilities.getBeginEndLineBalance(doc, offset);
207: // assertEquals(expResult, result);
208: // fail("The test case is a prototype.");
209: // } /* Test of getBeginEndLineBalance method, of class LexUtilities. */
210: //
211: // public void testGetLineBalance() {
212: // System.out.println("getLineBalance");
213: // BaseDocument doc = null;
214: // int offset = 0;
215: // TokenId up = null;
216: // TokenId down = null;
217: // int expResult = 0;
218: // int result = LexUtilities.getLineBalance(doc, offset, up, down);
219: // assertEquals(expResult, result);
220: // fail("The test case is a prototype.");
221: // } /* Test of getLineBalance method, of class LexUtilities. */
222: //
223: // public void testGetTokenBalance() throws Exception {
224: // System.out.println("getTokenBalance");
225: // BaseDocument doc = null;
226: // TokenId open = null;
227: // TokenId close = null;
228: // int offset = 0;
229: // int expResult = 0;
230: // int result = LexUtilities.getTokenBalance(doc, open, close, offset);
231: // assertEquals(expResult, result);
232: // fail("The test case is a prototype.");
233: // } /* Test of getTokenBalance method, of class LexUtilities. */
234: //
235: // public void testGetLineIndent() {
236: // System.out.println("getLineIndent");
237: // BaseDocument doc = null;
238: // int offset = 0;
239: // int expResult = 0;
240: // int result = LexUtilities.getLineIndent(doc, offset);
241: // assertEquals(expResult, result);
242: // fail("The test case is a prototype.");
243: // } /* Test of getLineIndent method, of class LexUtilities. */
244: //
245: // public void testIndent() {
246: // System.out.println("indent");
247: // StringBuilder sb = null;
248: // int indent = 0;
249: // LexUtilities.indent(sb, indent);
250: // fail("The test case is a prototype.");
251: // } /* Test of indent method, of class LexUtilities. */
252: //
253: // public void testGetIndentString() {
254: // System.out.println("getIndentString");
255: // int indent = 0;
256: // String expResult = "";
257: // String result = LexUtilities.getIndentString(indent);
258: // assertEquals(expResult, result);
259: // fail("The test case is a prototype.");
260: // } /* Test of getIndentString method, of class LexUtilities. */
261: //
262: // public void testIsCommentOnlyLine() throws Exception {
263: // System.out.println("isCommentOnlyLine");
264: // BaseDocument doc = null;
265: // int offset = 0;
266: // boolean expResult = false;
267: // boolean result = LexUtilities.isCommentOnlyLine(doc, offset);
268: // assertEquals(expResult, result);
269: // fail("The test case is a prototype.");
270: // } /* Test of isCommentOnlyLine method, of class LexUtilities. */
271: //
272: // public void testAdjustLineIndentation() {
273: // System.out.println("adjustLineIndentation");
274: // BaseDocument doc = null;
275: // int offset = 0;
276: // int adjustment = 0;
277: // LexUtilities.adjustLineIndentation(doc, offset, adjustment);
278: // fail("The test case is a prototype.");
279: // } /* Test of adjustLineIndentation method, of class LexUtilities. */
280: //
281: // public void testSetLineIndentation() {
282: // System.out.println("setLineIndentation");
283: // BaseDocument doc = null;
284: // int offset = 0;
285: // int indent = 0;
286: // int expResult = 0;
287: // int result = LexUtilities.setLineIndentation(doc, offset, indent);
288: // assertEquals(expResult, result);
289: // fail("The test case is a prototype.");
290: // } /* Test of setLineIndentation method, of class LexUtilities. */
291: //
292: // public void testGetStringAt() {
293: // System.out.println("getStringAt");
294: // int caretOffset = 0;
295: // TokenHierarchy<Document> th = null;
296: // String expResult = "";
297: // String result = LexUtilities.getStringAt(caretOffset, th);
298: // assertEquals(expResult, result);
299: // fail("The test case is a prototype.");
300: // } /* Test of getStringAt method, of class LexUtilities. */
301: //
302: // public void testGetRequireStringOffset() {
303: // System.out.println("getRequireStringOffset");
304: // int caretOffset = 0;
305: // TokenHierarchy<Document> th = null;
306: // int expResult = 0;
307: // int result = LexUtilities.getRequireStringOffset(caretOffset, th);
308: // assertEquals(expResult, result);
309: // fail("The test case is a prototype.");
310: // } /* Test of getRequireStringOffset method, of class LexUtilities. */
311: //
312: // public void testGetSingleQuotedStringOffset() {
313: // System.out.println("getSingleQuotedStringOffset");
314: // int caretOffset = 0;
315: // TokenHierarchy<Document> th = null;
316: // int expResult = 0;
317: // int result = LexUtilities.getSingleQuotedStringOffset(caretOffset, th);
318: // assertEquals(expResult, result);
319: // fail("The test case is a prototype.");
320: // } /* Test of getSingleQuotedStringOffset method, of class LexUtilities. */
321: //
322: // public void testGetDoubleQuotedStringOffset() {
323: // System.out.println("getDoubleQuotedStringOffset");
324: // int caretOffset = 0;
325: // TokenHierarchy<Document> th = null;
326: // int expResult = 0;
327: // int result = LexUtilities.getDoubleQuotedStringOffset(caretOffset, th);
328: // assertEquals(expResult, result);
329: // fail("The test case is a prototype.");
330: // } /* Test of getDoubleQuotedStringOffset method, of class LexUtilities. */
331: //
332: // public void testGetRegexpOffset() {
333: // System.out.println("getRegexpOffset");
334: // int caretOffset = 0;
335: // TokenHierarchy<Document> th = null;
336: // int expResult = 0;
337: // int result = LexUtilities.getRegexpOffset(caretOffset, th);
338: // assertEquals(expResult, result);
339: // fail("The test case is a prototype.");
340: // } /* Test of getRegexpOffset method, of class LexUtilities. */
341: //
342: // public void testGetCallType() {
343: // System.out.println("getCallType");
344: // BaseDocument doc = null;
345: // TokenHierarchy<Document> th = null;
346: // int offset = 0;
347: // Call expResult = null;
348: // Call result = LexUtilities.getCallType(doc, th, offset);
349: // assertEquals(expResult, result);
350: // fail("The test case is a prototype.");
351: // } /* Test of getCallType method, of class LexUtilities. */
352: //
353: public void testIsInsideQuotedString() {
354: String s = "x = \"foo\" ";
355: BaseDocument doc = getDocument(s);
356: for (int i = 0; i < 4; i++) {
357: assertFalse(LexUtilities.isInsideQuotedString(doc, i));
358: }
359: for (int i = 5; i <= 8; i++) {
360: assertTrue(LexUtilities.isInsideQuotedString(doc, i));
361: }
362: for (int i = 9; i < s.length(); i++) {
363: assertFalse(LexUtilities.isInsideQuotedString(doc, i));
364: }
365: }
366:
367: public void testIsInsideEmptyQuotedString() {
368: String s = "x = \"\"";
369: BaseDocument doc = getDocument(s);
370: for (int i = 0; i < 4; i++) {
371: assertFalse(LexUtilities.isInsideQuotedString(doc, i));
372: }
373: assertTrue(LexUtilities.isInsideQuotedString(doc, 5));
374: assertFalse(LexUtilities.isInsideQuotedString(doc, 6));
375: }
376:
377: public void testIsInsideQuotedStringNegative() {
378: String s = "x = 'foo'";
379: BaseDocument doc = getDocument(s);
380: for (int i = 0; i < s.length(); i++) {
381: assertFalse(LexUtilities.isInsideQuotedString(doc, i));
382: }
383: }
384:
385: public void testIsInsideRegexp() {
386: String s = "x = /foo/ ";
387: BaseDocument doc = getDocument(s);
388: for (int i = 0; i < 4; i++) {
389: assertFalse(LexUtilities.isInsideRegexp(doc, i));
390: }
391: for (int i = 5; i <= 8; i++) {
392: assertTrue(LexUtilities.isInsideRegexp(doc, i));
393: }
394: for (int i = 9; i < s.length(); i++) {
395: assertFalse(LexUtilities.isInsideRegexp(doc, i));
396: }
397: }
398:
399: public void testIsInsideEmptyRegexp() {
400: String s = "x = //";
401: BaseDocument doc = getDocument(s);
402: for (int i = 0; i < 4; i++) {
403: assertFalse(LexUtilities.isInsideRegexp(doc, i));
404: }
405: assertTrue(LexUtilities.isInsideRegexp(doc, 5));
406: assertFalse(LexUtilities.isInsideRegexp(doc, 6));
407: }
408:
409: public void testIsInsideRegexpNegative() {
410: String s = "x = 'foo'";
411: BaseDocument doc = getDocument(s);
412: for (int i = 0; i < s.length(); i++) {
413: assertFalse(LexUtilities.isInsideRegexp(doc, i));
414: }
415: }
416:
417: public void testFindSpaceBegin() {
418: // Spaces in strings don't count
419: String s = "x = 'f oo'";
420: BaseDocument doc = getDocument(s);
421: assertEquals(0, LexUtilities.findSpaceBegin(doc, 0));
422: assertEquals(1, LexUtilities.findSpaceBegin(doc, 1));
423: assertEquals(1, LexUtilities.findSpaceBegin(doc, 2));
424: assertEquals(3, LexUtilities.findSpaceBegin(doc, 3));
425: assertEquals(3, LexUtilities.findSpaceBegin(doc, 4));
426: assertEquals(3, LexUtilities.findSpaceBegin(doc, 5));
427: assertEquals(6, LexUtilities.findSpaceBegin(doc, 6));
428: assertEquals(7, LexUtilities.findSpaceBegin(doc, 7));
429: assertEquals(8, LexUtilities.findSpaceBegin(doc, 8));
430: assertEquals(9, LexUtilities.findSpaceBegin(doc, 9));
431: assertEquals(10, LexUtilities.findSpaceBegin(doc, 10));
432: }
433:
434: public void testFindSpaceBeginNoNewlines() {
435: // Spaces in strings don't count
436: String s = "x = \n 'f oo'";
437: BaseDocument doc = getDocument(s);
438: assertEquals(0, LexUtilities.findSpaceBegin(doc, 0));
439: assertEquals(1, LexUtilities.findSpaceBegin(doc, 1));
440: assertEquals(1, LexUtilities.findSpaceBegin(doc, 2));
441: assertEquals(3, LexUtilities.findSpaceBegin(doc, 3));
442: assertEquals(3, LexUtilities.findSpaceBegin(doc, 4));
443: assertEquals(5, LexUtilities.findSpaceBegin(doc, 5));
444: assertEquals(6, LexUtilities.findSpaceBegin(doc, 6));
445: assertEquals(7, LexUtilities.findSpaceBegin(doc, 7));
446: assertEquals(8, LexUtilities.findSpaceBegin(doc, 8));
447: assertEquals(9, LexUtilities.findSpaceBegin(doc, 9));
448: assertEquals(10, LexUtilities.findSpaceBegin(doc, 10));
449: }
450:
451: public void testFindSpaceBeginNoNewlinesBlank() {
452: String s = "x = \n ";
453: BaseDocument doc = getDocument(s);
454: assertEquals(0, LexUtilities.findSpaceBegin(doc, 0));
455: assertEquals(1, LexUtilities.findSpaceBegin(doc, 1));
456: assertEquals(1, LexUtilities.findSpaceBegin(doc, 2));
457: assertEquals(3, LexUtilities.findSpaceBegin(doc, 3));
458: assertEquals(3, LexUtilities.findSpaceBegin(doc, 4));
459: assertEquals(5, LexUtilities.findSpaceBegin(doc, 5));
460: assertEquals(6, LexUtilities.findSpaceBegin(doc, 6));
461: assertEquals(7, LexUtilities.findSpaceBegin(doc, 7));
462: assertEquals(8, LexUtilities.findSpaceBegin(doc, 8));
463: }
464:
465: public void testFindSpaceBeginLineContinuation() {
466: String s = "foo(a, \n f";
467: BaseDocument doc = getDocument(s);
468: assertEquals(0, LexUtilities.findSpaceBegin(doc, 0));
469: assertEquals(1, LexUtilities.findSpaceBegin(doc, 1));
470: assertEquals(2, LexUtilities.findSpaceBegin(doc, 2));
471: assertEquals(3, LexUtilities.findSpaceBegin(doc, 3));
472: assertEquals(4, LexUtilities.findSpaceBegin(doc, 4));
473: assertEquals(5, LexUtilities.findSpaceBegin(doc, 5));
474: assertEquals(6, LexUtilities.findSpaceBegin(doc, 6));
475: assertEquals(6, LexUtilities.findSpaceBegin(doc, 7));
476: assertEquals(6, LexUtilities.findSpaceBegin(doc, 8));
477: assertEquals(6, LexUtilities.findSpaceBegin(doc, 9));
478: assertEquals(6, LexUtilities.findSpaceBegin(doc, 10));
479: assertEquals(6, LexUtilities.findSpaceBegin(doc, 11));
480: assertEquals(12, LexUtilities.findSpaceBegin(doc, 12));
481: }
482:
483: public void testFindSpaceBeginBlanks() {
484: String s = " \n ";
485: BaseDocument doc = getDocument(s);
486: assertEquals(0, LexUtilities.findSpaceBegin(doc, 0));
487: assertEquals(1, LexUtilities.findSpaceBegin(doc, 1));
488: assertEquals(2, LexUtilities.findSpaceBegin(doc, 2));
489: assertEquals(3, LexUtilities.findSpaceBegin(doc, 3));
490: assertEquals(4, LexUtilities.findSpaceBegin(doc, 4));
491: }
492: }
|