Beispiel #1
0
 function parse($doc)
 {
     if ($this->Lexer) {
         $this->connectModes();
         // Normalize CRs and pad doc
         $doc = "\n" . str_replace("\r\n", "\n", $doc) . "\n";
         $this->Lexer->parse($doc);
         $this->Handler->_finalize();
         return $this->Handler->calls;
     } else {
         return false;
     }
 }
Beispiel #2
0
 /**
  * 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 = $this->getMock('TestParserByteIndex');
     $handler->expects($this->any())->method('ignore')->will($this->returnValue(true));
     $matches = array();
     preg_match('/' . $pattern . '/', $doc, $matches, PREG_OFFSET_CAPTURE);
     $handler->expects($this->once())->method('caught')->with("FOO", DOKU_LEXER_SPECIAL, $matches[0][1])->will($this->returnValue(true));
     $lexer = new Doku_Lexer($handler, "ignore");
     $lexer->addSpecialPattern($pattern, 'ignore', 'caught');
     $this->assertTrue($lexer->parse($doc));
 }
Beispiel #3
0
 /**
  * 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();
 }