01: package org.apache.lucene.analysis;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * 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.*;
21: import org.apache.lucene.util.LuceneTestCase;
22:
23: public class TestToken extends LuceneTestCase {
24:
25: public TestToken(String name) {
26: super (name);
27: }
28:
29: public void testToString() throws Exception {
30: char[] b = { 'a', 'l', 'o', 'h', 'a' };
31: Token t = new Token("", 0, 5);
32: t.setTermBuffer(b, 0, 5);
33: assertEquals("(aloha,0,5)", t.toString());
34:
35: t.setTermText("hi there");
36: assertEquals("(hi there,0,5)", t.toString());
37: }
38:
39: public void testMixedStringArray() throws Exception {
40: Token t = new Token("hello", 0, 5);
41: assertEquals(t.termText(), "hello");
42: assertEquals(t.termLength(), 5);
43: assertEquals(new String(t.termBuffer(), 0, 5), "hello");
44: t.setTermText("hello2");
45: assertEquals(t.termLength(), 6);
46: assertEquals(new String(t.termBuffer(), 0, 6), "hello2");
47: t.setTermBuffer("hello3".toCharArray(), 0, 6);
48: assertEquals(t.termText(), "hello3");
49:
50: // Make sure if we get the buffer and change a character
51: // that termText() reflects the change
52: char[] buffer = t.termBuffer();
53: buffer[1] = 'o';
54: assertEquals(t.termText(), "hollo3");
55: }
56: }
|