Skip to content
Snippets Groups Projects
Commit 2895686a authored by Chris Smith's avatar Chris Smith
Browse files

add unit tests for correct pattern selection when patterns contain...

add unit tests for correct pattern selection when patterns contain non-captured elements (e.g. boundaries, lookaheads & lookbehinds)

darcs-hash:20090419134450-f07c6-4ff7d226fcba002c840828336e73fb89cf48e3db.gz
parent b446308f
No related branches found
No related tags found
No related merge requests found
......@@ -446,7 +446,7 @@ class TestOfLexerByteIndices extends UnitTestCase {
$handler->expectCallCount("caught", 5);
$lexer = &new Doku_Lexer($handler, "ignore");
$lexer->addEntryPattern('<file>(?=.*\x3C/file\x3E)', "ignore", "caught");
$lexer->addEntryPattern('<file>(?=.*</file>)', "ignore", "caught");
$lexer->addExitPattern("</file>", "caught");
$lexer->addSpecialPattern('b','caught','special');
$lexer->mapHandler('special','caught');
......@@ -590,7 +590,36 @@ class TestOfLexerByteIndices extends UnitTestCase {
$this->assertTrue($lexer->parse($doc));
$handler->tally();
}
/**
* This test is primarily to ensure the correct match is chosen
* when there are non-captured elements in the pattern.
*/
function testIndexSelectCorrectMatch() {
$doc = "ALL FOOLS ARE FOO";
$pattern = '\bFOO\b';
$handler = &new MockTestParserByteIndex($this);
$handler->setReturnValue("ignore", true);
$handler->setReturnValue("caught", true);
$matches = array();
preg_match('/'.$pattern.'/',$doc,$matches,PREG_OFFSET_CAPTURE);
$handler->expectArgumentsAt(
0,
"caught",
array("FOO", DOKU_LEXER_SPECIAL, $matches[0][1])
);
$handler->expectCallCount("caught", 1);
$lexer = &new Doku_Lexer($handler, "ignore");
$lexer->addSpecialPattern($pattern,'ignore','caught');
$this->assertTrue($lexer->parse($doc));
$handler->tally();
}
}
?>
......@@ -14,6 +14,7 @@ require_once DOKU_INC . 'inc/parser/parser.php';
require_once DOKU_INC . 'inc/parser/handler.php';
require_once DOKU_INC . 'inc/events.php';
require_once DOKU_INC . 'inc/mail.php';
//require_once DOKU . 'parser/renderer.php';
//Mock::generate('Doku_Renderer');
......
......@@ -40,6 +40,23 @@ class TestOfDoku_Parser_Replacements extends TestOfDoku_Parser {
$this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
}
function testPickAcronymCorrectly() {
$this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOO')));
$this->P->parse('ALL FOOLS ARE FOO');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'ALL FOOLS ARE ')),
array('acronym',array('FOO')),
array('cdata',array("\n")),
array('p_close',array()),
array('document_end',array()),
);
$this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
}
function testMultipleAcronyms() {
$this->P->addMode('acronym',new Doku_Parser_Mode_Acronym(array('FOO','BAR')));
$this->P->parse('abc FOO def BAR xyz');
......
......@@ -136,10 +136,9 @@ class Doku_LexerParallelRegex {
}
$idx = count($matches)-2;
list($pre, $post) = preg_split($this->_patterns[$idx].$this->_getPerlMatchingFlags(), $subject, 2);
$split = array($pre, $matches[0], $post);
return isset($this->_labels[$idx]) ? $this->_labels[$idx] : true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment