summaryrefslogtreecommitdiff
path: root/tests/it.t
diff options
context:
space:
mode:
authorChristian Schneider2007-02-08 14:51:25 +0000
committerChristian Schneider2007-02-08 14:51:25 +0000
commit6943a9f3bc10a60fcc01f126dfbd22b24b9c99cb (patch)
tree7115430bdc88c9a05788b560cf0d58d62807d8f3 /tests/it.t
parente49941bbff3f9d7e87e26265b9971c788b861628 (diff)
downloaditools-6943a9f3bc10a60fcc01f126dfbd22b24b9c99cb.tar.gz
itools-6943a9f3bc10a60fcc01f126dfbd22b24b9c99cb.tar.bz2
itools-6943a9f3bc10a60fcc01f126dfbd22b24b9c99cb.zip
Moved ITools tests from searchlib to itools/live
Diffstat (limited to 'tests/it.t')
-rwxr-xr-xtests/it.t206
1 files changed, 206 insertions, 0 deletions
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
+<?php
+#
+# $Id$
+#
+# some tests for itools/it.class
+
+require 'searchlib/search_test.class';
+
+function match( $regex, $string, $exp, $name )
+{
+ $GLOBALS['TEST_MORE_LEVEL'] = 1;
+ $pass = is( it::match( $regex, $string ), $exp, $name );
+ if( !$pass ) {
+ diag( " regex given: $regex" );
+ diag( " regex converted: " . it::convertregex( $regex ) );
+ }
+ $GLOBALS['TEST_MORE_LEVEL'] = 0;
+}
+
+match(
+ 'b', 'aaaabaaaa',
+ 'b',
+ 'simple regex'
+ );
+match(
+ 'a/b', ' a/b ',
+ 'a/b',
+ 'regex with /'
+);
+match(
+ 'aa(bb)aa(cc)aa(dd)qq', 'aabbaaccaaddqq',
+ array( 'bb', 'cc', 'dd' ),
+ 'return array of captures'
+ );
+match(
+ '\bblah\b', ' blah ',
+ 'blah',
+ 'match \b at spaces'
+ );
+match(
+ '\bblah\b', 'blah',
+ 'blah',
+ 'match \b at end of string'
+ );
+match(
+ '\bblah\b', 'ablahc',
+ false,
+ 'don\'t match \b at word chars'
+ );
+match(
+ '\bblah\b', 'Üblahä',
+ false,
+ 'don\'t match \b at umlaute in latin1'
+ );
+match(
+ '\Bblah\B', ' blah ',
+ false,
+ 'don\'t match \B at spaces'
+ );
+match(
+ '\Bblah\B', 'blah',
+ false,
+ 'don\'t match \B at end of string'
+ );
+match(
+ '\Bblah\B', 'ablahc',
+ 'blah',
+ 'match \B at word chars'
+ );
+match(
+ '\Bblah\B', 'Üblahä',
+ 'blah',
+ 'match \B at umlaute in latin1'
+ );
+match(
+ '\w+', ' |#Üblahä ',
+ 'Üblahä',
+ 'include umlaute in \w'
+ );
+match(
+ '\W+', ' |#Üblahä ',
+ ' |#',
+ 'don\'t include umlaute in \W'
+ );
+
+eval( '$escapedwordregex = "' . it::convertregex( '\w' ) . '";' );
+$escapedwordregex = preg_replace( '|[\\\\/]|', '', $escapedwordregex );
+
+match(
+ '\\\\w+', $escapedwordregex,
+ false,
+ 'don\'t parse \w in \\\\w at beginning (no match)'
+ );
+match(
+ 'aaa\\\\w+', ' aaa\www ',
+ 'aaa\www',
+ 'don\'t parse \w in \\\\w at beginning (match)'
+ );
+match(
+ 'aaa\\\\w+', 'aaa' . $escapedwordregex,
+ false,
+ 'don\'t parse \w in \\\\w after chars (no match)'
+ );
+match(
+ 'aaa\\\\w+', ' aaa\www ',
+ 'aaa\www',
+ 'don\'t parse \w in \\\\w after chars (match)'
+ );
+match(
+ '\\\\\\\\w+', '\\' . $escapedwordregex,
+ false,
+ 'don\'t parse \w in \\\\\\\w (no match)'
+ );
+match(
+ '\\\\\\\\w+', ' \\\\www ',
+ '\\\\www',
+ 'don\'t parse \\\\\\\\w as \w (match)'
+ );
+match(
+ '[\w]+', '[[[]]]---',
+ false,
+ 'replace \w in [\w] correctly (no match)'
+ );
+match(
+ '[\w]+', ' \\\\aword[[[]]] ',
+ 'aword',
+ 'replace \w in [\w] correctly (match)',
+ );
+match(
+ '[\\\\w]+', ' blabergna ',
+ false,
+ 'don\'t parse \w in [\\\\w] (no match)'
+ );
+match(
+ '[\\\\w]+', ' \\\\worda[[[]',
+ '\\\\w',
+ 'don\'t parse \w in [\\\\w] (match)',
+ );
+match(
+ '[a\W]+', 'bbbbbbb a a%$+ accccc',
+ ' a a%$+ a',
+ '\W in []'
+ );
+match(
+ '\\\\\\w+', ' \Üblahä ',
+ '\Üblahä',
+ 'parse \w in \\\\\\w at beginning'
+ );
+match(
+ 'aaa\\\\\\w+', ' aaa\Üblahä ',
+ 'aaa\Üblahä',
+ 'parse \w in \\\\\\w after chars'
+ );
+is(
+ it::replace(
+ array(
+ 'regex1' => '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",
+ );
+?>