1 // Test line iteration of BreakIterator. |
|
2 |
|
3 // Copyright (c) 1999 Cygnus Solutions |
|
4 // Written by Tom Tromey <tromey@cygnus.com> |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 // Tags: JDK1.1 |
|
24 |
|
25 package gnu.testlet.java.text.BreakIterator; |
|
26 |
|
27 import gnu.testlet.Testlet; |
|
28 import gnu.testlet.TestHarness; |
|
29 |
|
30 import java.text.BreakIterator; |
|
31 import java.util.Locale; |
|
32 |
|
33 public class lineiter implements Testlet |
|
34 { |
|
35 public void check (String name, String in, String[] out, BreakIterator bi, |
|
36 TestHarness harness) |
|
37 { |
|
38 harness.checkPoint (name); |
|
39 bi.setText (in); |
|
40 |
|
41 int index = 0; |
|
42 int from = bi.current(); |
|
43 harness.check (from, 0); |
|
44 |
|
45 while (true) |
|
46 { |
|
47 int to = bi.next(); |
|
48 if (to == BreakIterator.DONE) |
|
49 break; |
|
50 harness.check (in.substring (from, to), out[index]); |
|
51 ++index; |
|
52 from = to; |
|
53 } |
|
54 |
|
55 harness.check (index, out.length); |
|
56 |
|
57 |
|
58 harness.checkPoint ("backwards " + name); |
|
59 bi.last(); |
|
60 index = out.length - 1; |
|
61 from = bi.current (); |
|
62 harness.check (from, in.length()); |
|
63 |
|
64 while (true) |
|
65 { |
|
66 int to = bi.previous(); |
|
67 if (to == BreakIterator.DONE) |
|
68 break; |
|
69 harness.check (in.substring (to, from), out[index]); |
|
70 --index; |
|
71 from = to; |
|
72 } |
|
73 |
|
74 harness.check (index, -1); |
|
75 } |
|
76 |
|
77 public void test (TestHarness harness) |
|
78 { |
|
79 // Just to be explicit: we're only testing the US locale here. |
|
80 Locale loc = Locale.US; |
|
81 Locale.setDefault (loc); |
|
82 |
|
83 BreakIterator bi = BreakIterator.getLineInstance (loc); |
|
84 |
|
85 String[] r1 = { "How ", "much ", "time ", "is ", "left? ", |
|
86 "We ", "don't ", "know." }; |
|
87 check ("How much", "How much time is left? We don't know.", r1, |
|
88 bi, harness); |
|
89 } |
|
90 } |
|