diff options
author | Nathan Gass | 2021-01-06 16:54:14 +0100 |
---|---|---|
committer | Nathan Gass | 2021-01-06 16:54:14 +0100 |
commit | bdb59ae566c1b4c78a4d82a881f8b1ffbf6dbbef (patch) | |
tree | 26d1bb58707c9b799f44866dc1640c106a474f87 /test/it.t | |
parent | 6190f37f8a6b6dadccb0766326a0ad8781670f41 (diff) | |
parent | 7ee56cc6e8ea89c030b3eb5f8d4d4f8c1d5a053d (diff) | |
download | itools-bdb59ae566c1b4c78a4d82a881f8b1ffbf6dbbef.tar.gz itools-bdb59ae566c1b4c78a4d82a881f8b1ffbf6dbbef.tar.bz2 itools-bdb59ae566c1b4c78a4d82a881f8b1ffbf6dbbef.zip |
Merge branch 'master' into ng/postgresql
Diffstat (limited to 'test/it.t')
-rwxr-xr-x | test/it.t | 89 |
1 files changed, 48 insertions, 41 deletions
@@ -12,7 +12,7 @@ $oldlocale = setlocale(LC_CTYPE, 0); ini_set('default_charset', 'utf-8'); setlocale(LC_CTYPE, 'de_CH'); # required becuase we're checking German umlauts in latin1 mode -function match($regex, $string, $expect, $name, $p = []) +function _match($regex, $string, $expect, $name, $p = []) { $GLOBALS['TEST_MORE_LEVEL'] = 1; $pass = is (it::match($regex, $string, $p), $expect, $name); @@ -24,103 +24,103 @@ function match($regex, $string, $expect, $name, $p = []) } -match( +_match( 'b', 'aaaabaaaa', 'b', 'simple regex' ); -match( +_match( 'a/b', ' a/b ', 'a/b', 'regex with /' ); -match( +_match( 'aa(bb)aa(cc)aa(dd)qq', 'aabbaaccaaddqq', ['bb', 'cc', 'dd'], 'return array of captures' ); -match( +_match( '\bblah\b', ' blah ', 'blah', 'match \b at spaces' ); -match( +_match( '\bblah\b', 'blah', 'blah', 'match \b at end of string' ); -match( +_match( '\bblah\b', 'ablahc', null, 'don\'t match \b at word chars' ); -match( +_match( '\bblah\b', 'Üblahä', null, 'don\'t match \b at umlaute' ); -match( +_match( '\Bblah\B', ' blah ', null, 'don\'t match \B at spaces' ); -match( +_match( '\Bblah\B', 'blah', null, 'don\'t match \B at end of string' ); -match( +_match( '\Bblah\B', 'ablahc', 'blah', 'match \B at word chars' ); -match( +_match( '\Bblah\B', 'Üblahä', 'blah', 'match \B at umlaute' ); -match( +_match( '\w+', ' |#Üblahä ', 'Üblahä', 'include umlaute in \w' ); -match( +_match( '[[:alpha:]]+', ' |#blahä ', 'blahä', 'include umlaute in [[:alpha:]]' ); -match( +_match( '\W+', ' |#Üblahä ', ' |#', 'don\'t include umlaute in \W' ); -match( +_match( '\ba', 'äa', null, '\b must know umlauts' ); -match( +_match( 'aaa\\\\w+', ' aaa\www ', 'aaa\www', 'don\'t parse \w in \\\\w at beginning (match)' ); -match( +_match( 'aaa\\\\w+', ' aaa\www ', 'aaa\www', 'don\'t parse \w in \\\\w after chars (match)' @@ -129,105 +129,105 @@ match( eval('$escapedwordregex = "' . it::convertregex('\w') . '";'); $escapedwordregex = preg_replace('|[\\\\/]|', '', $escapedwordregex); -match( +_match( '\\\\w+', $escapedwordregex, null, 'don\'t parse \w in \\\\w at beginning (no match)' ); -match( +_match( 'aaa\\\\w+', 'aaa' . $escapedwordregex, null, 'don\'t parse \w in \\\\w after chars (no match)' ); -match( +_match( '\\\\\\\\w+', '\\' . $escapedwordregex, null, 'don\'t parse \w in \\\\\\\w (no match)' ); -match( +_match( '\\\\\\\\w+', ' \\\\www ', '\\\\www', 'don\'t parse \\\\\\\\w as \w (match)' ); -match( +_match( '[\w]+', '[[[]]]---', null, 'replace \w in [\w] correctly (no match)' ); -match( +_match( '[\w]+', ' \\\\aword[[[]]] ', 'aword', 'replace \w in [\w] correctly (match)' ); -match( +_match( '[\\\\w]+', ' blabergna ', null, 'don\'t parse \w in [\\\\w] (no match)' ); -match( +_match( '[\\\\w]+', ' \\\\worda[[[]', '\\\\w', 'don\'t parse \w in [\\\\w] (match)' ); -match( +_match( '[a\W]+', 'bbbbbbb a a%$+ accccc', ' a a%$+ a', '\W in []' ); -match( +_match( '\\\\\\w+', ' \Üblahä ', '\Üblahä', 'parse \w in \\\\\\w at beginning' ); -match( +_match( 'aaa\\\\\\w+', ' aaa\Üblahä ', 'aaa\Üblahä', 'parse \w in \\\\\\w after chars' ); -match( +_match( '\w+', 'word1 wörd2 word_3', ['word1', 'wörd2', 'word_3'], "test match_all function", ['all' => true] ); -match( +_match( 'aBcD', ' aBcD ', 'aBcD', "caseinsensitive is default" ); -match( +_match( '\w+', 'Müller', 'Müller', '\w matches umlaut in utf-8 mode' ); -match( +_match( 'M.ller', 'Müller', 'Müller', '. matches umlaut in utf-8 mode' ); -match( +_match( utf8_decode('ö'), utf8_decode('Ö'), utf8_decode('Ö'), 'match umlaute in de_CH.latin1 case insensitive', ['utf8' => false] ); -match( +_match( utf8_decode('aöBÜ'), utf8_decode('AÖbü'), utf8_decode('AÖbü'), "match umlaute with non-utf-8 override in p", @@ -235,35 +235,35 @@ match( ); -match( +_match( 'abc', "aBc", null, "set case sensitivity by parameter", ['casesensitive' => 1] ); -match( +_match( '\w+', 'word1 wörd2 word_3', ['word1', 'wörd2', 'word_3'], "test all => 1 without captures", ['all' => 1] ); -match( +_match( '\w+\s+(\d+)', 'word1 12 wörd2 3 word_3 4', ['12', '3', '4'], "test all => 1 with one capture", ['all' => 1] ); -match( +_match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', [['word1', '12'], ['wörd2', '3'], ['word_3', '4']], "test all => 1 with captures", ['all' => 1] ); -match( +_match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', [['word1', 'wörd2', 'word_3'], ['12', '3', '4']], "test all => 1,pattern_order => 1", @@ -271,7 +271,7 @@ match( ); ini_set('default_charset', 'iso-8859-1'); -match( +_match( 'aöBÜ', "AÖbü", 'AÖbü', "match utf-8 umlaute in case insensitive mode with utf8 override", @@ -381,6 +381,10 @@ is(it::ucwords('foo bär über'), 'Foo Bär Über'); # it::substr_replace is(it::substr_replace('abcdefgh', 'xyz', 2, 4), substr_replace('abcdefgh', 'xyz', 2, 4), 'it::substr_replace the same as substr_replace for ascii'); is(it::substr_replace('✔☯♥', '☃☃', 1, 1), '✔☃☃♥', 'it::substr_replace for utf-8'); +is(it::substr_replace('', 'xyz', 0, 0), substr_replace('', 'xyz', 0, 0), 'it::substr_replace with empty haystack the same as substr_replace'); +is(it::substr_replace('abc', 'xyz', 0, 2), substr_replace('abc', 'xyz', 0, 2), 'it::substr_replace replacing to end of haystack'); +is(it::substr_replace('abc', 'xyz', 0, 10), substr_replace('abc', 'xyz', 0, 10), 'it::substr_replace replacing past end of haystack'); +is(it::substr_replace('abcdefgh', 'xyz', 10, 4), substr_replace('abcdefgh', 'xyz', 10, 4), 'it::substr_replace outside of string'); is(grapheme_strlen("\xc1"), null, "need grapheme_strlen side effect for any2utf8"); @@ -448,6 +452,7 @@ is(it::mod(7, 4), 3); is(it::map('5*$k+$v', [0 => 1, 1 => 2]), [1, 7]); is(it::map(function($k, $v) {return 5*$k+$v;}, [0 => 1, 1 => 2]), [1, 7]); +is(it::map(function($v) {return 2*$v;}, [0 => 1, 1 => 2]), [2, 4]); is(it::map('strlen', ["aaa", "aa"]), [3, 2]); is(it::map('it::ucfirst', ["aaa"]), ["Aaa"]); $dom = new DOMDocument; @@ -465,6 +470,8 @@ is(it::map('2*$v', ['foo' => 1, 'bar' => 2], ['keys' => 'foo']), ['foo' => 2, 'b # it::filter is(it::filter('$v > 2', [1, 5 => 2, 2 => 3]), [2 => 3]); is(it::filter('$k > 2', [1, 5 => 2, 2 => 3]), [5 => 2]); +is(it::filter(function($v) {return $v > 2;}, [1, 5 => 2, 2 => 3]), [2 => 3]); +is(it::filter(function($k, $v) {return $k > 2;}, [1, 5 => 2, 2 => 3]), [5 => 2]); is(it::split("b", "aba"), ["a", "a"]); is(it::split("b", "aBa"), ["a", "a"]); |