pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / queryparser / src / test / org / apache / lucene / queryParser / ext / TestExtensions.java
1 package org.apache.lucene.queryParser.ext;
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 org.apache.lucene.util.LuceneTestCase;
21
22 /**
23  * Testcase for the {@link Extensions} class
24  */
25 public class TestExtensions extends LuceneTestCase {
26
27   private Extensions ext;
28
29   @Override
30   public void setUp() throws Exception {
31     super.setUp();
32     this.ext = new Extensions();
33   }
34
35   public void testBuildExtensionField() {
36     assertEquals("field\\:key", ext.buildExtensionField("key", "field"));
37     assertEquals("\\:key", ext.buildExtensionField("key"));
38
39     ext = new Extensions('.');
40     assertEquals("field.key", ext.buildExtensionField("key", "field"));
41     assertEquals(".key", ext.buildExtensionField("key"));
42   }
43
44   public void testSplitExtensionField() {
45     assertEquals("field\\:key", ext.buildExtensionField("key", "field"));
46     assertEquals("\\:key", ext.buildExtensionField("key"));
47
48     ext = new Extensions('.');
49     assertEquals("field.key", ext.buildExtensionField("key", "field"));
50     assertEquals(".key", ext.buildExtensionField("key"));
51   }
52
53   public void testAddGetExtension() {
54     ParserExtension extension = new ExtensionStub();
55     assertNull(ext.getExtension("foo"));
56     ext.add("foo", extension);
57     assertSame(extension, ext.getExtension("foo"));
58     ext.add("foo", null);
59     assertNull(ext.getExtension("foo"));
60   }
61
62   public void testGetExtDelimiter() {
63     assertEquals(Extensions.DEFAULT_EXTENSION_FIELD_DELIMITER, this.ext
64         .getExtensionFieldDelimiter());
65     ext = new Extensions('?');
66     assertEquals('?', this.ext.getExtensionFieldDelimiter());
67   }
68
69   public void testEscapeExtension() {
70     assertEquals("abc\\:\\?\\{\\}\\[\\]\\\\\\(\\)\\+\\-\\!\\~", ext
71         .escapeExtensionField("abc:?{}[]\\()+-!~"));
72     try {
73       ext.escapeExtensionField(null);
74       fail("should throw NPE - escape string is null");
75     } catch (NullPointerException e) {
76       // 
77     }
78   }
79 }