This project has retired. For details please refer to its Attic page.
TestParserTextSearch xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.server.support.query;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  import org.junit.After;
24  import org.junit.Before;
25  import org.junit.Test;
26  
27  public class TestParserTextSearch extends AbstractParserTest{
28  
29      //private static final Logger log = LoggerFactory.getLogger(TestParserTextSearch.class);
30  
31      @Before
32      public void setUp() {
33          super.setUp(TextSearchLexer.class, TextSearchParser.class, null, "CmisBaseLexer");
34      }
35  
36      @Override
37      @After
38      public void tearDown() {
39          super.tearDown();
40      }
41  
42      // full text search parser
43      //    OR:
44      //    <<
45      //    OR
46      //    >> OK
47      @Test
48      public void testOR1() {
49        testLexerOk("OR", "OR");
50      }
51      
52      //
53      //    TEXT_SEARCH_WORD_LIT:
54      //    <<
55      //    abc
56      //    >> OK
57      @Test
58      public void testTEXT_SEARCH_WORD_LIT2() {
59        testLexerOk("TEXT_SEARCH_WORD_LIT", "abc");
60      }
61      
62      //
63      //    <<
64      //    ab c
65      //    >> FAIL
66      @Test
67      public void testTEXT_SEARCH_WORD_LIT3() {
68          testLexerFail("TEXT_SEARCH_WORD_LIT", "ab c");
69      }
70      
71      //
72      //    <<
73      //    'abc' 
74      //    >> FAIL
75      @Test
76      public void testTEXT_SEARCH_WORD_LIT4() {
77          testLexerFail("TEXT_SEARCH_WORD_LIT", "\'abc\'");
78      }
79      
80      //
81      //    <<
82      //    ab\'c
83      //    >> OK
84      @Test
85      public void testWordLiteralWithSingleQuote() {
86          testLexerOk("TEXT_SEARCH_WORD_LIT", "ab\\'c");
87          testLexerFail("TEXT_SEARCH_WORD_LIT", "ab'c");
88      }
89      
90      //
91      //    <<
92      //    "ab\\c"
93      //    >> OK
94      @Test
95      public void testPhraseWithBackslash() {
96        testLexerOk("TEXT_SEARCH_PHRASE_STRING_LIT", "\"ab\\\\c\"");
97      }
98      
99      //
100     //    phrase:
101     //
102     //    <<
103     //    \'abc\'
104     //    >> FAIL
105     @Test
106     public void testPhrase1() {
107         testParserFail("phrase", "\\'abc\\'");
108     }
109     
110     //
111     //    <<
112     //    "abc"
113     //    >> OK
114     @Test
115     public void testPhrase2() {
116         testParserOk("phrase", "\"abc\"");
117     }
118     
119     //
120     //    <<
121     //    "'abc'"
122     //    >> OK
123     @Test
124     public void testPhrase3() {
125       testParserFail("phrase", "'abc'");
126       testParserOk("phrase", "\"\\'abc\\'\"");
127     }
128     
129     //
130     //    <<
131     //    "abc def"
132     //    >> OK
133     @Test
134     public void testPhrase4() {
135       testParserOk("phrase", "\"abc def\"");
136     }
137     
138     //
139     //    <<
140     //    "ab\\c"
141     //    >> OK
142     @Test
143     public void testPhrase6() {
144       testParserOk("phrase", "\"ab\\\\c\"");
145     }
146     
147     //
148     //    <<
149     //    "ab\c"
150     //    >> FAIL
151     @Test
152     public void testPhraseEscapedBackslash() {
153         testParserFail("phrase", "\"ab\\c\"");
154         testParserOk("phrase", "\"ab\\\\c\"");
155     }
156     
157     //
158     //    <<
159     //    "ab\\\c"
160     //    >> FAIL
161     @Test
162     public void testPhrase8() {
163         testParserFail("phrase", "\"ab\\\\\\c\"");
164     }
165     
166     //
167     //    <<
168     //    "ab\'c"
169     //    >> OK
170     @Test
171     public void testPhraseSingleQuote() {
172         assertEquals("ab'c", "ab\'c");
173         testParserOk("phrase", "\"ab\\'c\"");
174         testParserFail("phrase", "\"ab'c\""); //!!
175     }
176     
177     //
178     //    <<
179     //    "ab\-c"
180     //    >> OK
181     @Test
182     public void testPhraseHyphen() {
183         testParserOk("phrase", "\"ab\\-c\"");
184         testParserFail("phrase", "\"ab-c\"");     // !!!
185     }
186     
187     //
188     //    << 
189     //    "abc*"
190     //    "abc\*"
191     //    "abc?"
192     //    "abc\?"
193     //    >> OK
194     @Test
195     public void testPhraseWildcards() {
196       testParserOk("phrase", "\"abc*\"");
197       testParserOk("phrase", "\"abc\\*\"");
198       testParserOk("phrase", "\"abc?\"");
199       testParserOk("phrase", "\"abc\\?\"");
200     }
201 
202     //
203     //    <<
204     //    "abc def"
205     //    >> OK
206     @Test
207     public void testPhrase10() {
208       testParserOk("phrase", "\"abc def\"");
209     }
210     
211     //
212     //    <<
213     //    "\'abc\'"
214     //    >> OK
215     @Test
216     public void testPhrase11() {
217       testParserOk("phrase", "\"\\'abc\\'\"");
218     }
219     
220     //
221     //    <<
222     //    "abc AND def"
223     //    >> OK
224     @Test
225     public void testPhrase12() {
226       testParserOk("phrase", "\"abc AND def\"");
227     }
228     
229     //
230     //    << 
231     //    "AND"
232     //    >> OK
233     @Test
234     public void testPhrase13() {
235       testParserOk("phrase", "\"AND\"");
236     }
237     
238     //
239     //    word:
240     //
241     //    << 
242     //    abc
243     //    >> OK
244     @Test
245     public void testWord1() {
246       testParserOk("word", "abc");
247     }
248     
249     //
250     //    << 
251     //    312#+!&abc
252     //    >> OK
253     @Test
254     public void testWord2() {
255       testParserOk("word", "312#+!&abc");
256     }
257     
258     //
259     //    << 
260     //    \'abc\'
261     //    >> OK
262     @Test
263     public void testWord3() {
264       testParserOk("word", "\\'abc\\'");
265     }
266     
267     //
268     //    << 
269     //    'abc'
270     //    >> FAIL
271     @Test
272     public void testWord4() {
273         testParserFail("word", "'abc'");
274     }    
275     
276     //
277     //    <<
278     //    ab\-c
279     //    >> OK
280     @Test
281     public void testWord6() {
282         testParserOk("word", "ab\\-c");
283     }
284     
285     //
286     //    <<
287     //    ab\\c
288     //    >> OK
289     @Test
290     public void testWord7() {
291         testParserOk("word", "ab\\\\c");
292     }
293     
294     //
295     //    <<
296     //    ab\'c
297     //    >> OK
298     @Test
299     public void testWord8() {
300         testParserOk("word", "ab\\'c");
301     }
302     
303     //
304     //    <<
305     //    OR
306     //    >> FAIL
307     @Test
308     public void testWord9() {
309         testParserFail("word", "OR");
310     }
311     
312     //
313     //    <<
314     //    AND
315     //    >> FAIL
316     @Test
317     public void testWord10() {
318         testParserFail("word", "AND");
319     }
320     
321     //
322     //
323     //    term:
324     //
325     //    <<
326     //    -abc
327     //    >> OK
328     @Test
329     public void testWord11() {
330       testParserOk("term", "-abc");
331     }
332     
333     //
334     //    <<
335     //    abc
336     //    >> OK
337     @Test
338     public void testWord12() {
339       testParserOk("term", "abc");
340     }
341     
342     //
343     //    <<
344     //    'abc def'
345     //    >> OK
346     @Test
347     public void testWord13() {
348       testParserOk("term", "\"abc def\"");
349     }
350     
351     //
352     //    <<
353     //    -'abc def'
354     //    >> OK
355     @Test
356     public void testWord14() {
357       testParserOk("term", "-\"abc def\"");
358     }
359     
360     //
361     //    conjunct:
362     //
363     //    <<
364     //    abc def
365     //    >> OK
366     @Test
367     public void testConjunct1() {
368       testParserOk("conjunct", "abc def");
369     }
370     
371     //
372     //    <<
373     //    abc AND def
374     //    >> OK
375     @Test
376     public void testConjunct2() {
377       testParserOk("conjunct", "abc AND def");
378     }
379     
380     //
381     //    <<
382     //    abc AND def ghi John\'s
383     //    >> OK
384     @Test
385     public void testConjunct3() {
386       testParserOk("conjunct", "abc AND def ghi John\\'s");
387     }
388     
389     //
390     //    text_search_expression:
391     //
392     //    <<
393     //    cat mouse dog
394     //    >> OK
395     @Test
396     public void testTextSearchExpression1() {
397       testParserOk("text_search_expression", "cat mouse dog");
398     }
399     
400     //
401     //    <<
402     //    cat AND mouse AND dog
403     //    >> OK
404     @Test
405     public void testTextSearchExpression2() {
406       testParserOk("text_search_expression", "cat AND mouse AND dog");
407     }
408     
409     //
410     //    <<
411     //    cat OR mouse OR dog
412     //    >> OK
413     @Test
414     public void testTextSearchExpression3() {
415       testParserOk("text_search_expression", "cat OR mouse OR dog");
416     }
417     
418     //
419     //    <<
420     //    cat mouse OR dog
421     //    >> OK
422     @Test
423     public void testTextSearchExpression4() {
424       testParserOk("text_search_expression", "cat mouse OR dog");
425     }
426     
427     //
428     //    <<
429     //    cat AND mouse OR dog AND John\'s
430     //    >> OK
431     @Test
432     public void testTextSearchExpression5() {
433       testParserOk("text_search_expression", "cat AND mouse OR dog AND John\\'s");
434     }
435     
436     //
437     //    <<
438     //    "cat AND mouse"
439     //    >> OK
440     @Test
441     public void testTextSearchExpression6() {
442       testParserOk("text_search_expression", "\"cat AND mouse\"");
443     }
444     
445     //
446     //    <<
447     //    "text search expression"
448     //    >> OK
449     @Test
450     public void testTextSearchExpression7() {
451       testParserOk("text_search_expression", "\"text search expression\"");
452     }
453     
454     //
455     //    <<
456     //    "John\'s presentation"
457     //    >> OK
458     @Test
459     public void testTextSearchExpression8() {
460       testParserOk("text_search_expression", "\"John\\'s presentation\"");
461     }
462     
463     //
464     //    <<
465     //    "John\\'s presentation"
466     //    >> FAIL
467     @Test
468     public void testTextSearchExpression9() {
469         testParserFail("text_search_expression", "\"John\\\\'s presentation\"");
470     }
471     
472     //
473     //    <<
474     //    A\-1
475     //    >> OK
476     @Test
477     public void testTextSearchExpression10() {
478       testParserOk("text_search_expression", "A\\-1");
479     }
480     
481     //
482     //    <<
483     //    "c:\\My Documents"
484     //    >> OK
485     @Test
486     public void testTextSearchExpression11() {
487       testParserOk("text_search_expression", "\"c:\\\\My Documents\"");
488     }
489     
490     //
491     //    <<
492     //    "c:\\\My Documents"
493     //    >> FAIL
494     @Test
495     public void testTextSearchExpression13() {
496         testParserFail("text_search_expression", "\"c:\\\\\\My Documents\"");
497     }
498     
499     //
500     //    <<
501     //    "c:\My Documents"
502     //    >> FAIL
503     @Test
504     public void testTextSearchExpression14() {
505       testParserFail("text_search_expression", "\"c:\\My Documents\"");
506     }
507     
508     //
509     //    <<
510     //    c:\My Documents
511     //    >> FAIL
512     @Test
513     public void testTextSearchExpression15() {
514       testParserFail("text_search_expression", "c:\\My Documents");
515     }
516     
517 }