pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / path / TestReversePathHierarchyTokenizer.java
1 package org.apache.lucene.analysis.path;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.io.StringReader;
21
22 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
23
24 public class TestReversePathHierarchyTokenizer extends BaseTokenStreamTestCase {
25
26   public void testBasicReverse() throws Exception {
27     String path = "/a/b/c";
28     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
29     assertTokenStreamContents(t,
30         new String[]{"/a/b/c", "a/b/c", "b/c", "c"},
31         new int[]{0, 1, 3, 5},
32         new int[]{6, 6, 6, 6},
33         new int[]{1, 0, 0, 0},
34         path.length());
35   }
36
37   public void testEndOfDelimiterReverse() throws Exception {
38     String path = "/a/b/c/";
39     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
40     assertTokenStreamContents(t,
41         new String[]{"/a/b/c/", "a/b/c/", "b/c/", "c/"},
42         new int[]{0, 1, 3, 5},
43         new int[]{7, 7, 7, 7},
44         new int[]{1, 0, 0, 0},
45         path.length());
46   }
47
48   public void testStartOfCharReverse() throws Exception {
49     String path = "a/b/c";
50     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
51     assertTokenStreamContents(t,
52         new String[]{"a/b/c", "b/c", "c"},
53         new int[]{0, 2, 4},
54         new int[]{5, 5, 5},
55         new int[]{1, 0, 0},
56         path.length());
57   }
58
59   public void testStartOfCharEndOfDelimiterReverse() throws Exception {
60     String path = "a/b/c/";
61     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
62     assertTokenStreamContents(t,
63         new String[]{"a/b/c/", "b/c/", "c/"},
64         new int[]{0, 2, 4},
65         new int[]{6, 6, 6},
66         new int[]{1, 0, 0},
67         path.length());
68   }
69
70   public void testOnlyDelimiterReverse() throws Exception {
71     String path = "/";
72     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
73     assertTokenStreamContents(t,
74         new String[]{"/"},
75         new int[]{0},
76         new int[]{1},
77         new int[]{1},
78         path.length());
79   }
80
81   public void testOnlyDelimitersReverse() throws Exception {
82     String path = "//";
83     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
84     assertTokenStreamContents(t,
85         new String[]{"//", "/"},
86         new int[]{0, 1},
87         new int[]{2, 2},
88         new int[]{1, 0},
89         path.length());
90   }
91
92   public void testEndOfDelimiterReverseSkip() throws Exception {
93     String path = "/a/b/c/";
94     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 1 );
95     assertTokenStreamContents(t,
96         new String[]{"/a/b/", "a/b/", "b/"},
97         new int[]{0, 1, 3},
98         new int[]{5, 5, 5},
99         new int[]{1, 0, 0},
100         path.length());
101   }
102
103   public void testStartOfCharReverseSkip() throws Exception {
104     String path = "a/b/c";
105     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 1 );
106     assertTokenStreamContents(t,
107         new String[]{"a/b/", "b/"},
108         new int[]{0, 2},
109         new int[]{4, 4},
110         new int[]{1, 0},
111         path.length());
112   }
113
114   public void testStartOfCharEndOfDelimiterReverseSkip() throws Exception {
115     String path = "a/b/c/";
116     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 1 );
117     assertTokenStreamContents(t,
118         new String[]{"a/b/", "b/"},
119         new int[]{0, 2},
120         new int[]{4, 4},
121         new int[]{1, 0},
122         path.length());
123   }
124
125   public void testOnlyDelimiterReverseSkip() throws Exception {
126     String path = "/";
127     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 1 );
128     assertTokenStreamContents(t,
129         new String[]{},
130         new int[]{},
131         new int[]{},
132         new int[]{},
133         path.length());
134   }
135
136   public void testOnlyDelimitersReverseSkip() throws Exception {
137     String path = "//";
138     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 1 );
139     assertTokenStreamContents(t,
140         new String[]{"/"},
141         new int[]{0},
142         new int[]{1},
143         new int[]{1},
144         path.length());
145   }
146
147   public void testReverseSkip2() throws Exception {
148     String path = "/a/b/c/";
149     ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 2 );
150     assertTokenStreamContents(t,
151         new String[]{"/a/", "a/"},
152         new int[]{0, 1},
153         new int[]{3, 3},
154         new int[]{1, 0},
155         path.length());
156   }
157 }