summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/tests/inc/parser/parser_code.test.php72
-rw-r--r--_test/tests/inc/parser/parser_file.test.php56
-rw-r--r--inc/parser/parser.php4
3 files changed, 130 insertions, 2 deletions
diff --git a/_test/tests/inc/parser/parser_code.test.php b/_test/tests/inc/parser/parser_code.test.php
new file mode 100644
index 000000000..c50d2d328
--- /dev/null
+++ b/_test/tests/inc/parser/parser_code.test.php
@@ -0,0 +1,72 @@
+<?php
+require_once 'parser.inc.php';
+
+class TestOfDoku_Parser_Code extends TestOfDoku_Parser {
+
+ function setUp() {
+ parent::setUp();
+ $this->P->addMode('code',new Doku_Parser_Mode_Code());
+ }
+
+ function testCode() {
+ $this->P->parse('Foo <code>Test</code> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('code',array('Test',null,null)),
+ array('p_open',array()),
+ array('cdata',array(' Bar')),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testCodeBash() {
+ $this->P->parse('Foo <code bash>Test</code> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('code',array('Test','bash',null)),
+ array('p_open',array()),
+ array('cdata',array(' Bar')),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testCodeDownload() {
+ $this->P->parse('Foo <code bash script.sh>Test</code> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('code',array('Test','bash','script.sh')),
+ array('p_open',array()),
+ array('cdata',array(' Bar')),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testCodeToken() {
+ $this->P->parse('Foo <code2>Bar</code2><code>Test</code>');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo <code2>Bar</code2>')),
+ array('p_close',array()),
+ array('code',array('Test',null,null)),
+ array('document_end',array()),
+ );
+ $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+}
+
diff --git a/_test/tests/inc/parser/parser_file.test.php b/_test/tests/inc/parser/parser_file.test.php
new file mode 100644
index 000000000..39bda8a58
--- /dev/null
+++ b/_test/tests/inc/parser/parser_file.test.php
@@ -0,0 +1,56 @@
+<?php
+require_once 'parser.inc.php';
+
+class TestOfDoku_Parser_File extends TestOfDoku_Parser {
+
+ function setUp() {
+ parent::setUp();
+ $this->P->addMode('file',new Doku_Parser_Mode_File());
+ }
+
+ function testFile() {
+ $this->P->parse('Foo <file>Test</file> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('file',array('Test',null,null)),
+ array('p_open',array()),
+ array('cdata',array(' Bar')),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testFileHighlightDownload() {
+ $this->P->parse('Foo <file txt test.txt>Test</file> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('file',array('Test','txt','test.txt')),
+ array('p_open',array()),
+ array('cdata',array(' Bar')),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testFileToken() {
+ $this->P->parse('Foo <file2>Test</file2> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo <file2>Test</file2> Bar')),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+}
+
diff --git a/inc/parser/parser.php b/inc/parser/parser.php
index 6aef3fda5..4af1cd333 100644
--- a/inc/parser/parser.php
+++ b/inc/parser/parser.php
@@ -555,7 +555,7 @@ class Doku_Parser_Mode_preformatted extends Doku_Parser_Mode {
class Doku_Parser_Mode_code extends Doku_Parser_Mode {
function connectTo($mode) {
- $this->Lexer->addEntryPattern('<code(?=.*</code>)',$mode,'code');
+ $this->Lexer->addEntryPattern('<code\b(?=.*</code>)',$mode,'code');
}
function postConnect() {
@@ -571,7 +571,7 @@ class Doku_Parser_Mode_code extends Doku_Parser_Mode {
class Doku_Parser_Mode_file extends Doku_Parser_Mode {
function connectTo($mode) {
- $this->Lexer->addEntryPattern('<file(?=.*</file>)',$mode,'file');
+ $this->Lexer->addEntryPattern('<file\b(?=.*</file>)',$mode,'file');
}
function postConnect() {