KickJava   Java API By Example, From Geeks To Geeks.

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


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.api.html.lexer.HTMLTokenId;
18 import org.netbeans.lib.lexer.test.FixedTextDescriptor;
19 import org.netbeans.lib.lexer.test.LexerTestUtilities;
20 import org.netbeans.lib.lexer.test.RandomCharDescriptor;
21 import org.netbeans.lib.lexer.test.RandomModifyDescriptor;
22 import org.netbeans.lib.lexer.test.RandomTextProvider;
23 import org.netbeans.lib.lexer.test.TestRandomModify;
24
25 /**
26  * Test several simple lexer impls.
27  *
28  * @author mmetelka
29  */

30 public class HTMLLexerRandomTest extends TestCase {
31     
32     public HTMLLexerRandomTest(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(HTMLTokenId.language());
51         
52         //randomModify.setDebugOperation(true);
53
//randomModify.setDebugDocumentText(true);
54
//randomModify.setDebugHierarchy(true);
55

56         // Explicit inserts/removals checks
57
randomModify.insertText(0, "<a>");
58         randomModify.insertText(2, " "); //mfukala - IMO it will be broken even here
59
randomModify.removeText(2, 1);
60         
61         randomModify.clearDocument();
62
63         //mfukala - temp. test
64
randomModify.insertText(0, "<body>");
65         randomModify.insertText(5, " "); // error: '>' is text here
66
randomModify.insertText(6, "bgcolor='red'"); //error: attr name and value are lexed incorrectly
67
randomModify.clearDocument();
68         
69         // Begin really randomized testing
70
FixedTextDescriptor[] fixedTexts = new FixedTextDescriptor[] {
71             FixedTextDescriptor.create("/>", 0.2),
72         };
73         
74         RandomCharDescriptor[] regularChars = new RandomCharDescriptor[] {
75             RandomCharDescriptor.letter(0.2),
76             RandomCharDescriptor.space(0.2),
77             RandomCharDescriptor.lf(0.05),
78             RandomCharDescriptor.chars(new char[] { '<', '>', '=' }, 0.3),
79         };
80
81         RandomTextProvider regularTextProvider = new RandomTextProvider(regularChars, fixedTexts);
82         
83         randomModify.test(
84             new RandomModifyDescriptor[] {
85                 new RandomModifyDescriptor(200, regularTextProvider,
86                         0.4, 0.2, 0.2,
87                         0.1, 0.1,
88                         0.0, 0.0), // snapshots create/destroy
89
new RandomModifyDescriptor(200, regularTextProvider,
90                         0.2, 0.2, 0.1,
91                         0.4, 0.3,
92                         0.0, 0.0), // snapshots create/destroy
93
}
94         );
95     }
96     
97 }
98
Popular Tags