X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=tests%2Ficonv%2Ficonv002.phpt;fp=tests%2Ficonv%2Ficonv002.phpt;h=16095b5837485a3cac09a36915cb13e9dcd65966;hp=0000000000000000000000000000000000000000;hb=d59f10e81c33354ee1589fb10847b4611423de2e;hpb=6bc2d7ee8421401fc11225e09e4bb1fab03594b8 diff --git a/tests/iconv/iconv002.phpt b/tests/iconv/iconv002.phpt new file mode 100644 index 0000000..16095b5 --- /dev/null +++ b/tests/iconv/iconv002.phpt @@ -0,0 +1,79 @@ +--TEST-- +iconv abstraction +--INI-- +psi.directory={PWD}/../../psi.d:{PWD} +--SKIPIF-- + +--FILE-- +===TEST=== +cd = psi\iconv_open($to, $from)) { + throw new Exception(psi\strerror(psi\errno())); + } + } + + function __destruct() { + psi\iconv_close($this->cd); + } + + function update(string $data) : string { + if (0 > psi\iconv($this->cd, $data, $result)) { + throw new Exception(psi\strerror(psi\errno())); + } + return $result; + } +} + +$ic = new iconv_stream("utf8", "latin1"); + +foreach (["föö", "bää", "baßß"] as $str) { + var_dump(array_map("ord", str_split($ic->update($str)))); +} + +$bc = new iconv_stream("latin1", "utf8"); +foreach (["föö", "bää", "baßß"] as $str) { + var_dump($bc->update($ic->update($str))); +} + +?> +===DONE=== +--EXPECT-- +===TEST=== +array(3) { + [0]=> + int(102) + [1]=> + int(246) + [2]=> + int(246) +} +array(3) { + [0]=> + int(98) + [1]=> + int(228) + [2]=> + int(228) +} +array(4) { + [0]=> + int(98) + [1]=> + int(97) + [2]=> + int(223) + [3]=> + int(223) +} +string(5) "föö" +string(5) "bää" +string(6) "baßß" +===DONE===