summaryrefslogtreecommitdiff
path: root/tests/it.t
diff options
context:
space:
mode:
authorChristian Schneider2007-10-11 00:39:30 +0000
committerChristian Schneider2007-10-11 00:39:30 +0000
commit35fe33f7364329dacf415c950bff01b6de9ef88e (patch)
treeb0e6b018b50038ca20266723c53750268f508df5 /tests/it.t
parent1f95711ff3e9697cd85a54545ab42e5fd3611317 (diff)
downloaditools-35fe33f7364329dacf415c950bff01b6de9ef88e.tar.gz
itools-35fe33f7364329dacf415c950bff01b6de9ef88e.tar.bz2
itools-35fe33f7364329dacf415c950bff01b6de9ef88e.zip
Populated release branch
Diffstat (limited to 'tests/it.t')
-rwxr-xr-xtests/it.t204
1 files changed, 204 insertions, 0 deletions
diff --git a/tests/it.t b/tests/it.t
new file mode 100755
index 0000000..e399c72
--- /dev/null
+++ b/tests/it.t
@@ -0,0 +1,204 @@
+#!/www/server/bin/php -qC
+<?php
+
+# Tests for 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', array('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", array('casesensitive' => 1 )),
+ false,
+ "set case sensitivity by parameter"
+ );
+
+is(
+ it::match( '\w+', 'word1 wörd2 word_3', array('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', array('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', array('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', array('all' => 1, 'pattern_order' => 1 )),
+ array( array( 'word1', 'wörd2', 'word_3' ), array( '12', '3', '4' ) ),
+ "test all=>1,pattern_order=>1"
+ );
+?>