KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > CharRangesTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.lexer;
21
22 import java.util.List JavaDoc;
23 import junit.framework.TestCase;
24 import org.netbeans.lib.lexer.test.CharRangesDump;
25
26 /**
27  * Test several simple lexer impls.
28  *
29  * @author mmetelka
30  */

31 public class CharRangesTest extends TestCase {
32
33     public CharRangesTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     protected void setUp() throws java.lang.Exception JavaDoc {
38     }
39
40     protected void tearDown() throws java.lang.Exception JavaDoc {
41     }
42
43     public void testCharRanges() {
44         // Check that character ranges of accepted characters for certain
45
// methods of java.lang.Character match expectations
46

47         //new CharRangesDump(new CharRangesDump.CharacterMethodAcceptor("isWhitespace")).dump();
48
//new CharRangesDump(new CharRangesDump.CharacterMethodAcceptor("isWhitespace")).dumpAsserts();
49
List JavaDoc<Integer JavaDoc> charRanges = new CharRangesDump(
50                 new CharRangesDump.CharacterMethodAcceptor("isWhitespace")).charRanges();
51         TestCase.assertEquals(charRanges.get(0).intValue(), 0x9);
52         TestCase.assertEquals(charRanges.get(1).intValue(), 0xd);
53         TestCase.assertEquals(charRanges.get(2).intValue(), 0x1c);
54         TestCase.assertEquals(charRanges.get(3).intValue(), 0x20);
55         
56         //new CharRangesDump(new CharRangesDump.CharacterMethodAcceptor("isJavaIdentifierStart")).dump();
57
//new CharRangesDump(new CharRangesDump.CharacterMethodAcceptor("isJavaIdentifierStart")).dumpAsserts();
58
charRanges = new CharRangesDump(
59                 new CharRangesDump.CharacterMethodAcceptor("isJavaIdentifierStart")).charRanges();
60         TestCase.assertEquals(charRanges.get(0).intValue(), 0x24);
61         TestCase.assertEquals(charRanges.get(1).intValue(), 0x24);
62         TestCase.assertEquals(charRanges.get(2).intValue(), 0x41);
63         TestCase.assertEquals(charRanges.get(3).intValue(), 0x5a);
64         TestCase.assertEquals(charRanges.get(4).intValue(), 0x5f);
65         TestCase.assertEquals(charRanges.get(5).intValue(), 0x5f);
66         TestCase.assertEquals(charRanges.get(6).intValue(), 0x61);
67         TestCase.assertEquals(charRanges.get(7).intValue(), 0x7a);
68         
69
70         //new CharRangesDump(new CharRangesDump.CharacterMethodAcceptor("isJavaIdentifierPart")).dump();
71
//new CharRangesDump(new CharRangesDump.CharacterMethodAcceptor("isJavaIdentifierPart")).dumpAsserts();
72
charRanges = new CharRangesDump(
73                 new CharRangesDump.CharacterMethodAcceptor("isJavaIdentifierPart")).charRanges();
74         TestCase.assertEquals(charRanges.get(0).intValue(), 0x0);
75         TestCase.assertEquals(charRanges.get(1).intValue(), 0x8);
76         TestCase.assertEquals(charRanges.get(2).intValue(), 0xe);
77         TestCase.assertEquals(charRanges.get(3).intValue(), 0x1b);
78         TestCase.assertEquals(charRanges.get(4).intValue(), 0x24);
79         TestCase.assertEquals(charRanges.get(5).intValue(), 0x24);
80         TestCase.assertEquals(charRanges.get(6).intValue(), 0x30);
81         TestCase.assertEquals(charRanges.get(7).intValue(), 0x39);
82         TestCase.assertEquals(charRanges.get(8).intValue(), 0x41);
83         TestCase.assertEquals(charRanges.get(9).intValue(), 0x5a);
84         TestCase.assertEquals(charRanges.get(10).intValue(), 0x5f);
85         TestCase.assertEquals(charRanges.get(11).intValue(), 0x5f);
86         TestCase.assertEquals(charRanges.get(12).intValue(), 0x61);
87         TestCase.assertEquals(charRanges.get(13).intValue(), 0x7a);
88         TestCase.assertEquals(charRanges.get(14).intValue(), 0x7f);
89         TestCase.assertEquals(charRanges.get(15).intValue(), 0x9f);
90
91         TestCase.assertEquals((char)-1, 0xFFFF);
92     }
93
94 }
95
Popular Tags