xref: /dokuwiki/_test/tests/inc/parser/parser_code.test.php (revision f2bbf30b71b15efa7a918944b4ffc74f8b1747a9)
1*f2bbf30bSGuy Brand<?php
2*f2bbf30bSGuy Brandrequire_once 'parser.inc.php';
3*f2bbf30bSGuy Brand
4*f2bbf30bSGuy Brandclass TestOfDoku_Parser_Code extends TestOfDoku_Parser {
5*f2bbf30bSGuy Brand
6*f2bbf30bSGuy Brand    function setUp() {
7*f2bbf30bSGuy Brand        parent::setUp();
8*f2bbf30bSGuy Brand        $this->P->addMode('code',new Doku_Parser_Mode_Code());
9*f2bbf30bSGuy Brand    }
10*f2bbf30bSGuy Brand
11*f2bbf30bSGuy Brand    function testCode() {
12*f2bbf30bSGuy Brand        $this->P->parse('Foo <code>Test</code> Bar');
13*f2bbf30bSGuy Brand        $calls = array (
14*f2bbf30bSGuy Brand            array('document_start',array()),
15*f2bbf30bSGuy Brand            array('p_open',array()),
16*f2bbf30bSGuy Brand            array('cdata',array("\n".'Foo ')),
17*f2bbf30bSGuy Brand            array('p_close',array()),
18*f2bbf30bSGuy Brand            array('code',array('Test',null,null)),
19*f2bbf30bSGuy Brand            array('p_open',array()),
20*f2bbf30bSGuy Brand            array('cdata',array(' Bar')),
21*f2bbf30bSGuy Brand            array('p_close',array()),
22*f2bbf30bSGuy Brand            array('document_end',array()),
23*f2bbf30bSGuy Brand        );
24*f2bbf30bSGuy Brand        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
25*f2bbf30bSGuy Brand    }
26*f2bbf30bSGuy Brand
27*f2bbf30bSGuy Brand    function testCodeBash() {
28*f2bbf30bSGuy Brand        $this->P->parse('Foo <code bash>Test</code> Bar');
29*f2bbf30bSGuy Brand        $calls = array (
30*f2bbf30bSGuy Brand            array('document_start',array()),
31*f2bbf30bSGuy Brand            array('p_open',array()),
32*f2bbf30bSGuy Brand            array('cdata',array("\n".'Foo ')),
33*f2bbf30bSGuy Brand            array('p_close',array()),
34*f2bbf30bSGuy Brand            array('code',array('Test','bash',null)),
35*f2bbf30bSGuy Brand            array('p_open',array()),
36*f2bbf30bSGuy Brand            array('cdata',array(' Bar')),
37*f2bbf30bSGuy Brand            array('p_close',array()),
38*f2bbf30bSGuy Brand            array('document_end',array()),
39*f2bbf30bSGuy Brand        );
40*f2bbf30bSGuy Brand        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
41*f2bbf30bSGuy Brand    }
42*f2bbf30bSGuy Brand
43*f2bbf30bSGuy Brand    function testCodeToken() {
44*f2bbf30bSGuy Brand        $this->P->parse('Foo <code2>Bar</code2><code>Test</code>');
45*f2bbf30bSGuy Brand        $calls = array (
46*f2bbf30bSGuy Brand            array('document_start',array()),
47*f2bbf30bSGuy Brand            array('p_open',array()),
48*f2bbf30bSGuy Brand            array('cdata',array("\n".'Foo <code2>Bar</code2>')),
49*f2bbf30bSGuy Brand            array('p_close',array()),
50*f2bbf30bSGuy Brand            array('code',array('Test',null,null)),
51*f2bbf30bSGuy Brand            array('document_end',array()),
52*f2bbf30bSGuy Brand        );
53*f2bbf30bSGuy Brand        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
54*f2bbf30bSGuy Brand    }
55*f2bbf30bSGuy Brand}
56*f2bbf30bSGuy Brand
57