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: * The Original Software is NetBeans. The Initial Developer of the Original
038: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
039: * Microsystems, Inc. All Rights Reserved.
040: *
041: * If you wish your version of this file to be governed by only the CDDL
042: * or only the GPL Version 2, indicate your decision by adding
043: * "[Contributor] elects to include this software in this distribution
044: * under the [CDDL or GPL Version 2] license." If you do not indicate a
045: * single choice of license, a recipient has the option to distribute
046: * your version of this file under either the CDDL, the GPL Version 2 or
047: * to extend the choice of license to its licensees as provided above.
048: * However, if you add GPL Version 2 code and therefore, elected the GPL
049: * Version 2 license, then the option applies only if the new code is
050: * made subject to such option by the copyright holder.
051: */
052:
053: package org.netbeans.modules.cnd.lexer;
054:
055: import junit.framework.Test;
056: import junit.framework.TestSuite;
057: import org.netbeans.api.lexer.Token;
058: import org.netbeans.api.lexer.TokenSequence;
059: import org.netbeans.junit.NbTestSuite;
060:
061: /**
062: *
063: * @author Vladimir Voskresensky
064: */
065: public class CndLexerUnitTest extends NbTestSuite {
066:
067: public CndLexerUnitTest() {
068: super ("C/C++ Lexer");
069: addTestSuite(CppFlyTokensTestCase.class);
070: addTestSuite(CppLexerBatchTestCase.class);
071: addTestSuite(CppLexerPerformanceTestCase.class);
072: addTestSuite(CppStringLexerTestCase.class);
073: addTestSuite(DoxygenLexerTestCase.class);
074: addTestSuite(PreprocLexerTestCase.class);
075: addTestSuite(EscapeLineTestCase.class);
076: }
077:
078: public static Test suite() {
079: TestSuite suite = new CndLexerUnitTest();
080: return suite;
081: }
082:
083: public static void dumpTokens(TokenSequence<?> ts) {
084: if (ts != null) {
085: while (ts.moveNext()) {
086: Token<?> token = ts.token();
087: System.err
088: .println("LexerTestUtilities.assertNextTokenEquals(ts, CppTokenId."
089: + token.id()
090: + ", \""
091: + escapeText(token.text()) + "\");");
092: }
093: }
094: System.err
095: .println("\nassertFalse(\"No more tokens\", ts.moveNext());");
096: System.err.println("------");
097: }
098:
099: private static String escapeText(CharSequence in) {
100: StringBuilder out = new StringBuilder();
101: for (int i = 0; i < in.length(); i++) {
102: char ch = in.charAt(i);
103: switch (ch) {
104: case '\r':
105: out.append("\\r");
106: break;
107: case '\n':
108: out.append("\\n");
109: break;
110: case '\"':
111: out.append("\\\"");
112: break;
113: case '\\':
114: out.append("\\\\");
115: break;
116: default:
117: out.append(ch);
118: }
119: }
120: return out.toString();
121: }
122: }
|