cvs: php4 /ext/iconv/tests iconv_strlen.phpt iconv_substr.phpt
| From: | Moriyoshi Koizumi | Date: | Fri, 03 Jan 2003 05:48:51 +0000 |
| Subject: | cvs: php4 /ext/iconv/tests iconv_strlen.phpt iconv_substr.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-17553@lists.php.net to get a copy of this message | ||
moriyoshi Fri Jan 3 00:48:51 2003 EDT
Added files:
/php4/ext/iconv/tests iconv_strlen.phpt iconv_substr.phpt
Log:
Added test cases for iconv_strlen() and iconv_substr()
Index: php4/ext/iconv/tests/iconv_strlen.phpt
+++ php4/ext/iconv/tests/iconv_strlen.phpt
--TEST--
iconv_strlen()
--SKIPIF--
<?php extension_loaded('iconv') or die('skip iconv extension is not
available'); ?>
--FILE--
<?php
function foo($str, $charset) {
var_dump(strlen($str));
var_dump(iconv_strlen($str, $charset));
}
foo("abc", "ASCII");
foo("ÆüËܸì EUC-JP", "EUC-JP");
?>
--EXPECT--
int(3)
int(3)
int(13)
int(10)
Index: php4/ext/iconv/tests/iconv_substr.phpt
+++ php4/ext/iconv/tests/iconv_substr.phpt
--TEST--
iconv_substr()
--SKIPIF--
<?php extension_loaded('iconv') or die('skip iconv extension is not
available'); ?>
--INI--
iconv.internal_charset=ISO-8859-1
--FILE--
<?php
function hexdump($str) {
$len = strlen($str);
for ($i = 0; $i < $len; ++$i) {
printf("%02x", ord($str{$i}));
}
print "\n";
}
function foo($str, $offset, $len, $charset) {
hexdump(substr($str, $offset, $len));
hexdump(iconv_substr($str, $offset, $len, $charset));
}
function bar($str, $offset, $len = false) {
if (is_bool($len)) {
var_dump(substr($str, $offset));
var_dump(iconv_substr($str, $offset));
} else {
var_dump(substr($str, $offset, $len));
var_dump(iconv_substr($str, $offset, $len));
}
}
foo("abcdefghijklmnopqrstuvwxyz", 5, 7, "ASCII");
foo("¤¢¤¤¤¦¤¨¤ª¤«¤¤¯¤±¤³¤µ¤·¤¹", 5, 7, "EUC-JP");
bar("This is a test", 100000);
bar("This is a test", 0, 100000);
bar("This is a test", -3);
bar("This is a test", 0, -9);
bar("This is a test", 0, -100000);
bar("This is a test", -9, -100000);
var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP",
"ISO-2022-JP", "¤³¤ó¤Ë¤Á¤Ï ISO-2022-JP"), 3, 8,
"ISO-2022-JP")));
?>
--EXPECT--
666768696a6b6c
666768696a6b6c
a6a4a8a4aaa4ab
a4aba4ada4afa4b1a4b3a4b5a4b7
bool(false)
string(0) ""
string(14) "This is a test"
string(14) "This is a test"
string(3) "est"
string(3) "est"
string(5) "This "
string(5) "This "
string(0) ""
string(0) ""
string(0) ""
string(0) ""
string(10) "¤Á¤Ï ISO-2"