summaryrefslogtreecommitdiff
path: root/test/it.t
diff options
context:
space:
mode:
Diffstat (limited to 'test/it.t')
-rwxr-xr-xtest/it.t112
1 files changed, 56 insertions, 56 deletions
diff --git a/test/it.t b/test/it.t
index 26d0f95..65adcd6 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 = array())
+function match($regex, $string, $expect, $name, $p = [])
{
$GLOBALS['TEST_MORE_LEVEL'] = 1;
$pass = is (it::match($regex, $string, $p), $expect, $name);
@@ -38,7 +38,7 @@ match(
match(
'aa(bb)aa(cc)aa(dd)qq', 'aabbaaccaaddqq',
- array('bb', 'cc', 'dd'),
+ ['bb', 'cc', 'dd'],
'return array of captures'
);
@@ -197,9 +197,9 @@ match(
match(
'\w+', 'word1 wörd2 word_3',
- array('word1', 'wörd2', 'word_3'),
+ ['word1', 'wörd2', 'word_3'],
"test match_all function",
- array('all' => true)
+ ['all' => true]
);
match(
@@ -224,14 +224,14 @@ match(
utf8_decode('ö'), utf8_decode('Ö'),
utf8_decode('Ö'),
'match umlaute in de_CH.latin1 case insensitive',
- array('utf8' => false)
+ ['utf8' => false]
);
match(
utf8_decode('aöBÜ'), utf8_decode('AÖbü'),
utf8_decode('AÖbü'),
"match umlaute with non-utf-8 override in p",
- array('utf8' => false)
+ ['utf8' => false]
);
@@ -239,35 +239,35 @@ match(
'abc', "aBc",
null,
"set case sensitivity by parameter",
- array('casesensitive' => 1)
+ ['casesensitive' => 1]
);
match(
'\w+', 'word1 wörd2 word_3',
- array('word1', 'wörd2', 'word_3'),
+ ['word1', 'wörd2', 'word_3'],
"test all => 1 without captures",
- array('all' => 1)
+ ['all' => 1]
);
match(
'\w+\s+(\d+)', 'word1 12 wörd2 3 word_3 4',
- array('12', '3', '4'),
+ ['12', '3', '4'],
"test all => 1 with one capture",
- array('all' => 1)
+ ['all' => 1]
);
match(
'(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4',
- array(array('word1', '12'), array('wörd2', '3'), array('word_3', '4')),
+ [['word1', '12'], ['wörd2', '3'], ['word_3', '4']],
"test all => 1 with captures",
- array('all' => 1)
+ ['all' => 1]
);
match(
'(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4',
- array(array('word1', 'wörd2', 'word_3'), array('12', '3', '4')),
+ [['word1', 'wörd2', 'word_3'], ['12', '3', '4']],
"test all => 1,pattern_order => 1",
- array('all' => 1, 'pattern_order' => 1)
+ ['all' => 1, 'pattern_order' => 1]
);
ini_set('default_charset', 'iso-8859-1');
@@ -275,7 +275,7 @@ match(
'aöBÜ', "AÖbü",
'AÖbü',
"match utf-8 umlaute in case insensitive mode with utf8 override",
- array('utf8' => true)
+ ['utf8' => true]
);
ini_set('default_charset', 'utf-8');
@@ -285,30 +285,30 @@ ini_set('default_charset', 'utf-8');
#
is(
it::replace(
- array(
+ [
'regex1' => 'repl1',
'regex2' => 'repl2',
- 'regex3' => 'repl3'),
+ 'regex3' => 'repl3'],
'regex2 regex1 regex3'),
'repl2 repl1 repl3',
'test tr regex function'
);
-is(it::replace(array('a' => "1", 'b' => "2"), "ab"), "12");
-is(it::replace(array('!' => "x"), "!"), "x");
-is(it::replace(array('\w' => "x"), "oö"), "xx");
-is(it::replace(array('[[:alpha:]]' => "x"), "ö"), "x");
-is(it::replace(array('\w' => "x", '#' => "!"), "#ö"), "!x");
-is(it::replace(array('#' => "!", '\w' => "x"), "#ö"), "!x");
-is(it::replace(array('ö' => "x"), "Ö"), "x");
-is(it::replace(array('a' => "1"), "aaa", array('limit' => 1)), "1aa");
-is(it::replace(array('\s' => "x"), it_html::entity_decode(" ")), "x", "match non-breaking space as white-space character");
-is(it::replace(array('a' => "b", 'b' => "c"), "a"), "c");
-
-is(it::grep('ismatch', array('ismatch', 'isnomatch')), array('ismatch'), 'grep with simple regex');
-is(it::grep('!', array('ismatch!', 'isnomatch')), array('ismatch!'), '! in regex');
-is(it::grep('lower|UPPER', array('lower', 'LOWER', 'upper', 'UPPER'), array('casesensitive' => 1)), array(0 => 'lower', 3 => 'UPPER'), 'set casesensitive');
-is(it::grep('match', array('foo' => 'match', 'bar' => 'gna')), array('foo' => 'match'), 'with keys');
+is(it::replace(['a' => "1", 'b' => "2"], "ab"), "12");
+is(it::replace(['!' => "x"], "!"), "x");
+is(it::replace(['\w' => "x"], "oö"), "xx");
+is(it::replace(['[[:alpha:]]' => "x"], "ö"), "x");
+is(it::replace(['\w' => "x", '#' => "!"], "#ö"), "!x");
+is(it::replace(['#' => "!", '\w' => "x"], "#ö"), "!x");
+is(it::replace(['ö' => "x"], "Ö"), "x");
+is(it::replace(['a' => "1"], "aaa", ['limit' => 1]), "1aa");
+is(it::replace(['\s' => "x"], it_html::entity_decode(" ")), "x", "match non-breaking space as white-space character");
+is(it::replace(['a' => "b", 'b' => "c"], "a"), "c");
+
+is(it::grep('ismatch', ['ismatch', 'isnomatch']), ['ismatch'], 'grep with simple regex');
+is(it::grep('!', ['ismatch!', 'isnomatch']), ['ismatch!'], '! in regex');
+is(it::grep('lower|UPPER', ['lower', 'LOWER', 'upper', 'UPPER'], ['casesensitive' => 1]), [0 => 'lower', 3 => 'UPPER'], 'set casesensitive');
+is(it::grep('match', ['foo' => 'match', 'bar' => 'gna']), ['foo' => 'match'], 'with keys');
is(it::grep('2', [0 => 1, 1 => 2, 2 => 3], ['invert' => true]), [0 => 1, 2 => 3]);
setlocale(LC_CTYPE, $oldlocale);
@@ -326,21 +326,21 @@ is(it::cidr_match('192.168.42.42', '192.168.42.64/26'), false, "cidr_match o
is(it::cidr_match('192.168.42.42', '192.168.42.32/27'), true, "cidr_match offset");
is(it::cidr_match('2001:918:ff83:101:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), true, "cidr_match ipv6");
is(it::cidr_match('2001:918:ff83:102:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), false, "cidr_match ipv6 no match" );
-is(it::cidr_match('10.11.12.13', array('10.0.0.0/8', '192.168.0.0./16')), true, "cidr_match array");
+is(it::cidr_match('10.11.12.13', ['10.0.0.0/8', '192.168.0.0./16']), true, "cidr_match array");
# it::filter_keys tests
-$data = array('a' => 1, 'b' => 2, 'c' => 3);
-is(it::filter_keys($data, 'a'), array('a' => 1), "select one key");
-is(it::filter_keys($data, array('a', 'b')), array('a' => 1, 'b' => 2), "select two keys with array");
-is(it::filter_keys($data, 'a,b'), array('a' => 1, 'b' => 2), "select two keys with string");
+$data = ['a' => 1, 'b' => 2, 'c' => 3];
+is(it::filter_keys($data, 'a'), ['a' => 1], "select one key");
+is(it::filter_keys($data, ['a', 'b']), ['a' => 1, 'b' => 2], "select two keys with array");
+is(it::filter_keys($data, 'a,b'), ['a' => 1, 'b' => 2], "select two keys with string");
is(
array_keys(it::filter_keys($data, 'b,a')),
- array('a', 'b'),
+ ['a', 'b'],
"keep order of data array per default");
is(
- array_keys(it::filter_keys($data, 'b,a', array('reorder' => true))),
- array('b', 'a'),
+ array_keys(it::filter_keys($data, 'b,a', ['reorder' => true])),
+ ['b', 'a'],
"reorder with given key order");
# it::date tests
@@ -409,10 +409,10 @@ is(it::any2utf8(utf8_encode(utf8_encode("Müller"))), "Müller", "it::any2utf8 t
is(it::any2utf8(utf8_decode("Müller")), "Müller", "it::any2utf8 incorrectly encoded latin1");
is(it::any2utf8("a💚b"), "a💚b", "it::any2utf8 correctly handles 4-byte utf-8 character GREEN HEART");
-is(it::any2utf8(array("foo", utf8_decode("bär"))), array("foo", "bär"), "any2utf8 on arrays");
-is(it::any2utf8(array("foo", array(utf8_decode("bär")))), array("foo", array("bär")), "any2utf8 on recursive arrays");
-is(it::any2utf8(array(1, true, false, null)), array(1, true, false, null), "any2utf8 should leave types alone");
-is(it::any2utf8(array(utf8_decode('Müller') => utf8_decode('Müller'))), array('Müller' => 'Müller'), "it::any2utf8 latin1 keys");
+is(it::any2utf8(["foo", utf8_decode("bär")]), ["foo", "bär"], "any2utf8 on arrays");
+is(it::any2utf8(["foo", [utf8_decode("bär")]]), ["foo", ["bär"]], "any2utf8 on recursive arrays");
+is(it::any2utf8([1, true, false, null]), [1, true, false, null], "any2utf8 should leave types alone");
+is(it::any2utf8([utf8_decode('Müller') => utf8_decode('Müller')]), ['Müller' => 'Müller'], "it::any2utf8 latin1 keys");
is(it::any2utf8("\xc2\xad"), "", "it::any2utf8 remove soft hyphens");
@@ -426,32 +426,32 @@ foreach ([ 'a' => 'ä', 'e' => 'ë', 'i' => 'ï', 'o' => 'ö', 'u' => 'ü' ] as
is(it::any2utf8("\x65\xcc\x81"), "é", "it::any2utf8 convert to normal form C");
-foreach (array($dummy, false, true, null, 1, "a", "Ä", "/", array()) as $var)
+foreach ([$dummy, false, true, null, 1, "a", "Ä", "/", []] as $var)
is(it::json_decode(it::json_encode($var)), $var);
is(it::json_decode('{"foo":"bar"}')->foo, "bar");
is(it::json_decode('{"foo":"bar"}', ['assoc' => true])['foo'], "bar");
-is(it::sort(array("2!","19!","1!")), array("1!", "19!", "2!"));
-is(it::sort(array("2!","19!","1!"), "r"), array("2!", "19!", "1!"));
-is(it::sort(array("2!","19!","1!"), "rn"), array("19!", "2!", "1!"));
+is(it::sort(["2!","19!","1!"]), ["1!", "19!", "2!"]);
+is(it::sort(["2!","19!","1!"], "r"), ["2!", "19!", "1!"]);
+is(it::sort(["2!","19!","1!"], "rn"), ["19!", "2!", "1!"]);
is(it::mod(-9, 4), 3);
is(it::mod(-8, 4), 0);
is(it::mod(0, 4), 0);
is(it::mod(7, 4), 3);
-is(it::map('5*$k+$v', array(0 => 1, 1 => 2)), array(1, 7));
-is(it::map(function($k, $v) {return 5*$k+$v;}, array(0 => 1, 1 => 2)), array(1, 7));
-is(it::map('strlen', array("aaa", "aa")), array(3, 2));
-is(it::map('it::ucfirst', array("aaa")), array("Aaa"));
+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('strlen', ["aaa", "aa"]), [3, 2]);
+is(it::map('it::ucfirst', ["aaa"]), ["Aaa"]);
$dom = new DOMDocument;
$dom->loadXML('<foo>42</foo>');
is(it::map('$v->C14N()', $dom->childNodes), [ '<foo>42</foo>' ], "Traversable: Needs copy, not modifiable in-place");
# Special values which are not callable
-is(it::map('null', array("aaa", "aa")), array(null, null));
-is(it::map('1', array("aaa", "aa")), array(1, 1));
-is(it::map(42, array("aaa", "aa")), array(42, 42));
+is(it::map('null', ["aaa", "aa"]), [null, null]);
+is(it::map('1', ["aaa", "aa"]), [1, 1]);
+is(it::map(42, ["aaa", "aa"]), [42, 42]);
# Only map selected keys
is(it::map('2*$v', [3, 4, 5], ['keys' => '0,1']), [6, 8, 5]);
is(it::map('2*$v', [3, 4, 5], ['keys' => [0,1]]), [6, 8, 5]);