Skip to content
This repository has been archived by the owner on Jan 20, 2020. It is now read-only.

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Funivan committed Dec 19, 2013
1 parent f9f48ff commit 5776217
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Fiv/Tokenizer/Query/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class Base {
protected $cache = null;


public function __construct($collection = null) {
public function __construct(Tokenizer\Collection $collection = null) {
$this->collection = $collection;
}

Expand Down
7 changes: 1 addition & 6 deletions src/Fiv/Tokenizer/Query/Extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ protected function parse() {
# У нас є 2 або більше умов
# І на останню умову немає токена.
# Все цикл завершується.
// @todo Перевірити вихід із цикла, якщо остання умова possible
if (!is_object($token)) {
$lastTokenIndex = false;
break;
Expand Down Expand Up @@ -343,11 +342,7 @@ protected function parse() {
*/
protected function addQuery(Query $query, $type, $options = []) {

if (!in_array($type, [static::STRICT, static::POSSIBLE, static::EXPECT, static::SEARCH, static::SECTION])) {
throw new \Fiv\Tokenizer\Exception('Invalid condition type: ' . $type);
}

$this->cleanCache();
$this->cleanCache();

$this->queries[] = [$query, $type, $options];

Expand Down
48 changes: 48 additions & 0 deletions tests/Tests/Tokenizer/Query/ExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,52 @@ public function testExpectResult() {
$this->assertEquals('echo 1+5*9', $code);
}

public function testExpectFail() {
$file = $this->initFileWithCode('<?php
echo 1+5*9; echo 2+4
');
$q = $file->getCollection()->extendedQuery();
$q->strict()->valueIs('echo');
$q->expect()->typeIs(T_WHITESPACE);

$this->assertCount(0, $q->getBlock());
}

public function testSectionFail() {
$file = $this->initFileWithCode('<?php
function(){}
function (){}
');
$q = $file->getCollection()->extendedQuery();
$q->strict()->valueIs('function');
$q->section('(', ')');

$this->assertCount(2, $q->getBlock());
}

public function testMoreQueriesThanTokens() {
$file = $this->initFileWithCode('<?php
echo
');
$q = $file->getCollection()->extendedQuery();
$q->strict()->valueLike('!.+!');
$q->strict()->typeIs(T_WHITESPACE);
$q->strict()->typeIs(T_ECHO);
$q->strict()->typeIs(T_WHITESPACE);
$q->strict()->valueLike('!.+!');

$this->assertCount(0, $q->getBlock());

$file = $this->initFileWithCode('<?php
echo 1;
echo');
$q = $file->getCollection()->extendedQuery();
$q->strict()->typeIs(T_ECHO);
$q->strict()->typeIs(T_WHITESPACE);
$q->strict()->valueLike('!.+!');

$this->assertCount(1, $q->getBlock());

}

}
8 changes: 8 additions & 0 deletions tests/Tests/Tokenizer/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public function testGetData() {
unlink($file->getPath());
}

public function testToString() {
$file = $this->initFileWithCode('<?php echo 1');
$firstToken = $file->getCollection()->getFirst();

$this->assertEquals('<?php ', (string)$firstToken);

}

}

0 comments on commit 5776217

Please sign in to comment.