summaryrefslogtreecommitdiff
path: root/inc/parser/tests/parser_preformatted.test.php
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-04-03 09:45:21 +0200
committerandi <andi@splitbrain.org>2005-04-03 09:45:21 +0200
commit3ae0dd35df72193095029d06f5459b5243430140 (patch)
treeee4a1c86f3d881bd3656df2e5a292f57e9cc23c2 /inc/parser/tests/parser_preformatted.test.php
parent0e1c636e20bd809a1d388e0c6f630b0ecda7086b (diff)
downloadrpg-3ae0dd35df72193095029d06f5459b5243430140.tar.gz
rpg-3ae0dd35df72193095029d06f5459b5243430140.tar.bz2
added unit tests
darcs-hash:20050403074521-9977f-d1a3c3a1200cab2d28789490ab3b49cd48691688.gz
Diffstat (limited to 'inc/parser/tests/parser_preformatted.test.php')
-rw-r--r--inc/parser/tests/parser_preformatted.test.php244
1 files changed, 244 insertions, 0 deletions
diff --git a/inc/parser/tests/parser_preformatted.test.php b/inc/parser/tests/parser_preformatted.test.php
new file mode 100644
index 000000000..2b5746216
--- /dev/null
+++ b/inc/parser/tests/parser_preformatted.test.php
@@ -0,0 +1,244 @@
+<?php
+require_once 'parser.test.php';
+
+class TestOfDoku_Parser_Preformatted extends TestOfDoku_Parser {
+
+ function TestOfDoku_Parser_Preformatted() {
+ $this->UnitTestCase('TestOfDoku_Parser_Preformatted');
+ }
+
+ function testFile() {
+ $this->P->addMode('file',new Doku_Parser_Mode_File());
+ $this->P->parse('Foo <file>testing</file> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('file',array('testing')),
+ array('p_open',array()),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testCode() {
+ $this->P->addMode('code',new Doku_Parser_Mode_Code());
+ $this->P->parse('Foo <code>testing</code> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('code',array('testing', NULL)),
+ array('p_open',array()),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testCodeWhitespace() {
+ $this->P->addMode('code',new Doku_Parser_Mode_Code());
+ $this->P->parse("Foo <code \n>testing</code> Bar");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('code',array('testing', NULL)),
+ array('p_open',array()),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testCodeLang() {
+ $this->P->addMode('code',new Doku_Parser_Mode_Code());
+ $this->P->parse("Foo <code php>testing</code> Bar");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('code',array('testing', 'php')),
+ array('p_open',array()),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testPreformatted() {
+ $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
+ $this->P->parse("F oo\n x \n y \nBar\n");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\nF oo")),
+ array('p_close',array()),
+ array('preformatted',array("x \n y ")),
+ array('p_open',array()),
+ array('cdata',array('Bar'."\n\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testPreformattedWinEOL() {
+ $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
+ $this->P->parse("F oo\r\n x \r\n y \r\nBar\r\n");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\nF oo")),
+ array('p_close',array()),
+ array('preformatted',array("x \n y ")),
+ array('p_open',array()),
+ array('cdata',array('Bar'."\n\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testPreformattedTab() {
+ $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
+ $this->P->parse("F oo\n\tx\t\n\t\ty\t\nBar\n");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\nF oo")),
+ array('p_close',array()),
+ array('preformatted',array("x\t\n\ty\t")),
+ array('p_open',array()),
+ array('cdata',array("Bar\n\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testPreformattedTabWinEOL() {
+ $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
+ $this->P->parse("F oo\r\n\tx\t\r\n\t\ty\t\r\nBar\r\n");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\nF oo")),
+ array('p_close',array()),
+ array('preformatted',array("x\t\n\ty\t")),
+ array('p_open',array()),
+ array('cdata',array("Bar\n\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testPreformattedList() {
+ $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
+ $this->P->addMode('listblock',new Doku_Parser_Mode_ListBlock());
+ $this->P->parse(" - x \n * y \nF oo\n x \n y \n -X\n *Y\nBar\n");
+ $calls = array (
+ array('document_start',array()),
+ array('listo_open',array()),
+ array('listitem_open',array(1)),
+ array('listcontent_open',array()),
+ array('cdata',array(" x ")),
+ array('listcontent_close',array()),
+ array('listitem_close',array()),
+ array('listo_close',array()),
+ array('listu_open',array()),
+ array('listitem_open',array(1)),
+ array('listcontent_open',array()),
+ array('cdata',array(" y ")),
+ array('listcontent_close',array()),
+ array('listitem_close',array()),
+ array('listu_close',array()),
+ array('p_open',array()),
+ array('cdata',array("F oo")),
+ array('p_close',array()),
+ array('preformatted',array("x \n y \n-X\n*Y")),
+ array('p_open',array()),
+ array('cdata',array("Bar\n\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testPHP() {
+ $this->P->addMode('php',new Doku_Parser_Mode_PHP());
+ $this->P->parse('Foo <php>testing</php> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('php',array('testing')),
+ array('p_open',array()),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testHTML() {
+ $this->P->addMode('html',new Doku_Parser_Mode_HTML());
+ $this->P->parse('Foo <html>testing</html> Bar');
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("\n".'Foo ')),
+ array('p_close',array()),
+ array('html',array('testing')),
+ array('p_open',array()),
+ array('cdata',array(' Bar'."\n")),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+
+ function testPreformattedPlusHeaderAndEol() {
+ // Note that EOL must come after preformatted!
+ $this->P->addMode('preformatted',new Doku_Parser_Mode_Preformatted());
+ $this->P->addMode('header',new Doku_Parser_Mode_Header());
+ $this->P->addMode('eol',new Doku_Parser_Mode_Eol());
+ $this->P->parse("F oo\n ==Test==\n y \nBar\n");
+ $calls = array (
+ array('document_start',array()),
+ array('p_open',array()),
+ array('cdata',array("F oo")),
+ array('p_close',array()),
+ array('preformatted',array("==Test==\n y ")),
+ array('p_open',array()),
+ array('cdata',array('Bar')),
+ array('p_close',array()),
+ array('p_open',array()),
+ array('p_close',array()),
+ array('p_open',array()),
+ array('p_close',array()),
+ array('document_end',array()),
+ );
+ $this->assertEqual(array_map('stripbyteindex',$this->H->calls),$calls);
+ }
+}
+
+/**
+* Conditional test runner
+*/
+if (!defined('TEST_RUNNING')) {
+ define('TEST_RUNNING', true);
+ $test = &new TestOfDoku_Parser_Preformatted();
+ $test->run(new HtmlReporter());
+}