From 79fd50e172a50918d9018f54ab6e40606181f95b Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 15 Sep 2020 13:20:03 +0200 Subject: Make itools PHP 8 compatible --- test/it.t | 82 +++++++++++++++++++++++++++++----------------------------- test/it_text.t | 2 ++ test/it_xml.t | 24 ++++++++--------- 3 files changed, 55 insertions(+), 53 deletions(-) (limited to 'test') diff --git a/test/it.t b/test/it.t index 64b0fac..203a136 100755 --- a/test/it.t +++ b/test/it.t @@ -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", diff --git a/test/it_text.t b/test/it_text.t index 5629d51..6726996 100755 --- a/test/it_text.t +++ b/test/it_text.t @@ -1,7 +1,9 @@ #!/www/server/bin/php x = "attr"; +$obj->y = (object)[]; $obj->y->z = "attr"; is(it_text::transmogrify(""), ""); diff --git a/test/it_xml.t b/test/it_xml.t index 27f910f..e21f052 100755 --- a/test/it_xml.t +++ b/test/it_xml.t @@ -3,7 +3,7 @@ # Tests for xml.class -function match($xmldata, $expected, $name, $prefix = "", $p = []) +function _match($xmldata, $expected, $name, $prefix = "", $p = []) { $classname = ($prefix ?: "it") . "_xml"; $varname = $prefix . "foo"; @@ -31,37 +31,37 @@ function match($xmldata, $expected, $name, $prefix = "", $p = []) ); } -match( +_match( '', 'foo Object ( ) ', 'empty tag' ); -match( +_match( '', 'Array ( [0] => foo Object ( ) [1] => foo Object ( ) ) ', 'multiple empty tags converted to array' ); -match( +_match( 'Stüssihofstadt', 'foo Object ( [attr] => Array ( [title] => Zürich ) [val] => Stüssihofstadt ) ', 'simple tag with latin1 content and attribute' ); -match( +_match( '', 'foo Object ( [a_b__c] => a_b__c Object ( [attr] => Array ( [d_e_f] => value ) ) ) ', 'Tags and attributes with name space and special characters' ); -match( +_match( 'x & y', 'foo Object ( [val] => x & y ) ', 'Character data with entities' ); -match( +_match( 'x ü y', utf8_decode('foo Object ( [val] => x ü y ) '), 'Manual encoding override', @@ -69,13 +69,13 @@ match( ['encoding' => "iso-8859-1"] ); -match( +_match( '&amp; <a> &amp; <b> &amp; <c> ü', 'foo Object ( [val] => & & & ü ) ', 'Predecode illegal entities while keeping properly encoded ones' ); -match( +_match( '&amp; <a> &amp; <b> &amp; <c> ü', utf8_decode('foo Object ( [val] => & & & ü ) '), 'Predecode illegal entities while keeping properly encoded ones (iso-8859-1)', @@ -83,7 +83,7 @@ match( ['encoding' => "iso-8859-1"] ); -match( +_match( "a\x05b", 'foo Object ( [val] => a b ) ', 'Illegal latin 1 character', @@ -109,7 +109,7 @@ function __construct($xmldata) } -match( +_match( '', 'myfoo Object ( [inheritbaseclass] => ) ', 'Inheritance and constructor (critical for e.g. tel_xmlentry)', @@ -118,7 +118,7 @@ match( $x = new foo("", ['prefix' => "test"]); $x->set(['gna' => 42, 'bar' => ['baz' => ["qux", "quux"]]]); -match( +_match( $x->to_xml(), 'foo Object ( [gna] => gna Object ( [val] => 42 ) [bar] => bar Object ( [baz] => Array ( [0] => baz Object ( [val] => qux ) [1] => baz Object ( [val] => quux ) ) ) ) ', "Method set()" -- cgit v1.2.3 From ea0289885c1fc4a8621d3a68893d3c08a2716504 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Mon, 9 Nov 2020 16:50:24 +0100 Subject: no longer ignore extra positional arguments --- test/getopt.t | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/getopt.t b/test/getopt.t index aa2de52..48f7d9d 100755 --- a/test/getopt.t +++ b/test/getopt.t @@ -38,10 +38,9 @@ getopt_ok([], false, "Missing positional argument fails"); getopt_ok(['posarg', '--argument'], false, "Missing long named argument fails"); getopt_ok(['posarg', '-a'], false, "Missing short named argument fails"); -// FIXME 2020-10 NG enable after fixme in it.class -// $GLOBALS['usage'] = it::replace('\s*\[VARARGS\]' => '', $GLOBALS['usage']); -// getopt_ok(['posargs', 'vararg'], false, "Extra positional argument fails"); -// getopt_ok(['posargs', '--zero', 'vararg'], false, "Extra positional argument fails after long argument"); -// getopt_ok(['posargs', '-0', 'vararg'], false, "Extra positional argument fails after short argument"); -// getopt_ok(['posargs', '--argument', 'value', 'vararg'], false, "Extra positional argument fails after long argument with value"); -// getopt_ok(['posargs', '-a', 'value', 'vararg'], false, "Extra positional argument fails after short argument with value"); +$GLOBALS['usage'] = it::replace(['\s*\[VARARGS\]' => ''], $GLOBALS['usage']); +getopt_ok(['posargs', 'vararg'], false, "Extra positional argument fails"); +getopt_ok(['posargs', '--zero', 'vararg'], false, "Extra positional argument fails after long argument"); +getopt_ok(['posargs', '-0', 'vararg'], false, "Extra positional argument fails after short argument"); +getopt_ok(['posargs', '--argument', 'value', 'vararg'], false, "Extra positional argument fails after long argument with value"); +getopt_ok(['posargs', '-a', 'value', 'vararg'], false, "Extra positional argument fails after short argument with value"); -- cgit v1.2.3 From 1b03f72e7edc609b326927dfebc9f3f0bd6228a1 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Fri, 27 Nov 2020 12:31:32 +0100 Subject: pass array values instead of keys to functions with only one argument in it::map and it::filter --- test/it.t | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/it.t b/test/it.t index 203a136..49d5854 100755 --- a/test/it.t +++ b/test/it.t @@ -448,6 +448,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 +466,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"]); -- cgit v1.2.3 From c997c6082ec2e47244ace87781d29c4766938197 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Thu, 3 Dec 2020 16:08:31 +0100 Subject: Add some tests for it::substr() behaviour we rely on which was broken for some PHP 8 Beta versions --- test/it.t | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/it.t b/test/it.t index 49d5854..a3abf32 100755 --- a/test/it.t +++ b/test/it.t @@ -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"); -- cgit v1.2.3