Skip to content

Commit

Permalink
split out parser modes into their own files
Browse files Browse the repository at this point in the history
This moves all the parser classes into their own namespace and files.
Next up are the handler classes.

I'm not sure about the namespace, yet. A nested namepspace Parser\Modes
would probably make more sense... we'll see.

This also removes the duplicated coded in the Plugin mode. We now use
the plugin trait and can inherit from AbstractMode instead.
  • Loading branch information
splitbrain committed Apr 28, 2018
1 parent de36992 commit 36dc94b
Show file tree
Hide file tree
Showing 52 changed files with 1,532 additions and 1,124 deletions.
5 changes: 4 additions & 1 deletion _test/tests/inc/parser/parser_code.test.php
@@ -1,4 +1,7 @@
<?php

use dokuwiki\ParserMode\Code;

require_once 'parser.inc.php';

/**
Expand All @@ -10,7 +13,7 @@ class TestOfDoku_Parser_Code extends TestOfDoku_Parser {

function setUp() {
parent::setUp();
$this->P->addMode('code',new Doku_Parser_Mode_Code());
$this->P->addMode('code',new Code());
}

function testCode() {
Expand Down
18 changes: 11 additions & 7 deletions _test/tests/inc/parser/parser_eol.test.php
@@ -1,10 +1,14 @@
<?php

use dokuwiki\ParserMode\Eol;
use dokuwiki\ParserMode\Linebreak;

require_once 'parser.inc.php';

class TestOfDoku_Parser_Eol extends TestOfDoku_Parser {

function testEol() {
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('eol',new Eol());
$this->P->parse("Foo\nBar");
$calls = array (
array('document_start',array()),
Expand All @@ -17,7 +21,7 @@ function testEol() {
}

function testEolMultiple() {
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('eol',new Eol());
$this->P->parse("Foo\n\nbar\nFoo");
$calls = array (
array('document_start',array()),
Expand All @@ -33,7 +37,7 @@ function testEolMultiple() {
}

function testWinEol() {
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('eol',new Eol());
$this->P->parse("Foo\r\nBar");
$calls = array (
array('document_start',array()),
Expand All @@ -46,7 +50,7 @@ function testWinEol() {
}

function testLinebreak() {
$this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak());
$this->P->addMode('linebreak',new Linebreak());
$this->P->parse('Foo\\\\ Bar');
$calls = array (
array('document_start',array()),
Expand All @@ -61,8 +65,8 @@ function testLinebreak() {
}

function testLinebreakPlusEol() {
$this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak());
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('linebreak',new Linebreak());
$this->P->addMode('eol',new Eol());
$this->P->parse('Foo\\\\'."\n\n".'Bar');

$calls = array (
Expand All @@ -80,7 +84,7 @@ function testLinebreakPlusEol() {
}

function testLinebreakInvalid() {
$this->P->addMode('linebreak',new Doku_Parser_Mode_Linebreak());
$this->P->addMode('linebreak',new Linebreak());
$this->P->parse('Foo\\\\Bar');
$calls = array (
array('document_start',array()),
Expand Down
5 changes: 4 additions & 1 deletion _test/tests/inc/parser/parser_file.test.php
@@ -1,11 +1,14 @@
<?php

use dokuwiki\ParserMode\File;

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());
$this->P->addMode('file',new File());
}

function testFile() {
Expand Down
42 changes: 27 additions & 15 deletions _test/tests/inc/parser/parser_footnote.test.php
@@ -1,11 +1,23 @@
<?php

use dokuwiki\ParserMode\Code;
use dokuwiki\ParserMode\Eol;
use dokuwiki\ParserMode\Footnote;
use dokuwiki\ParserMode\Formatting;
use dokuwiki\ParserMode\Hr;
use dokuwiki\ParserMode\Listblock;
use dokuwiki\ParserMode\Preformatted;
use dokuwiki\ParserMode\Quote;
use dokuwiki\ParserMode\Table;
use dokuwiki\ParserMode\Unformatted;

require_once 'parser.inc.php';

class TestOfDoku_Parser_Footnote extends TestOfDoku_Parser {

function setUp() {
parent::setUp();
$this->P->addMode('footnote',new Doku_Parser_Mode_Footnote());
$this->P->addMode('footnote',new Footnote());
}

function testFootnote() {
Expand Down Expand Up @@ -39,7 +51,7 @@ function testNotAFootnote() {
}

function testFootnoteLinefeed() {
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('eol',new Eol());
$this->P->parse("Foo (( testing\ntesting )) Bar");
$calls = array (
array('document_start',array()),
Expand Down Expand Up @@ -76,7 +88,7 @@ function testFootnoteNested() {
}

function testFootnoteEol() {
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('eol',new Eol());
$this->P->parse("Foo \nX(( test\ning ))Y\n Bar");
$calls = array (
array('document_start',array()),
Expand All @@ -95,7 +107,7 @@ function testFootnoteEol() {
}

function testFootnoteStrong() {
$this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong'));
$this->P->addMode('strong',new Formatting('strong'));
$this->P->parse('Foo (( **testing** )) Bar');
$calls = array (
array('document_start',array()),
Expand All @@ -118,7 +130,7 @@ function testFootnoteStrong() {
}

function testFootnoteHr() {
$this->P->addMode('hr',new Doku_Parser_Mode_HR());
$this->P->addMode('hr',new Hr());
$this->P->parse("Foo (( \n ---- \n )) Bar");
$calls = array (
array('document_start',array()),
Expand All @@ -139,7 +151,7 @@ function testFootnoteHr() {
}

function testFootnoteCode() {
$this->P->addMode('code',new Doku_Parser_Mode_Code());
$this->P->addMode('code',new Code());
$this->P->parse("Foo (( <code>Test</code> )) Bar");
$calls = array (
array('document_start',array()),
Expand All @@ -160,7 +172,7 @@ function testFootnoteCode() {
}

function testFootnotePreformatted() {
$this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
$this->P->addMode('preformatted',new Preformatted());
$this->P->parse("Foo (( \n Test\n )) Bar");
$calls = array (
array('document_start',array()),
Expand All @@ -181,8 +193,8 @@ function testFootnotePreformatted() {
}

function testFootnotePreformattedEol() {
$this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('preformatted',new Preformatted());
$this->P->addMode('eol',new Eol());
$this->P->parse("Foo (( \n Test\n )) Bar");
$calls = array (
array('document_start',array()),
Expand All @@ -204,7 +216,7 @@ function testFootnotePreformattedEol() {
}

function testFootnoteUnformatted() {
$this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted());
$this->P->addMode('unformatted',new Unformatted());
$this->P->parse("Foo (( <nowiki>Test</nowiki> )) Bar");
$calls = array (
array('document_start',array()),
Expand All @@ -225,7 +237,7 @@ function testFootnoteUnformatted() {
}

function testFootnoteNotHeader() {
$this->P->addMode('unformatted',new Doku_Parser_Mode_Unformatted());
$this->P->addMode('unformatted',new Unformatted());
$this->P->parse("Foo (( \n====Test====\n )) Bar");
$calls = array (
array('document_start',array()),
Expand All @@ -244,7 +256,7 @@ function testFootnoteNotHeader() {
}

function testFootnoteTable() {
$this->P->addMode('table',new Doku_Parser_Mode_Table());
$this->P->addMode('table',new Table());
$this->P->parse("Foo ((
| Row 0 Col 1 | Row 0 Col 2 | Row 0 Col 3 |
| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 |
Expand Down Expand Up @@ -290,7 +302,7 @@ function testFootnoteTable() {
}

function testFootnoteList() {
$this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock());
$this->P->addMode('listblock',new ListBlock());
$this->P->parse("Foo ((
*A
* B
Expand Down Expand Up @@ -332,7 +344,7 @@ function testFootnoteList() {
}

function testFootnoteQuote() {
$this->P->addMode('quote',new Doku_Parser_Mode_Quote());
$this->P->addMode('quote',new Quote());
$this->P->parse("Foo ((
> def
>>ghi
Expand Down Expand Up @@ -361,7 +373,7 @@ function testFootnoteQuote() {
}

function testFootnoteNesting() {
$this->P->addMode('strong',new Doku_Parser_Mode_Formatting('strong'));
$this->P->addMode('strong',new Formatting('strong'));
$this->P->parse("(( a ** (( b )) ** c ))");

$calls = array(
Expand Down
36 changes: 20 additions & 16 deletions _test/tests/inc/parser/parser_headers.test.php
@@ -1,10 +1,14 @@
<?php

use dokuwiki\ParserMode\Eol;
use dokuwiki\ParserMode\Header;

require_once 'parser.inc.php';

class TestOfDoku_Parser_Headers extends TestOfDoku_Parser {

function testHeader1() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n ====== Header ====== \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -23,7 +27,7 @@ function testHeader1() {
}

function testHeader2() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n ===== Header ===== \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -42,7 +46,7 @@ function testHeader2() {
}

function testHeader3() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n ==== Header ==== \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -61,7 +65,7 @@ function testHeader3() {
}

function testHeader4() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n === Header === \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -80,7 +84,7 @@ function testHeader4() {
}

function testHeader5() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n == Header == \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -99,7 +103,7 @@ function testHeader5() {
}

function testHeader2UnevenSmaller() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n ===== Header == \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -118,7 +122,7 @@ function testHeader2UnevenSmaller() {
}

function testHeader2UnevenBigger() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n ===== Header =========== \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -137,7 +141,7 @@ function testHeader2UnevenBigger() {
}

function testHeaderLarge() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n ======= Header ======= \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -156,7 +160,7 @@ function testHeaderLarge() {
}

function testHeaderSmall() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n= Header =\n def");
$calls = array (
array('document_start',array()),
Expand All @@ -170,7 +174,7 @@ function testHeaderSmall() {


function testHeader1Mixed() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n====== == Header == ======\n def");
$calls = array (
array('document_start',array()),
Expand All @@ -189,7 +193,7 @@ function testHeader1Mixed() {
}

function testHeader5Mixed() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n== ====== Header ====== ==\n def");
$calls = array (
array('document_start',array()),
Expand All @@ -208,7 +212,7 @@ function testHeader5Mixed() {
}

function testHeaderMultiline() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n== ====== Header\n ====== ==\n def");
$calls = array (
array('document_start',array()),
Expand All @@ -227,14 +231,14 @@ function testHeaderMultiline() {
}

# function testNoToc() {
# $this->P->addMode('notoc',new Doku_Parser_Mode_NoToc());
# $this->P->addMode('notoc',new NoToc());
# $this->P->parse('abc ~~NOTOC~~ def');
# $this->assertFalse($this->H->meta['toc']);
# }

function testHeader1Eol() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('eol',new Doku_Parser_Mode_Eol());
$this->P->addMode('header',new Header());
$this->P->addMode('eol',new Eol());
$this->P->parse("abc \n ====== Header ====== \n def");
$calls = array (
array('document_start',array()),
Expand All @@ -254,7 +258,7 @@ function testHeader1Eol() {
}

function testHeaderMulti2() {
$this->P->addMode('header',new Doku_Parser_Mode_Header());
$this->P->addMode('header',new Header());
$this->P->parse("abc \n ====== Header ====== \n def abc \n ===== Header2 ===== \n def");
$calls = array (
array('document_start',array()),
Expand Down

0 comments on commit 36dc94b

Please sign in to comment.