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