From f2bbf30b71b15efa7a918944b4ffc74f8b1747a9 Mon Sep 17 00:00:00 2001
From: Guy Brand <gb@unistra.fr>
Date: Wed, 31 Jul 2013 11:38:44 +0200
Subject: [PATCH] Simple test cases for code and file token fix

---
 _test/tests/inc/parser/parser_code.test.php | 56 +++++++++++++++++++++
 _test/tests/inc/parser/parser_file.test.php | 28 +++++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 _test/tests/inc/parser/parser_code.test.php
 create mode 100644 _test/tests/inc/parser/parser_file.test.php

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..4f89b4826
--- /dev/null
+++ b/_test/tests/inc/parser/parser_code.test.php
@@ -0,0 +1,56 @@
+<?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 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..924b00382
--- /dev/null
+++ b/_test/tests/inc/parser/parser_file.test.php
@@ -0,0 +1,28 @@
+<?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);
+    }
+
+}
+
-- 
GitLab