diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-10-27 18:26:53 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-10-27 18:26:53 +0100 |
| commit | 724cb02e3e7a98e58387e80c9360b420a09b3607 (patch) | |
| tree | 22585558d92d90624c666f81707c8c22a661a475 /tests/Lib/Search/QueryParserTest.php | |
| parent | 16bb2f544c636425ed9e6bff90654b8fa3c0f2e3 (diff) | |
| download | grauphel-724cb02e3e7a98e58387e80c9360b420a09b3607.tar.gz grauphel-724cb02e3e7a98e58387e80c9360b420a09b3607.zip | |
new search query parser; support for NOT
Diffstat (limited to 'tests/Lib/Search/QueryParserTest.php')
| -rw-r--r-- | tests/Lib/Search/QueryParserTest.php | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/Lib/Search/QueryParserTest.php b/tests/Lib/Search/QueryParserTest.php new file mode 100644 index 0000000..122138f --- /dev/null +++ b/tests/Lib/Search/QueryParserTest.php @@ -0,0 +1,92 @@ +<?php +require_once __DIR__ . '/../../../lib/search/queryparser.php'; + +use OCA\Grauphel\Search\Queryparser; + +class Lib_Search_QueryParserTest extends PHPUnit_Framework_TestCase +{ + public function testParseSimple() + { + $qp = new QueryParser(); + $this->assertEquals( + array('AND' => array('foo')), + $qp->parse('foo') + ); + + $this->assertEquals( + array('AND' => array('foo', 'bar')), + $qp->parse('foo bar') + ); + } + + public function testParseQuotes() + { + $qp = new QueryParser(); + $this->assertEquals( + array('AND' => array('foo bar')), + $qp->parse('"foo bar"') + ); + + $this->assertEquals( + array('AND' => array('foo bar', 'baz')), + $qp->parse('"foo bar" baz') + ); + + $this->assertEquals( + array('AND' => array('foo \'bar\' baz', 'bat')), + $qp->parse('"foo \'bar\' baz" bat') + ); + + $this->assertEquals( + array('AND' => array('foo bar baz')), + $qp->parse('"foo bar baz"') + ); + + $this->assertEquals( + array('AND' => array('one two three', 'four', 'five six', 'seven')), + $qp->parse('"one two three" four "five six" seven') + ); + } + + public function testParseWhitespace() + { + $qp = new QueryParser(); + $this->assertEquals( + array('AND' => array('foo')), + $qp->parse(' foo ') + ); + + $this->assertEquals( + array('AND' => array('foo', 'bar')), + $qp->parse(' foo bar ') + ); + + $this->assertEquals( + array('AND' => array('foo ', ' bar')), + $qp->parse(' "foo " " bar" ') + ); + } + + public function testParseNot() + { + $qp = new QueryParser(); + $this->assertEquals( + array('AND' => array('foo')), + $qp->parse('+foo') + ); + + $this->assertEquals( + array('AND' => array('foo'), 'NOT' => array('bar')), + $qp->parse('+foo -bar') + ); + + $this->assertEquals( + array( + 'AND' => array('foo', 'bat'), + 'NOT' => array('bar baz') + ), + $qp->parse('+foo -"bar baz" +bat') + ); + } +} +?> |
