tests: do not depend on ctype
[awesomized/ext-ion] / tests / Symbol / Table / Shared.phpt
1 --TEST--
2 ion\Symbol\Table\Shared
3 --EXTENSIONS--
4 ion
5 --FILE--
6 TEST
7 <?php
8
9 $c = new ion\Catalog;
10 $c->add(new ion\Symbol\Table\Shared("shared", 1, ["shared1", "shared2"]));
11 $w = new ion\Writer\Buffer\Writer($buf,
12 new ion\Writer\Options(catalog: $c, outputBinary: true));
13
14 $w->writeSymbol("shared1");
15 $w->writeSymbol("shared1");
16 $w->writeSymbol("shared2");
17 $w->writeSymbol("shared2");
18
19 $w->finish();
20
21 foreach (str_split($buf, 8) as $line) {
22 printf("%-26s", chunk_split(bin2hex($line), 2, " "));
23 foreach (str_split($line) as $byte) {
24 echo $byte >= ' ' && $byte <= '~' ? $byte : ".";
25 }
26 echo "\n";
27 }
28 echo "\n";
29
30 $u = new ion\Unserializer\PHP(multiSequence: true);
31 var_dump($s = $u->unserialize($buf));
32
33 foreach ($s as $sym) {
34 /** @var ion\Symbol $sym */
35 $t = $c->findBest($sym->importLocation->name);
36 $r = $t->findLocal($sym->importLocation->location);
37 printf("%s: %s@%d\n", $r->value, $sym->importLocation->name,
38 $sym->importLocation->location);
39 }
40
41 $u = new ion\Unserializer\PHP(multiSequence: true,
42 readerOptions: new ion\Reader\Options(
43 catalog: $c,
44 onContextChange: fn(ion\Reader $r) => print("on_context_change\n")));
45 var_dump($u->unserialize($buf));
46
47 ?>
48 DONE
49 --EXPECTF--
50 TEST
51 e0 01 00 ea ee 97 81 83 ........
52 de 93 86 be 90 de 8e 84 ........
53 86 73 68 61 72 65 64 85 .shared.
54 21 01 88 21 02 71 0a 71 !..!.q.q
55 0a 71 0b 71 0b .q.q.
56
57 array(4) {
58 [0]=>
59 object(ion\Symbol)#%d (3) {
60 ["value"]=>
61 string(0) ""
62 ["sid"]=>
63 int(10)
64 ["importLocation"]=>
65 object(ion\Symbol\ImportLocation)#%d (2) {
66 ["name"]=>
67 string(6) "shared"
68 ["location"]=>
69 int(1)
70 }
71 }
72 [1]=>
73 object(ion\Symbol)#%d (3) {
74 ["value"]=>
75 string(0) ""
76 ["sid"]=>
77 int(10)
78 ["importLocation"]=>
79 object(ion\Symbol\ImportLocation)#%d (2) {
80 ["name"]=>
81 string(6) "shared"
82 ["location"]=>
83 int(1)
84 }
85 }
86 [2]=>
87 object(ion\Symbol)#%d (3) {
88 ["value"]=>
89 string(0) ""
90 ["sid"]=>
91 int(11)
92 ["importLocation"]=>
93 object(ion\Symbol\ImportLocation)#%d (2) {
94 ["name"]=>
95 string(6) "shared"
96 ["location"]=>
97 int(2)
98 }
99 }
100 [3]=>
101 object(ion\Symbol)#%d (3) {
102 ["value"]=>
103 string(0) ""
104 ["sid"]=>
105 int(11)
106 ["importLocation"]=>
107 object(ion\Symbol\ImportLocation)#%d (2) {
108 ["name"]=>
109 string(6) "shared"
110 ["location"]=>
111 int(2)
112 }
113 }
114 }
115 shared1: shared@1
116 shared1: shared@1
117 shared2: shared@2
118 shared2: shared@2
119 on_context_change
120 array(4) {
121 [0]=>
122 object(ion\Symbol)#%d (3) {
123 ["value"]=>
124 string(7) "shared1"
125 ["sid"]=>
126 int(10)
127 ["importLocation"]=>
128 object(ion\Symbol\ImportLocation)#%d (2) {
129 ["name"]=>
130 string(6) "shared"
131 ["location"]=>
132 int(1)
133 }
134 }
135 [1]=>
136 object(ion\Symbol)#%d (3) {
137 ["value"]=>
138 string(7) "shared1"
139 ["sid"]=>
140 int(10)
141 ["importLocation"]=>
142 object(ion\Symbol\ImportLocation)#%d (2) {
143 ["name"]=>
144 string(6) "shared"
145 ["location"]=>
146 int(1)
147 }
148 }
149 [2]=>
150 object(ion\Symbol)#%d (3) {
151 ["value"]=>
152 string(7) "shared2"
153 ["sid"]=>
154 int(11)
155 ["importLocation"]=>
156 object(ion\Symbol\ImportLocation)#%d (2) {
157 ["name"]=>
158 string(6) "shared"
159 ["location"]=>
160 int(2)
161 }
162 }
163 [3]=>
164 object(ion\Symbol)#%d (3) {
165 ["value"]=>
166 string(7) "shared2"
167 ["sid"]=>
168 int(11)
169 ["importLocation"]=>
170 object(ion\Symbol\ImportLocation)#%d (2) {
171 ["name"]=>
172 string(6) "shared"
173 ["location"]=>
174 int(2)
175 }
176 }
177 }
178 DONE