improve catalog support; depends on amzn/ion-c#271
[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(catalog: $c));
35 var_dump($u($buf));
36
37 ?>
38 DONE
39 --EXPECTF--
40 TEST
41 e0 01 00 ea ee 97 81 83 ........
42 de 93 86 be 90 de 8e 84 ........
43 86 73 68 61 72 65 64 85 .shared.
44 21 01 88 21 02 71 0a 71 !..!.q.q
45 0a 71 0b 71 0b .q.q.
46
47 array(4) {
48 [0]=>
49 object(ion\Symbol)#%d (3) {
50 ["value"]=>
51 string(0) ""
52 ["sid"]=>
53 int(10)
54 ["importLocation"]=>
55 object(ion\Symbol\ImportLocation)#%d (2) {
56 ["name"]=>
57 string(6) "shared"
58 ["location"]=>
59 int(1)
60 }
61 }
62 [1]=>
63 object(ion\Symbol)#%d (3) {
64 ["value"]=>
65 string(0) ""
66 ["sid"]=>
67 int(10)
68 ["importLocation"]=>
69 object(ion\Symbol\ImportLocation)#%d (2) {
70 ["name"]=>
71 string(6) "shared"
72 ["location"]=>
73 int(1)
74 }
75 }
76 [2]=>
77 object(ion\Symbol)#%d (3) {
78 ["value"]=>
79 string(0) ""
80 ["sid"]=>
81 int(11)
82 ["importLocation"]=>
83 object(ion\Symbol\ImportLocation)#%d (2) {
84 ["name"]=>
85 string(6) "shared"
86 ["location"]=>
87 int(2)
88 }
89 }
90 [3]=>
91 object(ion\Symbol)#%d (3) {
92 ["value"]=>
93 string(0) ""
94 ["sid"]=>
95 int(11)
96 ["importLocation"]=>
97 object(ion\Symbol\ImportLocation)#%d (2) {
98 ["name"]=>
99 string(6) "shared"
100 ["location"]=>
101 int(2)
102 }
103 }
104 }
105 on_context_change
106 array(4) {
107 [0]=>
108 object(ion\Symbol)#%d (3) {
109 ["value"]=>
110 string(7) "shared1"
111 ["sid"]=>
112 int(10)
113 ["importLocation"]=>
114 object(ion\Symbol\ImportLocation)#%d (2) {
115 ["name"]=>
116 string(6) "shared"
117 ["location"]=>
118 int(1)
119 }
120 }
121 [1]=>
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 [2]=>
136 object(ion\Symbol)#%d (3) {
137 ["value"]=>
138 string(7) "shared2"
139 ["sid"]=>
140 int(11)
141 ["importLocation"]=>
142 object(ion\Symbol\ImportLocation)#%d (2) {
143 ["name"]=>
144 string(6) "shared"
145 ["location"]=>
146 int(2)
147 }
148 }
149 [3]=>
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 }
164 DONE