Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / testsuite / javax.swing.text.html.parser / test / gnu / javax / swing / text / html / parser / low / ReaderTokenizer_Test.java
blobebfda42a946546e199f4bc6157725203b7e8b075
1 /* ReaderTokenizer_Test.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package test.gnu.javax.swing.text.html.parser.low;
41 import test.gnu.javax.swing.text.html.parser.TestCase;
43 import gnu.javax.swing.text.html.parser.support.low.Constants;
44 import gnu.javax.swing.text.html.parser.support.low.ReaderTokenizer;
45 import gnu.javax.swing.text.html.parser.support.low.Token;
46 import gnu.javax.swing.text.html.parser.support.low.node;
47 import gnu.javax.swing.text.html.parser.support.low.pattern;
49 import java.io.StringReader;
51 import java.util.ArrayList;
53 /**
54 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
56 public class ReaderTokenizer_Test
57 extends TestCase
59 ReaderTokenizer rt = new ReaderTokenizer();
61 public void testComplexToken()
62 throws Exception
64 String x = "< style >x";
66 pattern a =
67 new pattern(new node[]
69 new node(Constants.BEGIN), new node(Constants.NUMTOKEN),
70 new node(Constants.END), new node(Constants.NUMTOKEN)
74 pattern b =
75 new pattern(new node[]
77 new node(Constants.BEGIN), new node(Constants.STYLE),
78 new node(Constants.END), new node(Constants.NUMTOKEN)
82 pattern c =
83 new pattern(new node[]
85 new node(Constants.BEGIN), new node(Constants.WS, true),
86 new node(Constants.STYLE), new node(Constants.WS, true),
87 new node(Constants.END), new node(Constants.NUMTOKEN)
91 pattern d =
92 new pattern(new node[]
94 new node(Constants.BEGIN), new node(Constants.WS, true),
95 new node(Constants.STYLE), new node(Constants.WS, true),
96 new node(Constants.END), new node(Constants.BEGIN)
100 ReaderTokenizer rt = new ReaderTokenizer();
101 rt.reset(new StringReader(x));
103 assertFalse(a.matches(rt));
104 assertFalse(b.matches(rt));
105 assertTrue(c.matches(rt));
106 assertFalse(d.matches(rt));
109 public void testReadingAndAhead()
110 throws Exception
112 ArrayList tokens = new ArrayList();
113 StringBuffer b = new StringBuffer();
114 for (int i = 0; i < 10; i++)
116 String r = rs();
117 b.append(" ");
118 b.append(r + i);
119 tokens.add(" ");
120 tokens.add(r + i);
122 rt.reset(new StringReader(b.toString()));
124 for (int i = 0; i < 10; i++)
126 for (int ah = 0; ah < 10; ah++)
128 Token ahead = rt.getTokenAhead(ah);
129 if (i + ah >= tokens.size())
131 assertEquals(ahead.kind, rt.EOF);
133 else
135 if ((i + ah) % 2 == 0)
136 assertEquals(ahead.kind, rt.WS);
137 else
139 assertEquals(ahead.getImage(), tokens.get(i + ah));
140 assertEquals(ahead.kind, rt.NUMTOKEN);
145 Token r = rt.getNextToken();
146 assertEquals(r.getImage(), tokens.get(i));
150 private String rs()
152 StringBuffer b = new StringBuffer();
153 for (int i = 0; i < 10 * Math.random(); i++)
155 b.append("l");
157 return b.toString();