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

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