1 package org.apache.lucene.analysis.path;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.StringReader;
22 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
24 public class TestReversePathHierarchyTokenizer extends BaseTokenStreamTestCase {
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},
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},
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"},
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/"},
70 public void testOnlyDelimiterReverse() throws Exception {
72 ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
73 assertTokenStreamContents(t,
81 public void testOnlyDelimitersReverse() throws Exception {
83 ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path) );
84 assertTokenStreamContents(t,
85 new String[]{"//", "/"},
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/"},
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/"},
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/"},
125 public void testOnlyDelimiterReverseSkip() throws Exception {
127 ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 1 );
128 assertTokenStreamContents(t,
136 public void testOnlyDelimitersReverseSkip() throws Exception {
138 ReversePathHierarchyTokenizer t = new ReversePathHierarchyTokenizer( new StringReader(path), 1 );
139 assertTokenStreamContents(t,
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/"},