KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > html > lexer > ELLexerRandomTest


1 /*
2  * Sun Public License Notice
3  *
4  * The contents of this file are subject to the Sun Public License
5  * Version 1.0 (the "License"). You may not use this file except in
6  * compliance with the License. A copy of the License is available at
7  * http://www.sun.com/
8  *
9  * The Original Code is NetBeans. The Initial Developer of the Original
10  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11  * Microsystems, Inc. All Rights Reserved.
12  */

13
14 package org.netbeans.lib.html.lexer;
15
16 import junit.framework.TestCase;
17 import org.netbeans.lib.lexer.test.FixedTextDescriptor;
18 import org.netbeans.lib.lexer.test.LexerTestUtilities;
19 import org.netbeans.lib.lexer.test.RandomCharDescriptor;
20 import org.netbeans.lib.lexer.test.RandomModifyDescriptor;
21 import org.netbeans.lib.lexer.test.RandomTextProvider;
22 import org.netbeans.lib.lexer.test.TestRandomModify;
23 import org.netbeans.modules.el.lexer.api.ELTokenId;
24
25 /**
26  * Test several simple lexer impls.
27  *
28  * @author mmetelka
29  */

30 public class ELLexerRandomTest extends TestCase {
31     
32     public ELLexerRandomTest(String JavaDoc testName) {
33         super(testName);
34     }
35     
36     protected void setUp() throws java.lang.Exception JavaDoc {
37         // Set-up testing environment
38
LexerTestUtilities.setTesting(true);
39     }
40
41     protected void tearDown() throws java.lang.Exception JavaDoc {
42     }
43
44     public void testRandom() throws Exception JavaDoc {
45         test(0);
46     }
47     
48     private void test(long seed) throws Exception JavaDoc {
49         TestRandomModify randomModify = new TestRandomModify(seed);
50         randomModify.setLanguage(ELTokenId.language());
51         
52         //randomModify.setDebugOperation(true);
53
//randomModify.setDebugDocumentText(true);
54
//randomModify.setDebugHierarchy(true);
55

56         // Explicit inserts/removals checks
57
randomModify.insertText(0, "(");
58         randomModify.insertText(1, "1");
59         randomModify.insertText(2, "2");
60         randomModify.insertText(3, ")");
61         randomModify.insertText(2, "+");
62         randomModify.removeText(2, 1);
63         randomModify.insertText(2, "-");
64         
65         randomModify.clearDocument();
66         
67         // Begin really randomized testing
68
FixedTextDescriptor[] fixedTexts = new FixedTextDescriptor[] {
69             FixedTextDescriptor.create(" ", 0.2),
70         };
71         
72         RandomCharDescriptor[] regularChars = new RandomCharDescriptor[] {
73             RandomCharDescriptor.digit(0.2),
74             RandomCharDescriptor.space(0.2),
75             RandomCharDescriptor.chars(new char[] { '+', '-', '(', ')' }, 0.3),
76         };
77
78         RandomTextProvider regularTextProvider = new RandomTextProvider(regularChars, fixedTexts);
79         
80         randomModify.test(
81             new RandomModifyDescriptor[] {
82                 new RandomModifyDescriptor(20, regularTextProvider,
83                         0.4, 0.2, 0.2,
84                         0.1, 0.1,
85                         0.0, 0.0), // snapshots create/destroy
86
new RandomModifyDescriptor(20, regularTextProvider,
87                         0.2, 0.2, 0.1,
88                         0.4, 0.3,
89                         0.0, 0.0), // snapshots create/destroy
90
}
91         );
92     }
93     
94 }
95
Popular Tags