1 package org.apache.maven.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import junit.framework.TestCase;
22
23 public class EnhancedStringTokenizerTest
24 extends TestCase
25 {
26 public EnhancedStringTokenizerTest( String name )
27 {
28 super( name );
29 }
30
31 protected void setUp()
32 throws Exception
33 {
34 }
35
36 protected void tearDown()
37 throws Exception
38 {
39 }
40
41 public void testSimple()
42 {
43 EnhancedStringTokenizer tok = new EnhancedStringTokenizer( "a,b,c,d,,e,,,f,,,,,g", "," );
44 checkTokens( tok );
45 }
46
47 /**
48 * @param tok The tokenizer to check
49 */
50 private void checkTokens( EnhancedStringTokenizer tok )
51 {
52 assertEquals( "Token 1", "a", tok.nextToken() );
53 assertEquals( "Token 2", "b", tok.nextToken() );
54 assertEquals( "Token 3", "c", tok.nextToken() );
55 assertEquals( "Token 4", "d", tok.nextToken() );
56 assertEquals( "Token 5", "", tok.nextToken() );
57 assertEquals( "Token 6", "e", tok.nextToken() );
58 assertEquals( "Token 7", "", tok.nextToken() );
59 assertEquals( "Token 8", "", tok.nextToken() );
60 assertEquals( "Token 9", "f", tok.nextToken() );
61 assertEquals( "Token 10", "", tok.nextToken() );
62 assertEquals( "Token 11", "", tok.nextToken() );
63 assertEquals( "Token 12", "", tok.nextToken() );
64 assertEquals( "Token 13", "", tok.nextToken() );
65 assertEquals( "Token 14", "g", tok.nextToken() );
66 assertEquals( "tok.hasMoreTokens()", false, tok.hasMoreTokens() );
67 }
68
69 public void testSimpleTab()
70 {
71 EnhancedStringTokenizer tok = new EnhancedStringTokenizer( "a\tb\tc\td\t\te\t\t\tf\t\t\t\t\tg", "\t" );
72 checkTokens( tok );
73 }
74
75 public void testNoDelim()
76 {
77 EnhancedStringTokenizer tok = new EnhancedStringTokenizer( "a,b,c,d,,e,,,f,,,,,g", "\t" );
78 assertEquals( "Token 1", "a,b,c,d,,e,,,f,,,,,g", tok.nextToken() );
79 assertEquals( "tok.hasMoreTokens()", false, tok.hasMoreTokens() );
80 }
81
82 public void testNoText()
83 {
84 EnhancedStringTokenizer tok = new EnhancedStringTokenizer( "", "," );
85 assertEquals( "tok.hasMoreTokens()", false, tok.hasMoreTokens() );
86 }
87
88 public void testReturnDelim()
89 {
90 EnhancedStringTokenizer tok = new EnhancedStringTokenizer( "a,b,,c,d", ",", true );
91 assertEquals( "Token 1", "a", tok.nextToken() );
92 assertEquals( "Token 2", ",", tok.nextToken() );
93 assertEquals( "Token 3", "b", tok.nextToken() );
94 assertEquals( "Token 4", ",", tok.nextToken() );
95 assertEquals( "Token 5", "", tok.nextToken() );
96 assertEquals( "Token 6", ",", tok.nextToken() );
97 assertEquals( "Token 7", "c", tok.nextToken() );
98 assertEquals( "Token 2", ",", tok.nextToken() );
99 assertEquals( "Token 8", "d", tok.nextToken() );
100 assertEquals( "tok.hasMoreTokens()", false, tok.hasMoreTokens() );
101 }
102
103 public void testMultipleDelim()
104 {
105 EnhancedStringTokenizer tok = new EnhancedStringTokenizer( "a.,b.,c.d", ".,", true );
106 assertEquals( "Token 1", "a", tok.nextToken() );
107 assertEquals( "Token 2", ".", tok.nextToken() );
108 assertEquals( "Token 3", "", tok.nextToken() );
109 assertEquals( "Token 4", ",", tok.nextToken() );
110 assertEquals( "Token 5", "b", tok.nextToken() );
111 assertEquals( "Token 6", ".", tok.nextToken() );
112 assertEquals( "Token 7", "", tok.nextToken() );
113 assertEquals( "Token 8", ",", tok.nextToken() );
114 assertEquals( "Token 9", "c", tok.nextToken() );
115 assertEquals( "Token 10", ".", tok.nextToken() );
116 assertEquals( "Token 11", "d", tok.nextToken() );
117 assertEquals( "tok.hasMoreTokens()", false, tok.hasMoreTokens() );
118 }
119
120 }