2 *******************************************************************************
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
8 package com.ibm.icu.dev.test.util;
10 import com.ibm.icu.dev.test.TestFmwk;
11 import com.ibm.icu.impl.Utility;
12 import com.ibm.icu.text.ReplaceableString;
13 import com.ibm.icu.text.UnicodeSet;
14 import com.ibm.icu.util.StringTokenizer;
17 * Testing class for StringTokenizer class
18 * @author Syn Wee Quek
21 public final class StringTokenizerTest extends TestFmwk
23 // constructor ===================================================
28 public StringTokenizerTest()
32 // public methods --------------------------------------------------------
35 * Testing constructors
37 public void TestConstructors()
39 String str = "this\tis\na\rstring\ftesting\tStringTokenizer\nconstructors!";
40 String delimiter = " \t\n\r\f";
41 String expected[] = {"this", "is", "a", "string", "testing",
42 "StringTokenizer", "constructors!"};
43 StringTokenizer defaultst = new StringTokenizer(str);
44 StringTokenizer stdelimiter = new StringTokenizer(str, delimiter);
45 StringTokenizer stdelimiterreturn = new StringTokenizer(str, delimiter,
47 UnicodeSet delimiterset = new UnicodeSet("[" + delimiter + "]", false);
48 StringTokenizer stdelimiterset = new StringTokenizer(str, delimiterset);
49 StringTokenizer stdelimitersetreturn = new StringTokenizer(str,
52 for (int i = 0; i < expected.length; i ++) {
53 if (!(defaultst.nextElement().equals(expected[i])
54 && stdelimiter.nextElement().equals(expected[i])
55 && stdelimiterreturn.nextElement().equals(expected[i])
56 && stdelimiterset.nextElement().equals(expected[i])
57 && stdelimitersetreturn.nextElement().equals(expected[i]))) {
58 errln("Constructor with default delimiter gives wrong results");
62 UnicodeSet delimiterset1 = new UnicodeSet("[" + delimiter + "]", true);
63 StringTokenizer stdelimiterset1 = new StringTokenizer(str, delimiterset1);
64 if(!(stdelimiterset1.nextElement().equals(str)))
65 errln("Constructor with a UnicodeSet to ignoreWhiteSpace is " +
66 "to return the same string.");
68 String expected1[] = {"this", "\t", "is", "\n", "a", "\r", "string", "\f",
69 "testing", "\t", "StringTokenizer", "\n",
71 stdelimiterreturn = new StringTokenizer(str, delimiter, true);
72 stdelimitersetreturn = new StringTokenizer(str, delimiterset, true);
73 for (int i = 0; i < expected1.length; i ++) {
74 if (!(stdelimiterreturn.nextElement().equals(expected1[i])
75 && stdelimitersetreturn.nextElement().equals(expected1[i]))) {
76 errln("Constructor with default delimiter and delimiter tokens gives wrong results");
80 stdelimiter = new StringTokenizer(str, (String)null);
81 stdelimiterreturn = new StringTokenizer(str, (String)null, false);
83 stdelimiterset = new StringTokenizer(str, delimiterset);
84 stdelimitersetreturn = new StringTokenizer(str, delimiterset, false);
86 if (!(stdelimiter.nextElement().equals(str)
87 && stdelimiterreturn.nextElement().equals(str)
88 && stdelimiterset.nextElement().equals(str)
89 && stdelimitersetreturn.nextElement().equals(str))) {
90 errln("Constructor with null delimiter gives wrong results");
94 stdelimiter = new StringTokenizer(str, delimiter);
95 stdelimiterreturn = new StringTokenizer(str, delimiter, false);
96 delimiterset = new UnicodeSet();
97 stdelimiterset = new StringTokenizer(str, delimiterset);
98 stdelimitersetreturn = new StringTokenizer(str, delimiterset, false);
100 if (!(stdelimiter.nextElement().equals(str)
101 && stdelimiterreturn.nextElement().equals(str)
102 && stdelimiterset.nextElement().equals(str)
103 && stdelimitersetreturn.nextElement().equals(str))) {
104 errln("Constructor with empty delimiter gives wrong results");
108 defaultst = new StringTokenizer(null);
109 errln("null string should throw an exception");
110 } catch (Exception e) {
111 logln("PASS: Constructor with null string failed as expected");
114 stdelimiter = new StringTokenizer(null, delimiter);
115 errln("null string should throw an exception");
116 } catch (Exception e) {
117 logln("PASS: Constructor with null string failed as expected");
120 stdelimiterreturn = new StringTokenizer(null, delimiter, false);
121 errln("null string should throw an exception");
122 } catch (Exception e) {
123 logln("PASS: Constructor with null string failed as expected");
126 stdelimiterset = new StringTokenizer(null, delimiterset);
127 errln("null string should throw an exception");
128 } catch (Exception e) {
129 logln("PASS: Constructor with null string failed as expected");
132 stdelimitersetreturn = new StringTokenizer(null, delimiterset,
134 errln("null string should throw an exception");
135 } catch (Exception e) {
136 logln("PASS: Constructor with null string failed as expected");
141 * Testing supplementary
143 public void TestSupplementary()
145 String str = "bmp string \ud800 with a unmatched surrogate character";
146 String delimiter = "\ud800\udc00";
147 String expected[] = {str};
149 StringTokenizer tokenizer = new StringTokenizer(str, delimiter);
150 if (!tokenizer.nextElement().equals(expected[0])) {
151 errln("Error parsing \"" + Utility.hex(str) + "\"");
153 if (tokenizer.hasMoreElements()) {
154 errln("Number of tokens exceeded expected");
156 delimiter = "\ud800";
157 String expected1[] = {"bmp string ",
158 " with a unmatched surrogate character"};
159 tokenizer = new StringTokenizer(str, delimiter);
161 while (tokenizer.hasMoreElements()) {
162 if (!tokenizer.nextElement().equals(expected1[i ++])) {
163 errln("Error parsing \"" + Utility.hex(str) + "\"");
166 if (tokenizer.hasMoreElements()) {
167 errln("Number of tokens exceeded expected");
170 str = "string \ud800\udc00 with supplementary character";
171 delimiter = "\ud800";
172 String expected2[] = {str};
173 tokenizer = new StringTokenizer(str, delimiter);
174 if (!tokenizer.nextElement().equals(expected2[0])) {
175 errln("Error parsing \"" + Utility.hex(str) + "\"");
177 if (tokenizer.hasMoreElements()) {
178 errln("Number of tokens exceeded expected");
181 delimiter = "\ud800\udc00";
182 String expected3[] = {"string ", " with supplementary character"};
183 tokenizer = new StringTokenizer(str, delimiter);
185 while (tokenizer.hasMoreElements()) {
186 if (!tokenizer.nextElement().equals(expected3[i ++])) {
187 errln("Error parsing \"" + Utility.hex(str) + "\"");
190 if (tokenizer.hasMoreElements()) {
191 errln("Number of tokens exceeded expected");
194 str = "\ud800 \ud800\udc00 \ud800 \ud800\udc00";
195 delimiter = "\ud800";
196 String expected4[] = {" \ud800\udc00 ", " \ud800\udc00"};
198 while (tokenizer.hasMoreElements()) {
199 if (!tokenizer.nextElement().equals(expected4[i ++])) {
200 errln("Error parsing \"" + Utility.hex(str) + "\"");
203 if (tokenizer.hasMoreElements()) {
204 errln("Number of tokens exceeded expected");
207 delimiter = "\ud800\udc00";
208 String expected5[] = {"\ud800 ", " \ud800 "};
210 while (tokenizer.hasMoreElements()) {
211 if (!tokenizer.nextElement().equals(expected5[i ++])) {
212 errln("Error parsing \"" + Utility.hex(str) + "\"");
215 if (tokenizer.hasMoreElements()) {
216 errln("Number of tokens exceeded expected");
223 public void TestNextNonDelimiterToken()
225 String str = " , 1 2 3 AHHHHH! 5.5 6 7 , 8\n";
226 String expected[] = {",", "1", "2", "3", "AHHHHH!", "5.5", "6", "7",
228 String delimiter = " ";
230 StringTokenizer tokenizer = new StringTokenizer(str, delimiter);
232 while (tokenizer.hasMoreElements()) {
233 if (!tokenizer.nextElement().equals(expected[currtoken])) {
234 errln("Error token mismatch, expected " + expected[currtoken]);
239 if (currtoken != expected.length) {
240 errln("Didn't get correct number of tokens");
243 tokenizer = new StringTokenizer("", delimiter);
244 if (tokenizer.hasMoreElements()) {
245 errln("Empty string should not have any tokens");
248 tokenizer.nextElement();
249 errln("Empty string should not have any tokens");
250 } catch (Exception e) {
251 logln("PASS: empty string failed as expected");
254 tokenizer = new StringTokenizer(", ,", ", ");
255 if (tokenizer.hasMoreElements()) {
256 errln("String with only delimiters should not have any tokens");
259 tokenizer.nextElement();
260 errln("String with only delimiters should not have any tokens");
261 } catch (Exception e) {
262 logln("PASS: String with only delimiters failed as expected");
265 tokenizer = new StringTokenizer("q, ,", ", ");
266 if (!tokenizer.hasMoreElements()) {
267 errln("String that does not begin with delimiters should have some tokens");
269 if (!tokenizer.nextElement().equals("q")) {
270 errln("String that does not begin with delimiters should have some tokens");
273 tokenizer.nextElement();
274 errln("String has only one token");
275 } catch (Exception e) {
276 logln("PASS: String with only one token failed as expected");
280 tokenizer = new StringTokenizer(null, delimiter);
281 errln("StringTokenizer constructed with null source should throw a nullpointerexception");
282 } catch (Exception e) {
283 logln("PASS: StringTokenizer constructed with null source failed as expected");
286 tokenizer = new StringTokenizer(str, "q");
287 if (!tokenizer.nextElement().equals(str)) {
288 errln("Should have received the same string when there are no delimiters");
293 * Test java compatibility, except we support surrogates.
295 public void TestNoCoalesce() {
296 String str = "This is a test\rto see if\nwhitespace is handled \n\r unusually\r\n by our tokenizer\n\n\n!!!plus some other odd ones like \ttab\ttab\ttab\nand form\ffeed\ffoo.\n";
297 String delims = " \t\n\r\f\ud800\udc00";
299 java.util.StringTokenizer jt = new java.util.StringTokenizer(str, delims, true);
300 com.ibm.icu.util.StringTokenizer it = new com.ibm.icu.util.StringTokenizer(str, delims, true);
302 while (jt.hasMoreTokens() && it.hasMoreTokens()) {
303 assertEquals("[" + String.valueOf(n++) + "]", jt.nextToken(), it.nextToken());
305 assertFalse("java tokenizer has no more tokens", jt.hasMoreTokens());
306 assertFalse("icu tokenizer has no more tokens", it.hasMoreTokens());
308 String sur = "Even\ud800\udc00 works.\n\n";
309 it = new com.ibm.icu.util.StringTokenizer(sur, delims, true); // no coalesce
310 assertEquals("sur1", it.nextToken(), "Even");
311 assertEquals("sur2", it.nextToken(), "\ud800\udc00");
312 assertEquals("sur3", it.nextToken(), " ");
313 assertEquals("sur4", it.nextToken(), "works.");
314 assertEquals("sur5", it.nextToken(), "\n");
315 assertEquals("sur6", it.nextToken(), "\n");
316 assertFalse("sur7", it.hasMoreTokens());
322 public void TestNextDelimiterToken()
324 String str = " , 1 2 3 AHHHHH! 5.5 6 7 , 8\n";
325 String expected[] = {" ", ",", " ", "1", " ", "2", " ", "3", " ",
326 "AHHHHH!", " ", "5.5", " ", "6", " ", "7", " ",
328 String delimiter = " ";
330 StringTokenizer tokenizer = new StringTokenizer(str, delimiter, true, true);
333 while (tokenizer.hasMoreElements()) {
334 if (!tokenizer.nextElement().equals(expected[currtoken])) {
335 errln("Error token mismatch, expected " + expected[currtoken]);
340 if (currtoken != expected.length) {
341 errln("Didn't get correct number of tokens");
344 tokenizer = new StringTokenizer("", delimiter, true);
345 if (tokenizer.hasMoreElements()) {
346 errln("Empty string should not have any tokens");
349 tokenizer.nextElement();
350 errln("Empty string should not have any tokens");
351 } catch (Exception e) {
352 logln("PASS: Empty string failed as expected");
355 tokenizer = new StringTokenizer(", ,", ", ", true, true);
356 if (!tokenizer.hasMoreElements()) {
357 errln("String with only delimiters should have tokens when delimiter is treated as tokens");
359 if (!tokenizer.nextElement().equals(", ,")) {
360 errln("String with only delimiters should return itself when delimiter is treated as tokens");
363 tokenizer = new StringTokenizer("q, ,", ", ", true, true);
365 if (!tokenizer.hasMoreElements()) {
366 errln("String should have some tokens");
368 if (!tokenizer.nextElement().equals("q")
369 || !tokenizer.nextElement().equals(", ,")) {
370 errln("String tokens do not match expected results");
374 tokenizer = new StringTokenizer(null, delimiter, true);
375 errln("StringTokenizer constructed with null source should throw a nullpointerexception");
376 } catch (Exception e) {
377 logln("PASS: StringTokenizer constructed with null source failed as expected");
380 tokenizer = new StringTokenizer(str, "q", true);
381 if (!tokenizer.nextElement().equals(str)) {
382 errln("Should have recieved the same string when there are no delimiters");
387 * Testing count tokens
389 public void TestCountTokens()
391 String str = "this\tis\na\rstring\ftesting\tStringTokenizer\nconstructors!";
392 String delimiter = " \t\n\r\f";
393 String expected[] = {"this", "is", "a", "string", "testing",
394 "StringTokenizer", "constructors!"};
395 String expectedreturn[] = {"this", "\t", "is", "\n", "a", "\r",
396 "string", "\f", "testing", "\t",
397 "StringTokenizer", "\n", "constructors!"};
398 StringTokenizer st = new StringTokenizer(str, delimiter);
399 StringTokenizer streturn = new StringTokenizer(str, delimiter, true);
400 if (st.countTokens() != expected.length) {
401 errln("CountTokens failed for non-delimiter tokens");
403 if (streturn.countTokens() != expectedreturn.length) {
404 errln("CountTokens failed for delimiter tokens");
406 for (int i = 0; i < expected.length; i ++) {
407 if (!st.nextElement().equals(expected[i])
408 || st.countTokens() != expected.length - i - 1) {
409 errln("CountTokens default delimiter gives wrong results");
412 for (int i = 0; i < expectedreturn.length; i ++) {
413 if (!streturn.nextElement().equals(expectedreturn[i])
414 || streturn.countTokens() != expectedreturn.length - i - 1) {
415 errln("CountTokens with default delimiter and delimiter tokens gives wrong results");
421 * Next token with new delimiters
423 public void TestNextNewDelimiters()
425 String str = "abc0def1ghi2jkl3mno4pqr0stu1vwx2yza3bcd4efg0hij1klm2nop3qrs4tuv";
426 String delimiter[] = {"0", "1", "2", "3", "4"};
427 String expected[][] = {{"abc", "pqr", "efg"},
428 {"def", "stu", "hij"},
429 {"ghi", "vwx", "klm"},
430 {"jkl", "yza", "nop"},
431 {"mno", "bcd", "qrs"}
433 StringTokenizer st = new StringTokenizer(str);
434 int size = expected[0].length;
435 for (int i = 0; i < size; i ++) {
436 for (int j = 0; j < delimiter.length; j ++) {
437 if (!st.nextToken(delimiter[j]).equals(expected[j][i])) {
438 errln("nextToken() with delimiters error " + i + " " + j);
440 if (st.countTokens() != expected[j].length - i) {
441 errln("countTokens() after nextToken() with delimiters error"
446 st = new StringTokenizer(str);
447 String delimiter1[] = {"0", "2", "4"};
448 String expected1[] = {"abc", "def1ghi", "jkl3mno", "pqr", "stu1vwx",
449 "yza3bcd", "efg", "hij1klm", "nop3qrs", "tuv"};
450 for (int i = 0; i < expected1.length; i ++) {
451 if (!st.nextToken(delimiter1[i % delimiter1.length]).equals(
453 errln("nextToken() with delimiters error " + i);
458 public void TestBug4423()
460 // bug 4423: a bad interaction between countTokens() and hasMoreTokens().
462 String s1 = "This is a test";
463 StringTokenizer tzr = new StringTokenizer(s1);
466 int t = tzr.countTokens();
468 errln("tzr.countTokens() returned " + t + ". Expected 4");
470 while (tzr.hasMoreTokens()) {
471 String tok = tzr.nextToken();
472 if (tok.length() == 0) {
473 errln("token with length == 0");
477 if (tokenCount != 4) {
478 errln("Incorrect number of tokens found = " + tokenCount);
481 // Precomputed tokens arrays can grow. Check for edge cases around
482 // boundary where growth is forced. Array grows in increments of 100 tokens.
484 for (int i=1; i<250; i++) {
486 StringTokenizer tzb = new StringTokenizer(s2);
487 int t2 = tzb.countTokens();
489 errln("tzb.countTokens() returned " + t + ". Expected " + i);
493 while (tzb.hasMoreTokens()) {
494 String tok = tzb.nextToken();
496 if (tok.equals(Integer.toString(j)) == false) {
497 errln("Wrong token string. Expected \"" + j + "\", got \""
503 errln("Wrong number of tokens. Expected " + i + ". Got " + j
511 public void TestCountTokensNoCoalesce() {
515 StringTokenizer st = new StringTokenizer(str, del, true);
517 while (st.hasMoreTokens()) {
518 String t = st.nextToken();
519 logln("[" + count + "] '" + t + "'");
522 st = new StringTokenizer(str, del, true);
523 int ncount = st.countTokens();
525 while (st.hasMoreTokens()) {
526 String t = st.nextToken();
527 logln("[" + xcount + "] '" + t + "'");
530 if (count != ncount || count != xcount) {
531 errln("inconsistent counts " + count + ", " + ncount + ", " + xcount);
535 public static void main(String[] arg)
539 StringTokenizerTest test = new StringTokenizerTest();
541 // test.TestCaseCompare();
550 * public StringBuffer _generatePattern(StringBuffer result, boolean escapeUnprintable)
552 public void Test_GeneratePattern(){
553 UnicodeSet us = new UnicodeSet();
554 StringBuffer sb = new StringBuffer();
556 us._generatePattern(sb, true);
557 us._generatePattern(sb, false);
558 us._generatePattern(sb.append(1), true);
559 us._generatePattern(sb.append(1.0), true);
560 us._generatePattern(sb.reverse(), true);
561 } catch(Exception e){
562 errln("UnicodeSet._generatePattern is not suppose to return an exception.");
566 us._generatePattern(null, true);
567 errln("UnicodeSet._generatePattern is suppose to return an exception.");
568 } catch(Exception e){}
572 * public int matches(Replaceable text, int[] offset, int limit, boolean incremental)
574 public void TestMatches(){
575 // Tests when "return incremental ? U_PARTIAL_MATCH : U_MATCH;" is true and false
576 ReplaceableString rs = new ReplaceableString("dummy");
577 UnicodeSet us = new UnicodeSet(0,100000); // Create a large Unicode set
583 if(us.matches(null, offset, limit, true) != UnicodeSet.U_PARTIAL_MATCH){
584 errln("UnicodeSet.matches is suppose to return " + UnicodeSet.U_PARTIAL_MATCH +
585 " but got " + us.matches(null, offset, limit, true));
588 if(us.matches(null, offset, limit, false) != UnicodeSet.U_MATCH){
589 errln("UnicodeSet.matches is suppose to return " + UnicodeSet.U_MATCH +
590 " but got " + us.matches(null, offset, limit, false));
593 // Tests when "int maxLen = forward ? limit-offset[0] : offset[0]-limit;" is true and false
595 offset[0] = 0; // Takes the letter "d"
596 us.matches(rs, offset, 1, true);
597 offset[0] = 4; // Takes the letter "y"
598 us.matches(rs, offset, 1, true);
599 } catch(Exception e) {
600 errln("UnicodeSet.matches is not suppose to return an exception");
603 // TODO: Tests when "if (forward && length < highWaterLength)" is true
607 * private static int matchRest (Replaceable text, int start, int limit, String s)
608 * from public int matches(Replaceable text, ...
610 public void TestMatchRest(){
611 // TODO: Tests when "if (maxLen > slen) maxLen = slen;" is true and false
615 * public int matchesAt(CharSequence text, int offset)
617 public void TestMatchesAt(){
618 UnicodeSet us = new UnicodeSet(); // Empty set
619 us.matchesAt((CharSequence)"dummy", 0);
620 us.add("dummy"); // Add an item
622 us.matchesAt((CharSequence)"dummy", 0);
623 us.add("dummy2"); // Add another item
625 us.matchesAt((CharSequence)"yummy", 0); //charAt(0) >
626 us.matchesAt((CharSequence)"amy", 0); //charAt(0) <
628 UnicodeSet us1 = new UnicodeSet(0,100000); // Increase the set
629 us1.matchesAt((CharSequence)"dummy", 0);
633 * public int indexOf(int c)
635 public void TestIndexOf(){
636 // Tests when "if (c < MIN_VALUE || c > MAX_VALUE)" is true
637 UnicodeSet us = new UnicodeSet();
638 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
639 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
640 int[] valid = {UnicodeSet.MIN_VALUE, UnicodeSet.MIN_VALUE+1,
641 UnicodeSet.MAX_VALUE, UnicodeSet.MAX_VALUE-1};
643 for(int i=0; i < invalid.length; i++){
645 us.indexOf(invalid[i]);
646 errln("UnicodeSet.indexOf is suppose to return an exception " +
647 "for a value of " + invalid[i]);
648 } catch(Exception e){}
651 for(int i=0; i < valid.length; i++){
653 us.indexOf(valid[i]);
654 } catch(Exception e){
655 errln("UnicodeSet.indexOf is not suppose to return an exception " +
656 "for a value of " + valid[i]);
662 * public int charAt(int index)
664 public void TestCharAt(){
665 UnicodeSet us = new UnicodeSet();
667 // Test when "if (index >= 0)" is false
668 int[] invalid = {-100,-10,-5,-2,-1};
669 for(int i=0; i < invalid.length; i++){
670 if(us.charAt(invalid[i]) != -1){
671 errln("UnicodeSet.charAt(int index) was suppose to return -1 "
672 + "for an invalid input of " + invalid[i]);
678 * private UnicodeSet add_unchecked(int start, int end)
679 * from public UnicodeSet add(int start, int end)
681 public void TestAdd_int_int(){
682 UnicodeSet us = new UnicodeSet();
683 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
684 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
686 // Tests when "if (start < MIN_VALUE || start > MAX_VALUE)" is true
687 for(int i=0; i < invalid.length; i++){
689 us.add(invalid[i], UnicodeSet.MAX_VALUE);
690 errln("UnicodeSet.add(int start, int end) was suppose to give "
691 + "an exception for an start invalid input of "
693 } catch (Exception e){}
696 // Tests when "if (end < MIN_VALUE || end > MAX_VALUE)" is true
697 for(int i=0; i < invalid.length; i++){
699 us.add(UnicodeSet.MIN_VALUE, invalid[i]);
700 errln("UnicodeSet.add(int start, int end) was suppose to give "
701 + "an exception for an end invalid input of "
703 } catch (Exception e){}
706 // Tests when "else if (start == end)" is false
707 if(!(us.add(UnicodeSet.MIN_VALUE+1, UnicodeSet.MIN_VALUE).equals(us)))
708 errln("UnicodeSet.add(int start, int end) was suppose to return "
709 + "the same object because start of value " + (UnicodeSet.MIN_VALUE+1)
710 + " is greater than end of value " + UnicodeSet.MIN_VALUE);
712 if(!(us.add(UnicodeSet.MAX_VALUE, UnicodeSet.MAX_VALUE-1).equals(us)))
713 errln("UnicodeSet.add(int start, int end) was suppose to return "
714 + "the same object because start of value " + UnicodeSet.MAX_VALUE
715 + " is greater than end of value " + (UnicodeSet.MAX_VALUE-1));
719 * private final UnicodeSet add_unchecked(int c)
720 * from public final UnicodeSet add(int c)
722 public void TestAdd_int(){
723 UnicodeSet us = new UnicodeSet();
724 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
725 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
727 // Tests when "if (c < MIN_VALUE || c > MAX_VALUE)" is true
728 for(int i=0; i < invalid.length; i++){
731 errln("UnicodeSet.add(int c) was suppose to give "
732 + "an exception for an start invalid input of "
734 } catch (Exception e){}
737 // Tests when "if (c == MAX_VALUE)" is true
738 // TODO: Check comment in UnicodeSet.java
742 * private static int getSingleCP(String s)
743 * from public final boolean contains(String s)
745 public void TestGetSingleCP(){
746 UnicodeSet us = new UnicodeSet();
747 // Tests when "if (s.length() < 1)" is true
750 errln("UnicodeSet.getSingleCP is suppose to give an exception for " +
752 } catch (Exception e){}
755 us.contains((String)null);
756 errln("UnicodeSet.getSingleCP is suppose to give an exception for " +
758 } catch (Exception e){}
760 // Tests when "if (cp > 0xFFFF)" is true
761 String[] cases = {"\uD811\uDC00","\uD811\uDC11","\uD811\uDC22"};
762 for(int i=0; i<cases.length; i++){
764 us.contains(cases[i]);
765 } catch (Exception e){
766 errln("UnicodeSet.getSingleCP is not suppose to give an exception for " +
773 * public final UnicodeSet removeAllStrings()
775 public void TestRemoveAllString(){
776 // Tests when "if (strings.size() != 0)" is false
777 UnicodeSet us = new UnicodeSet();
779 us.removeAllStrings();
780 } catch(Exception e){
781 errln("UnicodeSet.removeAllString() was not suppose to given an " +
782 "exception for a strings size of 0");
787 * public UnicodeSet retain(int start, int end)
789 public void TestRetain_int_int(){
790 UnicodeSet us = new UnicodeSet();
791 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
792 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
794 // Tests when "if (start < MIN_VALUE || start > MAX_VALUE)" is true
795 for(int i=0; i < invalid.length; i++){
797 us.retain(invalid[i], UnicodeSet.MAX_VALUE);
798 errln("UnicodeSet.retain(int start, int end) was suppose to give "
799 + "an exception for an start invalid input of "
801 } catch (Exception e){}
804 // Tests when "if (end < MIN_VALUE || end > MAX_VALUE)" is true
805 for(int i=0; i < invalid.length; i++){
807 us.retain(UnicodeSet.MIN_VALUE, invalid[i]);
808 errln("UnicodeSet.retain(int start, int end) was suppose to give "
809 + "an exception for an end invalid input of "
811 } catch (Exception e){}
814 // Tests when "if (start <= end)" is false
816 us.retain(UnicodeSet.MIN_VALUE+1, UnicodeSet.MIN_VALUE);
817 } catch(Exception e){
818 errln("UnicodeSet.retain(int start, int end) was not suppose to give "
823 us.retain(UnicodeSet.MAX_VALUE, UnicodeSet.MAX_VALUE-1);
824 } catch(Exception e){
825 errln("UnicodeSet.retain(int start, int end) was not suppose to give "
831 * public final UnicodeSet retain(String s)
833 public void TestRetain_String(){
834 // Tests when "if (isIn && size() == 1)" is true
835 UnicodeSet us = new UnicodeSet();
837 if(!(us.retain("dummy").equals(us))){
838 errln("UnicodeSet.retain(String s) was suppose to return the " +
839 "same UnicodeSet since the string was found in the original.");
844 * public UnicodeSet remove(int start, int end)
846 public void TestRemove(){
847 UnicodeSet us = new UnicodeSet();
848 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
849 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
851 // Tests when "if (start < MIN_VALUE || start > MAX_VALUE)" is true
852 for(int i=0; i < invalid.length; i++){
854 us.remove(invalid[i], UnicodeSet.MAX_VALUE);
855 errln("UnicodeSet.remove(int start, int end) was suppose to give "
856 + "an exception for an start invalid input of "
858 } catch (Exception e){}
861 // Tests when "if (end < MIN_VALUE || end > MAX_VALUE)" is true
862 for(int i=0; i < invalid.length; i++){
864 us.remove(UnicodeSet.MIN_VALUE, invalid[i]);
865 errln("UnicodeSet.remove(int start, int end) was suppose to give "
866 + "an exception for an end invalid input of "
868 } catch (Exception e){}
871 // Tests when "if (start <= end)" is false
873 us.remove(UnicodeSet.MIN_VALUE+1, UnicodeSet.MIN_VALUE);
874 } catch(Exception e){
875 errln("UnicodeSet.remove(int start, int end) was not suppose to give "
880 us.remove(UnicodeSet.MAX_VALUE, UnicodeSet.MAX_VALUE-1);
881 } catch(Exception e){
882 errln("UnicodeSet.remove(int start, int end) was not suppose to give "
888 * public UnicodeSet complement(int start, int end)
890 public void TestComplement_int_int(){
891 UnicodeSet us = new UnicodeSet();
892 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
893 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
895 // Tests when "if (start < MIN_VALUE || start > MAX_VALUE)" is true
896 for(int i=0; i < invalid.length; i++){
898 us.complement(invalid[i], UnicodeSet.MAX_VALUE);
899 errln("UnicodeSet.complement(int start, int end) was suppose to give "
900 + "an exception for an start invalid input of "
902 } catch (Exception e){}
905 // Tests when "if (end < MIN_VALUE || end > MAX_VALUE)" is true
906 for(int i=0; i < invalid.length; i++){
908 us.complement(UnicodeSet.MIN_VALUE, invalid[i]);
909 errln("UnicodeSet.complement(int start, int end) was suppose to give "
910 + "an exception for an end invalid input of "
912 } catch (Exception e){}
915 // Tests when "if (start <= end)" is false
917 us.complement(UnicodeSet.MIN_VALUE+1, UnicodeSet.MIN_VALUE);
918 } catch(Exception e){
919 errln("UnicodeSet.complement(int start, int end) was not suppose to give "
924 us.complement(UnicodeSet.MAX_VALUE, UnicodeSet.MAX_VALUE-1);
925 } catch(Exception e){
926 errln("UnicodeSet.complement(int start, int end) was not suppose to give "
932 * public final UnicodeSet complement(String s)
934 public void TestComplement_String(){
935 // Tests when "if (cp < 0)" is false
936 UnicodeSet us = new UnicodeSet();
939 us.complement("dummy");
940 } catch (Exception e){
941 errln("UnicodeSet.complement(String s) was not suppose to give "
942 + "an exception for 'dummy'.");
945 // Tests when "if (strings.contains(s))" is true
946 us = new UnicodeSet();
949 us.complement("\uDC11");
950 } catch (Exception e){
951 errln("UnicodeSet.complement(String s) was not suppose to give "
952 + "an exception for '\uDC11'.");
957 * public boolean contains(int c)
959 public void TestContains_int(){
960 UnicodeSet us = new UnicodeSet();
961 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
962 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
964 // Tests when "if (c < MIN_VALUE || c > MAX_VALUE)" is true
965 for(int i=0; i < invalid.length; i++){
967 us.contains(invalid[i]);
968 errln("UnicodeSet.contains(int c) was suppose to give "
969 + "an exception for an start invalid input of "
971 } catch (Exception e){}
976 * public boolean contains(int start, int end)
978 public void TestContains_int_int(){
979 UnicodeSet us = new UnicodeSet();
980 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
981 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
983 // Tests when "if (start < MIN_VALUE || start > MAX_VALUE)" is true
984 for(int i=0; i < invalid.length; i++){
986 us.contains(invalid[i], UnicodeSet.MAX_VALUE);
987 errln("UnicodeSet.contains(int start, int end) was suppose to give "
988 + "an exception for an start invalid input of "
990 } catch (Exception e){}
993 // Tests when "if (end < MIN_VALUE || end > MAX_VALUE)" is true
994 for(int i=0; i < invalid.length; i++){
996 us.contains(UnicodeSet.MIN_VALUE, invalid[i]);
997 errln("UnicodeSet.contains(int start, int end) was suppose to give "
998 + "an exception for an end invalid input of "
1000 } catch (Exception e){}
1005 * public String getRegexEquivalent()
1007 public void TestGetRegexEquivalent(){
1008 UnicodeSet us = new UnicodeSet();
1009 String res = us.getRegexEquivalent();
1010 if(!(res.equals("[]")))
1011 errln("UnicodeSet.getRegexEquivalent is suppose to return '[]' " +
1016 * public boolean containsNone(int start, int end)
1018 public void TestContainsNone(){
1019 UnicodeSet us = new UnicodeSet();
1020 int[] invalid = {UnicodeSet.MIN_VALUE-1, UnicodeSet.MIN_VALUE-2,
1021 UnicodeSet.MAX_VALUE+1, UnicodeSet.MAX_VALUE+2};
1023 // Tests when "if (start < MIN_VALUE || start > MAX_VALUE)" is true
1024 for(int i=0; i < invalid.length; i++){
1026 us.containsNone(invalid[i], UnicodeSet.MAX_VALUE);
1027 errln("UnicodeSet.containsNoneint start, int end) was suppose to give "
1028 + "an exception for an start invalid input of "
1030 } catch (Exception e){}
1033 // Tests when "if (end < MIN_VALUE || end > MAX_VALUE)" is true
1034 for(int i=0; i < invalid.length; i++){
1036 us.containsNone(UnicodeSet.MIN_VALUE, invalid[i]);
1037 errln("UnicodeSet.containsNone(int start, int end) was suppose to give "
1038 + "an exception for an end invalid input of "
1040 } catch (Exception e){}
1043 // Tests when "if (start < list[++i])" is false
1046 us.containsNone(1, 2); // 1 > 0
1047 } catch (Exception e){
1048 errln("UnicodeSet.containsNone(int start, int end) was not suppose to give " +