diff options
author | Christian Schneider | 2017-01-25 17:42:54 +0100 |
---|---|---|
committer | Christian Schneider | 2017-01-25 17:42:54 +0100 |
commit | fa73882a1221136f502b7c5a8a57a91fa7d2542a (patch) | |
tree | 04964b3a126bde89a23adf1a153a1ded090027a7 /tests/it.t | |
parent | 3ebbf18ecd027fbeaa53166af4f6ceb6ca3e86a3 (diff) | |
download | itools-fa73882a1221136f502b7c5a8a57a91fa7d2542a.tar.gz itools-fa73882a1221136f502b7c5a8a57a91fa7d2542a.tar.bz2 itools-fa73882a1221136f502b7c5a8a57a91fa7d2542a.zip |
Second version of it::map with keys: Handle 'null', '1' for code and Traversable objects for array
Diffstat (limited to 'tests/it.t')
-rwxr-xr-x | tests/it.t | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -12,7 +12,6 @@ $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()) { $GLOBALS['TEST_MORE_LEVEL'] = 1; @@ -418,3 +417,14 @@ is(it::mod(7, 4), 3); is(it::map('5*$k+$v', array(0 => 1, 1 => 2)), array(1, 7)); is(it::map(create_function('$k,$v', 'return 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('$v->C14N()', DOMDocument::loadXML('<foo>42</foo>')->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)); +# 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]); +is(it::map('2*$v', ['foo' => 1, 'bar' => 2], ['keys' => 'foo']), ['foo' => 2, 'bar' => 2]); |