Support phpunit 7, let travis test PHP 7.2 and 7.1
[grauphel.git] / tests / Lib / Search / QueryParserTest.php
1 <?php
2 require_once __DIR__ . '/../../../lib/search/queryparser.php';
3
4 use OCA\Grauphel\Search\Queryparser;
5
6 class Lib_Search_QueryParserTest extends \PHPUnit\Framework\TestCase
7 {
8     public function testParseSimple()
9     {
10         $qp = new QueryParser();
11         $this->assertEquals(
12             array('AND' => array('foo')),
13             $qp->parse('foo')
14         );
15
16         $this->assertEquals(
17             array('AND' => array('foo', 'bar')),
18             $qp->parse('foo bar')
19         );
20     }
21
22     public function testParseQuotes()
23     {
24         $qp = new QueryParser();
25         $this->assertEquals(
26             array('AND' => array('foo bar')),
27             $qp->parse('"foo bar"')
28         );
29
30         $this->assertEquals(
31             array('AND' => array('foo bar', 'baz')),
32             $qp->parse('"foo bar" baz')
33         );
34
35         $this->assertEquals(
36             array('AND' => array('foo \'bar\' baz', 'bat')),
37             $qp->parse('"foo \'bar\' baz" bat')
38         );
39
40         $this->assertEquals(
41             array('AND' => array('foo bar baz')),
42             $qp->parse('"foo bar baz"')
43         );
44
45         $this->assertEquals(
46             array('AND' => array('one two three', 'four', 'five six', 'seven')),
47             $qp->parse('"one two three" four "five six" seven')
48         );
49     }
50
51     public function testParseWhitespace()
52     {
53         $qp = new QueryParser();
54         $this->assertEquals(
55             array('AND' => array('foo')),
56             $qp->parse(' foo ')
57         );
58
59         $this->assertEquals(
60             array('AND' => array('foo', 'bar')),
61             $qp->parse(' foo    bar ')
62         );
63
64         $this->assertEquals(
65             array('AND' => array('foo ', '  bar')),
66             $qp->parse(' "foo " "  bar" ')
67         );
68     }
69
70     public function testParseNot()
71     {
72         $qp = new QueryParser();
73         $this->assertEquals(
74             array('AND' => array('foo')),
75             $qp->parse('+foo')
76         );
77
78         $this->assertEquals(
79             array('AND' => array('foo'), 'NOT' => array('bar')),
80             $qp->parse('+foo -bar')
81         );
82
83         $this->assertEquals(
84             array(
85                 'AND' => array('foo', 'bat'),
86                 'NOT' => array('bar baz')
87             ),
88             $qp->parse('+foo -"bar baz" +bat')
89         );
90     }
91 }
92 ?>