1 package org.apache.lucene.queryParser.ext;
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 org.apache.lucene.util.LuceneTestCase;
23 * Testcase for the {@link Extensions} class
25 public class TestExtensions extends LuceneTestCase {
27 private Extensions ext;
30 public void setUp() throws Exception {
32 this.ext = new Extensions();
35 public void testBuildExtensionField() {
36 assertEquals("field\\:key", ext.buildExtensionField("key", "field"));
37 assertEquals("\\:key", ext.buildExtensionField("key"));
39 ext = new Extensions('.');
40 assertEquals("field.key", ext.buildExtensionField("key", "field"));
41 assertEquals(".key", ext.buildExtensionField("key"));
44 public void testSplitExtensionField() {
45 assertEquals("field\\:key", ext.buildExtensionField("key", "field"));
46 assertEquals("\\:key", ext.buildExtensionField("key"));
48 ext = new Extensions('.');
49 assertEquals("field.key", ext.buildExtensionField("key", "field"));
50 assertEquals(".key", ext.buildExtensionField("key"));
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"));
59 assertNull(ext.getExtension("foo"));
62 public void testGetExtDelimiter() {
63 assertEquals(Extensions.DEFAULT_EXTENSION_FIELD_DELIMITER, this.ext
64 .getExtensionFieldDelimiter());
65 ext = new Extensions('?');
66 assertEquals('?', this.ext.getExtensionFieldDelimiter());
69 public void testEscapeExtension() {
70 assertEquals("abc\\:\\?\\{\\}\\[\\]\\\\\\(\\)\\+\\-\\!\\~", ext
71 .escapeExtensionField("abc:?{}[]\\()+-!~"));
73 ext.escapeExtensionField(null);
74 fail("should throw NPE - escape string is null");
75 } catch (NullPointerException e) {