diff options
author | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-04-19 15:44:50 +0200 |
---|---|---|
committer | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-04-19 15:44:50 +0200 |
commit | 2895686a53a433ee6d243315ff6186de326f005f (patch) | |
tree | 033fe579d61d131f81922be264e9be941e4e8d34 /_test/cases/inc/parser/lexer.test.php | |
parent | b446308f29808c2df119fd3d79cfb9ac2e49e7ac (diff) | |
download | rpg-2895686a53a433ee6d243315ff6186de326f005f.tar.gz rpg-2895686a53a433ee6d243315ff6186de326f005f.tar.bz2 |
add unit tests for correct pattern selection when patterns contain non-captured elements (e.g. boundaries, lookaheads & lookbehinds)
darcs-hash:20090419134450-f07c6-4ff7d226fcba002c840828336e73fb89cf48e3db.gz
Diffstat (limited to '_test/cases/inc/parser/lexer.test.php')
-rw-r--r-- | _test/cases/inc/parser/lexer.test.php | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/_test/cases/inc/parser/lexer.test.php b/_test/cases/inc/parser/lexer.test.php index 75fa32ee0..cbfce9ba9 100644 --- a/_test/cases/inc/parser/lexer.test.php +++ b/_test/cases/inc/parser/lexer.test.php @@ -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(); + } + } ?> |