travis: update
[m6w6/ext-psi] / tests / iconv / iconv002.phpt
1 --TEST--
2 iconv abstraction
3 --INI--
4 psi.directory={PWD}/../../psi.d:{PWD}
5 --FILE--
6 ===TEST===
7 <?php
8
9 class iconv_stream {
10 private $cd;
11
12 function __construct($from, $to) {
13 if (!$this->cd = psi\iconv_open($to, $from)) {
14 throw new Exception(psi\strerror(psi\errno()));
15 }
16 }
17
18 function __destruct() {
19 psi\iconv_close($this->cd);
20 }
21
22 function update(string $data) : string {
23 if (0 > psi\iconv($this->cd, $data, $result)) {
24 throw new Exception(psi\strerror(psi\errno()));
25 }
26 return $result;
27 }
28 }
29
30 $ic = new iconv_stream("utf8", "latin1");
31
32 foreach (["föö", "bää", "baßß"] as $str) {
33 var_dump(array_map("ord", str_split($ic->update($str))));
34 }
35
36 $bc = new iconv_stream("latin1", "utf8");
37 foreach (["föö", "bää", "baßß"] as $str) {
38 var_dump($bc->update($ic->update($str)));
39 }
40
41 ?>
42 ===DONE===
43 --EXPECT--
44 ===TEST===
45 array(3) {
46 [0]=>
47 int(102)
48 [1]=>
49 int(246)
50 [2]=>
51 int(246)
52 }
53 array(3) {
54 [0]=>
55 int(98)
56 [1]=>
57 int(228)
58 [2]=>
59 int(228)
60 }
61 array(4) {
62 [0]=>
63 int(98)
64 [1]=>
65 int(97)
66 [2]=>
67 int(223)
68 [3]=>
69 int(223)
70 }
71 string(5) "föö"
72 string(5) "bää"
73 string(6) "baßß"
74 ===DONE===