seriously simplify the buffer writer by not accepting a ref to a buffer
[awesomized/ext-ion] / tests / Symbol / Table / Shared.phpt
index 2d51c48a731c4f810da0a9c46ee735abd91adefc..1a052dbbf0e01ff393748b1d72e6abc1f59fceec 100644 (file)
@@ -8,8 +8,7 @@ TEST
 
 $c = new ion\Catalog;
 $c->add(new ion\Symbol\Table\Shared("shared", 1, ["shared1", "shared2"]));
-$w = new ion\Writer\Buffer\Writer($buf,
-       new ion\Writer\Options(catalog: $c, outputBinary: true));
+$w = new ion\Writer\Buffer\Writer(new ion\Writer\Options(catalog: $c, outputBinary: true));
 
 $w->writeSymbol("shared1");
 $w->writeSymbol("shared1");
@@ -18,21 +17,31 @@ $w->writeSymbol("shared2");
 
 $w->finish();
 
-foreach (str_split($buf, 8) as $line) {
+foreach (str_split($w->getBuffer(), 8) as $line) {
        printf("%-26s", chunk_split(bin2hex($line), 2, " "));
        foreach (str_split($line) as $byte) {
-               echo ctype_print($byte) ? $byte : ".";
+               echo $byte >= ' ' && $byte <= '~' ? $byte : ".";
        }
        echo "\n";
 }
 echo "\n";
 
 $u = new ion\Unserializer\PHP(multiSequence: true);
-var_dump($u($buf));
+var_dump($s = $u->unserialize($w->getBuffer()));
+
+foreach ($s as $sym) {
+       /** @var ion\Symbol $sym */
+       $t = $c->findBest($sym->importLocation->name);
+       $r = $t->findLocal($sym->importLocation->location);
+       printf("%s: %s@%d\n", $r->value, $sym->importLocation->name,
+               $sym->importLocation->location);
+}
 
 $u = new ion\Unserializer\PHP(multiSequence: true,
-       readerOptions: new ion\Reader\Options(catalog: $c));
-var_dump($u($buf));
+       readerOptions: new ion\Reader\Options(
+               catalog: $c,
+               onContextChange: fn(ion\Reader $r) => print("on_context_change\n")));
+var_dump($u->unserialize($w->getBuffer()));
 
 ?>
 DONE
@@ -102,6 +111,10 @@ array(4) {
     }
   }
 }
+shared1: shared@1
+shared1: shared@1
+shared2: shared@2
+shared2: shared@2
 on_context_change
 array(4) {
   [0]=>