ensure proper default initialization
[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 ctype_print($byte) ? $byte : ".";
25 }
26 echo "\n";
27 }
28 echo "\n";
29
30 $u = new ion\Unserializer\PHP(multiSequence: true);
31 var_dump($u($buf));
32
33 $u = new ion\Unserializer\PHP(multiSequence: true,
34 readerOptions: new ion\Reader\Options(
35 catalog: $c,
36 onContextChange: fn(ion\Reader $r) => print("on_context_change\n")));
37 var_dump($u($buf));
38
39 ?>
40 DONE
41 --EXPECTF--
42 TEST
43 e0 01 00 ea ee 97 81 83 ........
44 de 93 86 be 90 de 8e 84 ........
45 86 73 68 61 72 65 64 85 .shared.
46 21 01 88 21 02 71 0a 71 !..!.q.q
47 0a 71 0b 71 0b .q.q.
48
49 array(4) {
50 [0]=>
51 object(ion\Symbol)#%d (3) {
52 ["value"]=>
53 string(0) ""
54 ["sid"]=>
55 int(10)
56 ["importLocation"]=>
57 object(ion\Symbol\ImportLocation)#%d (2) {
58 ["name"]=>
59 string(6) "shared"
60 ["location"]=>
61 int(1)
62 }
63 }
64 [1]=>
65 object(ion\Symbol)#%d (3) {
66 ["value"]=>
67 string(0) ""
68 ["sid"]=>
69 int(10)
70 ["importLocation"]=>
71 object(ion\Symbol\ImportLocation)#%d (2) {
72 ["name"]=>
73 string(6) "shared"
74 ["location"]=>
75 int(1)
76 }
77 }
78 [2]=>
79 object(ion\Symbol)#%d (3) {
80 ["value"]=>
81 string(0) ""
82 ["sid"]=>
83 int(11)
84 ["importLocation"]=>
85 object(ion\Symbol\ImportLocation)#%d (2) {
86 ["name"]=>
87 string(6) "shared"
88 ["location"]=>
89 int(2)
90 }
91 }
92 [3]=>
93 object(ion\Symbol)#%d (3) {
94 ["value"]=>
95 string(0) ""
96 ["sid"]=>
97 int(11)
98 ["importLocation"]=>
99 object(ion\Symbol\ImportLocation)#%d (2) {
100 ["name"]=>
101 string(6) "shared"
102 ["location"]=>
103 int(2)
104 }
105 }
106 }
107 on_context_change
108 array(4) {
109 [0]=>
110 object(ion\Symbol)#%d (3) {
111 ["value"]=>
112 string(7) "shared1"
113 ["sid"]=>
114 int(10)
115 ["importLocation"]=>
116 object(ion\Symbol\ImportLocation)#%d (2) {
117 ["name"]=>
118 string(6) "shared"
119 ["location"]=>
120 int(1)
121 }
122 }
123 [1]=>
124 object(ion\Symbol)#%d (3) {
125 ["value"]=>
126 string(7) "shared1"
127 ["sid"]=>
128 int(10)
129 ["importLocation"]=>
130 object(ion\Symbol\ImportLocation)#%d (2) {
131 ["name"]=>
132 string(6) "shared"
133 ["location"]=>
134 int(1)
135 }
136 }
137 [2]=>
138 object(ion\Symbol)#%d (3) {
139 ["value"]=>
140 string(7) "shared2"
141 ["sid"]=>
142 int(11)
143 ["importLocation"]=>
144 object(ion\Symbol\ImportLocation)#%d (2) {
145 ["name"]=>
146 string(6) "shared"
147 ["location"]=>
148 int(2)
149 }
150 }
151 [3]=>
152 object(ion\Symbol)#%d (3) {
153 ["value"]=>
154 string(7) "shared2"
155 ["sid"]=>
156 int(11)
157 ["importLocation"]=>
158 object(ion\Symbol\ImportLocation)#%d (2) {
159 ["name"]=>
160 string(6) "shared"
161 ["location"]=>
162 int(2)
163 }
164 }
165 }
166 DONE