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-2006 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.lib.html.lexer;
043:
044: import junit.framework.TestCase;
045: import org.netbeans.lib.lexer.test.FixedTextDescriptor;
046: import org.netbeans.lib.lexer.test.LexerTestUtilities;
047: import org.netbeans.lib.lexer.test.RandomCharDescriptor;
048: import org.netbeans.lib.lexer.test.RandomModifyDescriptor;
049: import org.netbeans.lib.lexer.test.RandomTextProvider;
050: import org.netbeans.lib.lexer.test.TestRandomModify;
051: import org.netbeans.modules.el.lexer.api.ELTokenId;
052:
053: /**
054: * Test several simple lexer impls.
055: *
056: * @author mmetelka
057: */
058: public class ELLexerRandomTest extends TestCase {
059:
060: public ELLexerRandomTest(String testName) {
061: super (testName);
062: }
063:
064: protected void setUp() throws java.lang.Exception {
065: // Set-up testing environment
066: LexerTestUtilities.setTesting(true);
067: }
068:
069: protected void tearDown() throws java.lang.Exception {
070: }
071:
072: public void testRandom() throws Exception {
073: test(0);
074: }
075:
076: private void test(long seed) throws Exception {
077: TestRandomModify randomModify = new TestRandomModify(seed);
078: randomModify.setLanguage(ELTokenId.language());
079:
080: //randomModify.setDebugOperation(true);
081: //randomModify.setDebugDocumentText(true);
082: //randomModify.setDebugHierarchy(true);
083:
084: // Explicit inserts/removals checks
085: randomModify.insertText(0, "(");
086: randomModify.insertText(1, "1");
087: randomModify.insertText(2, "2");
088: randomModify.insertText(3, ")");
089: randomModify.insertText(2, "+");
090: randomModify.removeText(2, 1);
091: randomModify.insertText(2, "-");
092:
093: randomModify.clearDocument();
094:
095: // Begin really randomized testing
096: FixedTextDescriptor[] fixedTexts = new FixedTextDescriptor[] { FixedTextDescriptor
097: .create(" ", 0.2), };
098:
099: RandomCharDescriptor[] regularChars = new RandomCharDescriptor[] {
100: RandomCharDescriptor.digit(0.2),
101: RandomCharDescriptor.space(0.2),
102: RandomCharDescriptor.chars(new char[] { '+', '-', '(',
103: ')' }, 0.3), };
104:
105: RandomTextProvider regularTextProvider = new RandomTextProvider(
106: regularChars, fixedTexts);
107:
108: randomModify.test(new RandomModifyDescriptor[] {
109: new RandomModifyDescriptor(20, regularTextProvider,
110: 0.4, 0.2, 0.2, 0.1, 0.1, 0.0, 0.0), // snapshots create/destroy
111: new RandomModifyDescriptor(20, regularTextProvider,
112: 0.2, 0.2, 0.1, 0.4, 0.3, 0.0, 0.0), // snapshots create/destroy
113: });
114: }
115:
116: }
|