blob: 5508c2a73a71c94287a3427e7ec3701a6c3dfb42 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.rewrite;
import static org.junit.Assert.*;
import org.junit.Test;
import com.yahoo.prelude.query.AndItem;
import com.yahoo.prelude.query.CompositeItem;
import com.yahoo.prelude.query.Item;
import com.yahoo.prelude.query.parser.SpecialTokenRegistry;
import com.yahoo.search.Query;
import com.yahoo.search.searchchain.Execution;
import com.yahoo.search.searchchain.Execution.Context;
import com.yahoo.vespa.configdefinition.SpecialtokensConfig;
import com.yahoo.vespa.configdefinition.SpecialtokensConfig.Tokenlist;
import com.yahoo.vespa.configdefinition.SpecialtokensConfig.Tokenlist.Tokens;
/**
* Fine grained testing of RewriterFeatures for easier testing of innards.
*/
public class RewriterFeaturesTestCase {
private static final String ASCII_ELLIPSIS = "...";
@Test
public final void testConvertStringToQTree() {
Execution placeholder = new Execution(Context.createContextStub());
SpecialTokenRegistry tokenRegistry = new SpecialTokenRegistry(
new SpecialtokensConfig(
new SpecialtokensConfig.Builder()
.tokenlist(new Tokenlist.Builder().name(
"default").tokens(
new Tokens.Builder().token(ASCII_ELLIPSIS)))));
placeholder.context().setTokenRegistry(tokenRegistry);
Query query = new Query();
query.getModel().setExecution(placeholder);
Item parsed = RewriterFeatures.convertStringToQTree(query, "a b c "
+ ASCII_ELLIPSIS);
assertSame(AndItem.class, parsed.getClass());
assertEquals(4, ((CompositeItem) parsed).getItemCount());
assertEquals(ASCII_ELLIPSIS, ((CompositeItem) parsed).getItem(3).toString());
}
}
|