From 3ae0dd35df72193095029d06f5459b5243430140 Mon Sep 17 00:00:00 2001 From: andi Date: Sun, 3 Apr 2005 09:45:21 +0200 Subject: added unit tests darcs-hash:20050403074521-9977f-d1a3c3a1200cab2d28789490ab3b49cd48691688.gz --- inc/parser/tests/parser_preformatted.test.php | 244 ++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 inc/parser/tests/parser_preformatted.test.php (limited to 'inc/parser/tests/parser_preformatted.test.php') 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 @@ +UnitTestCase('TestOfDoku_Parser_Preformatted'); + } + + function testFile() { + $this->P->addMode('file',new Doku_Parser_Mode_File()); + $this->P->parse('Foo testing 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 testing 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 testing 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 testing 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 testing 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 testing 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()); +} -- cgit v1.2.3