From 6943a9f3bc10a60fcc01f126dfbd22b24b9c99cb Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Thu, 8 Feb 2007 14:51:25 +0000 Subject: Moved ITools tests from searchlib to itools/live --- .gitattributes | 3 + tests/it.t | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/it_html.t | 86 +++++++++++++++++++++++ tests/it_xml.t | 66 ++++++++++++++++++ tests/itjs.t | 46 +++++++++++++ 5 files changed, 407 insertions(+) create mode 100755 tests/it.t create mode 100755 tests/it_html.t create mode 100755 tests/it_xml.t create mode 100755 tests/itjs.t diff --git a/.gitattributes b/.gitattributes index 9c7115f..e17f544 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ * text=auto !eol itjs/error.gif -text +tests/it_html.t -text +tests/it_xml.t -text +tests/itjs.t -text diff --git a/tests/it.t b/tests/it.t new file mode 100755 index 0000000..65ac0b9 --- /dev/null +++ b/tests/it.t @@ -0,0 +1,206 @@ +#!/www/server/bin/php -qC + 'repl1', + 'regex2' => 'repl2', + 'regex3' => 'repl3' ), + 'regex2 regex1 regex3' ), + 'repl2 repl1 repl3', + 'test tr regex function' + ); +is( + it::match( '\w+', 'word1 wörd2 word_3', 'all' => true ), + array( 'word1', 'wörd2', 'word_3' ), + "test match_all function" + ); +match( + 'aBcD', ' aBcD ', + 'aBcD', + "caseinsensitive is default" + ); +match( + 'ö', 'Ö', + 'Ö', + 'match umlaute in latin1 case insensitive' + ); +is( + it::match( 'abc', "aBc", 'casesensitive' => 1 ), + false, + "set case sensitivity by parameter" + ); + +is( + it::match( '\w+', 'word1 wörd2 word_3', 'all' => 1 ), + array( 'word1', 'wörd2', 'word_3' ), + "test all=>1 without captures" + ); +is( + it::match( '\w+\s+(\d+)', 'word1 12 wörd2 3 word_3 4', 'all' => 1 ), + array( '12', '3', '4' ), + "test all=>1 with one capture" + ); +is( + it::match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', 'all' => 1 ), + array( array( 'word1', '12' ), array( 'wörd2', '3' ), array( 'word_3', '4' ) ), + "test all=>1 with captures" + ); +is( + it::match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', 'all' => 1, 'pattern_order' => 1 ), + array( array( 'word1', 'wörd2', 'word_3' ), array( '12', '3', '4' ) ), + "test all=>1,pattern_order=>1", + ); +?> diff --git a/tests/it_html.t b/tests/it_html.t new file mode 100755 index 0000000..95d615c --- /dev/null +++ b/tests/it_html.t @@ -0,0 +1,86 @@ +#!/www/server/bin/php -qC + "html"); + +is( + a('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => "", "bar"), + 'bar', + "tag with attributes" +); + +is( + div(), + "
\n", + "empty script tag" +); + +is( + img('src' => "foo.png"), + '', + "empty link tag" +); + +is( + tag('link'), + "\n", + "empty link tag" +); + +is( + tag('link', "foo"), + "foo\n", + "link tag with data" +); + +# XML generation +unset($GLOBALS['it_html']); +new it_html('htmltype' => "xhtml", 'tags' => "xmltest"); + +is( + xmltest(), + "\n", + "empty xmltest tag" +); + +is( + xmltest("foo"), + "foo\n", + "empty xmltest tag" +); + +is( + xmltest('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => ""), + '' . "\n", + "xmltest tag with attributes" +); + +# Inheriting and extending it_html +class myhtml extends it_html +{ +function myimg($args) +{ + array_unshift($args, 'alt' => "ALT", 'bar' => "BAR"); + + return parent::img($args); +} +} + +unset($GLOBALS['it_html']); +new myhtml('htmltype' => "html"); + +is( + myimg('src' => "foo.gif", 'alt' => "foo"), + 'foo', + "it_html inheritance" +); + + +?> diff --git a/tests/it_xml.t b/tests/it_xml.t new file mode 100755 index 0000000..06df969 --- /dev/null +++ b/tests/it_xml.t @@ -0,0 +1,66 @@ +#!/www/server/bin/php -qC +$xmldata"); + + is( + preg_replace('/[#\s]+/', " ", search_test::dump($xml->$varname)), + $expected, + $name, + ); +} + +match( + '', + 'class foo { }', + 'empty tag' +); + +#match( +# '', +# 'array ( 0 => class foo { }, 1 => class foo { }, )', +# 'multiple empty tags converted to array' +#); + +match( + 'Stüssihofstadt', + 'class foo { var $attr = array( \'title\' => \'Zürich\' ); var $val = \'Stüssihofstadt\'; }', + 'simple tag with latin1 content and attribute' +); + +# Test inheritance +class my_xml extends it_xml +{ + +function my_xml($xmldata) +{ + parent::it_xml($xmldata); + + # Code which should be executed in root and only there + $this->qux = new it_xml; + $this->qux->val = "qux"; + + if (is_object($this->myfoo)) + $this->myfoo->properbaseclass = is_a($this->myfoo, "my_xml"); +} + +} + +match( + '', + 'class myfoo { var $properbaseclass = true; }', + 'Inheritance and constructor', + 'my' +); + +?> diff --git a/tests/itjs.t b/tests/itjs.t new file mode 100755 index 0000000..8cbf90c --- /dev/null +++ b/tests/itjs.t @@ -0,0 +1,46 @@ +#!/www/server/bin/php -qC + "bar", "qux", 42 => "quux")), + "{foo:\"bar\",\n'0':\"qux\",\n'42':\"quux\"}", + 'key-value pairs' +); + +is( + itjs::serialize(array('foo' => array('bar' => array("qux", 42)))), + '{foo:{bar:["qux", 42]}}', + 'nested arrays' +); + +?> -- cgit v1.2.3