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: package org.netbeans.modules.cnd.editor.cplusplus;
042:
043: import org.netbeans.editor.TokenID;
044:
045: /**
046: * Test case for tokenizing preprocessor directives in document
047: *
048: * @author Vladimir Voskresensky
049: */
050: public class CCTokenizePreprocessorUnitTestCase extends
051: CCTokenizeUnitTestCase {
052:
053: public CCTokenizePreprocessorUnitTestCase(String testMethodName) {
054: super (testMethodName);
055: }
056:
057: public void testIncludeDirectiveNoSpace() {
058: doParse("#include<file.h>\n" + "#include\"file.h\"\n",
059: new TokenID[] { CCTokenContext.CPPINCLUDE,
060: CCTokenContext.SYS_INCLUDE,
061: CCTokenContext.WHITESPACE,
062: CCTokenContext.CPPINCLUDE,
063: CCTokenContext.USR_INCLUDE,
064: CCTokenContext.WHITESPACE }, true);
065: }
066:
067: public void testIncludeDirective() {
068: doParse("# include <folder/file.h>\n"
069: + "# include \"folder/file.h\"\n",
070: new TokenID[] { CCTokenContext.CPPINCLUDE,
071: CCTokenContext.WHITESPACE,
072: CCTokenContext.SYS_INCLUDE,
073: CCTokenContext.WHITESPACE,
074: CCTokenContext.CPPINCLUDE,
075: CCTokenContext.WHITESPACE,
076: CCTokenContext.USR_INCLUDE,
077: CCTokenContext.WHITESPACE }, false);
078:
079: }
080:
081: public void testAloneSharpDirective() {
082: doParse("#\n", new TokenID[] { CCTokenContext.HASH,
083: CCTokenContext.WHITESPACE }, false);
084: }
085:
086: public void testAloneSharpDirectiveWithSpace() {
087: doParse("# \n", new TokenID[] { CCTokenContext.HASH,
088: CCTokenContext.WHITESPACE }, false);
089: }
090:
091: public void testStructAfterSharpIdDirective() {
092: doParse("# id\n" + "struct A {\n" + "};", new TokenID[] {
093: CCTokenContext.CPPIDENTIFIER,
094: CCTokenContext.WHITESPACE, CCTokenContext.STRUCT,
095: CCTokenContext.WHITESPACE, CCTokenContext.IDENTIFIER,
096: CCTokenContext.WHITESPACE, CCTokenContext.LBRACE,
097: CCTokenContext.WHITESPACE, CCTokenContext.RBRACE,
098: CCTokenContext.SEMICOLON }, false);
099: }
100:
101: public void testStructAfterSharpDirective() {
102: doParse("# \n" + "struct A {\n" + "};", new TokenID[] {
103: CCTokenContext.HASH, CCTokenContext.WHITESPACE,
104: CCTokenContext.STRUCT, CCTokenContext.WHITESPACE,
105: CCTokenContext.IDENTIFIER, CCTokenContext.WHITESPACE,
106: CCTokenContext.LBRACE, CCTokenContext.WHITESPACE,
107: CCTokenContext.RBRACE, CCTokenContext.SEMICOLON },
108: false);
109: }
110:
111: public void testStructAfterPPDirective() {
112: doParse("# 1 id\n" + "struct A {\n" + "};", new TokenID[] {
113: CCTokenContext.HASH, CCTokenContext.INT_LITERAL,
114: CCTokenContext.WHITESPACE, CCTokenContext.IDENTIFIER,
115: CCTokenContext.WHITESPACE, CCTokenContext.STRUCT,
116: CCTokenContext.WHITESPACE, CCTokenContext.IDENTIFIER,
117: CCTokenContext.WHITESPACE, CCTokenContext.LBRACE,
118: CCTokenContext.WHITESPACE, CCTokenContext.RBRACE,
119: CCTokenContext.SEMICOLON }, false);
120: }
121:
122: public void testDefineDirectiveWithSpace() {
123: doParse("# define A B\n", new TokenID[] {
124: CCTokenContext.CPPDEFINE, CCTokenContext.WHITESPACE,
125: CCTokenContext.IDENTIFIER, CCTokenContext.WHITESPACE,
126: CCTokenContext.IDENTIFIER, CCTokenContext.WHITESPACE },
127: false);
128: }
129: }
|