KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > util > test > TestTokenizer


1 /******************************************************************
2  * File: TestTokenizer.java
3  * Created by: Dave Reynolds
4  * Created on: 24-Jun-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: TestTokenizer.java,v 1.4 2005/02/21 12:19:23 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.util.test;
11
12 import com.hp.hpl.jena.util.Tokenizer;
13
14 import junit.framework.TestCase;
15 import junit.framework.TestSuite;
16
17 /**
18  * Test for the trivial tokenizer utility.
19  *
20  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
21  * @version $Revision: 1.4 $ on $Date: 2005/02/21 12:19:23 $
22  */

23 public class TestTokenizer extends TestCase {
24          
25     /**
26      * Boilerplate for junit
27      */

28     public TestTokenizer( String JavaDoc name ) {
29         super( name );
30     }
31     
32     /**
33      * Boilerplate for junit.
34      * This is its own test suite
35      */

36     public static TestSuite suite() {
37         return new TestSuite( TestTokenizer.class );
38     }
39     
40     /**
41      * Test tokenizer on a basic example or two.
42      */

43     public void testTokenizer() {
44         Tokenizer tokenizer = new Tokenizer("a(foo,bar) 'i am a literal' so there", "()[], \t\n\r'", "'", true);
45         assertEquals(tokenizer.nextToken(), "a");
46         assertEquals(tokenizer.nextToken(), "(");
47         assertEquals(tokenizer.nextToken(), "foo");
48         assertEquals(tokenizer.nextToken(), ",");
49         assertEquals(tokenizer.nextToken(), "bar");
50         assertEquals(tokenizer.nextToken(), ")");
51         assertEquals(tokenizer.nextToken(), " ");
52         assertEquals(tokenizer.nextToken(), " ");
53         assertEquals(tokenizer.nextToken(), "'");
54         assertEquals(tokenizer.nextToken(), "i am a literal");
55         assertEquals(tokenizer.nextToken(), "'");
56         assertEquals(tokenizer.nextToken(), " ");
57         assertEquals(tokenizer.nextToken(), "so");
58         assertEquals(tokenizer.nextToken(), " ");
59         assertEquals(tokenizer.nextToken(), "there");
60         assertTrue( ! tokenizer.hasMoreTokens());
61           
62         tokenizer = new Tokenizer("a(foo,bar) 'i am a literal' so there", "()[], \t\n\r'", "'", false);
63         assertEquals(tokenizer.nextToken(), "a");
64         assertEquals(tokenizer.nextToken(), "foo");
65         assertEquals(tokenizer.nextToken(), "bar");
66         assertEquals(tokenizer.nextToken(), "i am a literal");
67         assertEquals(tokenizer.nextToken(), "so");
68         assertEquals(tokenizer.nextToken(), "there");
69         assertTrue( ! tokenizer.hasMoreTokens());
70           
71     }
72     
73
74 }
75
76
77 /*
78     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
79     All rights reserved.
80
81     Redistribution and use in source and binary forms, with or without
82     modification, are permitted provided that the following conditions
83     are met:
84
85     1. Redistributions of source code must retain the above copyright
86        notice, this list of conditions and the following disclaimer.
87
88     2. Redistributions in binary form must reproduce the above copyright
89        notice, this list of conditions and the following disclaimer in the
90        documentation and/or other materials provided with the distribution.
91
92     3. The name of the author may not be used to endorse or promote products
93        derived from this software without specific prior written permission.
94
95     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
96     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
97     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
98     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
99     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
101     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
102     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
103     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
104     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105 */
Popular Tags