blob: 53454356e8dbcc742780627afb3329c6e07902b4 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.el.lexer;
import junit.framework.TestCase;
import org.netbeans.lib.lexer.test.FixedTextDescriptor;
import org.netbeans.lib.lexer.test.LexerTestUtilities;
import org.netbeans.lib.lexer.test.RandomCharDescriptor;
import org.netbeans.lib.lexer.test.RandomModifyDescriptor;
import org.netbeans.lib.lexer.test.RandomTextProvider;
import org.netbeans.lib.lexer.test.TestRandomModify;
import org.netbeans.modules.el.lexer.api.ELTokenId;
/**
* Test several simple lexer impls.
*
* @author mmetelka
*/
public class ELLexerRandomTest extends TestCase {
public ELLexerRandomTest(String testName) {
super(testName);
}
protected void setUp() throws java.lang.Exception {
// Set-up testing environment
LexerTestUtilities.setTesting(true);
}
protected void tearDown() throws java.lang.Exception {
}
public void testRandom() throws Exception {
test(0);
}
private void test(long seed) throws Exception {
TestRandomModify randomModify = new TestRandomModify(seed);
randomModify.setLanguage(ELTokenId.language());
//randomModify.setDebugOperation(true);
//randomModify.setDebugDocumentText(true);
//randomModify.setDebugHierarchy(true);
// Explicit inserts/removals checks
randomModify.insertText(0, "(");
randomModify.insertText(1, "1");
randomModify.insertText(2, "2");
randomModify.insertText(3, ")");
randomModify.insertText(2, "+");
randomModify.removeText(2, 1);
randomModify.insertText(2, "-");
randomModify.clearDocument();
// Begin really randomized testing
FixedTextDescriptor[] fixedTexts = new FixedTextDescriptor[] {
FixedTextDescriptor.create(" ", 0.2),
};
RandomCharDescriptor[] regularChars = new RandomCharDescriptor[] {
RandomCharDescriptor.digit(0.2),
RandomCharDescriptor.space(0.2),
RandomCharDescriptor.chars(new char[] { '+', '-', '(', ')' }, 0.3),
};
RandomTextProvider regularTextProvider = new RandomTextProvider(regularChars, fixedTexts);
randomModify.test(
new RandomModifyDescriptor[] {
new RandomModifyDescriptor(20, regularTextProvider,
0.4, 0.2, 0.2,
0.1, 0.1,
0.0, 0.0), // snapshots create/destroy
new RandomModifyDescriptor(20, regularTextProvider,
0.2, 0.2, 0.1,
0.4, 0.3,
0.0, 0.0), // snapshots create/destroy
}
);
}
}