Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
29   89   6   5.8
2   65   0.21   5
5     1.2  
1    
 
  TestAnalyzers       Line # 22 29 6 100% 1.0
 
  (3)
 
1    package org.apache.lucene.analysis;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import java.io.*;
20    import junit.framework.*;
21   
 
22    public class TestAnalyzers extends TestCase {
23   
 
24  3 toggle public TestAnalyzers(String name) {
25  3 super(name);
26    }
27   
 
28  18 toggle public void assertAnalyzesTo(Analyzer a,
29    String input,
30    String[] output) throws Exception {
31  18 TokenStream ts = a.tokenStream("dummy", new StringReader(input));
32  64 for (int i=0; i<output.length; i++) {
33  46 Token t = ts.next();
34  46 assertNotNull(t);
35  46 assertEquals(t.termText(), output[i]);
36    }
37  18 assertNull(ts.next());
38  18 ts.close();
39    }
40   
 
41  1 toggle public void testSimple() throws Exception {
42  1 Analyzer a = new SimpleAnalyzer();
43  1 assertAnalyzesTo(a, "foo bar FOO BAR",
44    new String[] { "foo", "bar", "foo", "bar" });
45  1 assertAnalyzesTo(a, "foo bar . FOO <> BAR",
46    new String[] { "foo", "bar", "foo", "bar" });
47  1 assertAnalyzesTo(a, "foo.bar.FOO.BAR",
48    new String[] { "foo", "bar", "foo", "bar" });
49  1 assertAnalyzesTo(a, "U.S.A.",
50    new String[] { "u", "s", "a" });
51  1 assertAnalyzesTo(a, "C++",
52    new String[] { "c" });
53  1 assertAnalyzesTo(a, "B2B",
54    new String[] { "b", "b" });
55  1 assertAnalyzesTo(a, "2B",
56    new String[] { "b" });
57  1 assertAnalyzesTo(a, "\"QUOTED\" word",
58    new String[] { "quoted", "word" });
59    }
60   
 
61  1 toggle public void testNull() throws Exception {
62  1 Analyzer a = new WhitespaceAnalyzer();
63  1 assertAnalyzesTo(a, "foo bar FOO BAR",
64    new String[] { "foo", "bar", "FOO", "BAR" });
65  1 assertAnalyzesTo(a, "foo bar . FOO <> BAR",
66    new String[] { "foo", "bar", ".", "FOO", "<>", "BAR" });
67  1 assertAnalyzesTo(a, "foo.bar.FOO.BAR",
68    new String[] { "foo.bar.FOO.BAR" });
69  1 assertAnalyzesTo(a, "U.S.A.",
70    new String[] { "U.S.A." });
71  1 assertAnalyzesTo(a, "C++",
72    new String[] { "C++" });
73  1 assertAnalyzesTo(a, "B2B",
74    new String[] { "B2B" });
75  1 assertAnalyzesTo(a, "2B",
76    new String[] { "2B" });
77  1 assertAnalyzesTo(a, "\"QUOTED\" word",
78    new String[] { "\"QUOTED\"", "word" });
79    }
80   
 
81  1 toggle public void testStop() throws Exception {
82  1 Analyzer a = new StopAnalyzer();
83  1 assertAnalyzesTo(a, "foo bar FOO BAR",
84    new String[] { "foo", "bar", "foo", "bar" });
85  1 assertAnalyzesTo(a, "foo a bar such FOO THESE BAR",
86    new String[] { "foo", "bar", "foo", "bar" });
87    }
88    }
89