diff --git a/src/main/php/text/json/Format.class.php b/src/main/php/text/json/Format.class.php index 11afaba..8269057 100755 --- a/src/main/php/text/json/Format.class.php +++ b/src/main/php/text/json/Format.class.php @@ -1,6 +1,7 @@ 'value'; }]; } + /** @return iterable */ + private function blobs() { + yield ['""', new Blob()]; + yield ['"Test"', new Blob(['Test'])]; + yield ['"Test \"the\" west"', new Blob(['Test', ' "the" ', 'west'])]; + yield ['"Test\t"', new Blob(['Test', "\t"])]; + yield ['"Tested"', new Blob(['Test', 'ed'])]; + yield ['"Tested"', new Blob((function() { yield 'Test'; yield 'ed'; })())]; + } + #[Before] public function usePrecision() { self::$precision= ini_set('precision', 14); @@ -147,6 +158,17 @@ public function write_generator($expected, $write) { Assert::equals($expected, $this->write($write())); } + #[Test, Values(from: 'blobs')] + public function write_blob($expected, $write) { + Assert::equals($expected, $this->write($write)); + } + + /** @see https://bugs.php.net/bug.php?id=77069 */ + #[Test, Runtime(php: '>=7.4.14')] + public function write_encoded_blob() { + Assert::equals('"VGVzdA=="', $this->write((new Blob('Test'))->encoded('convert.base64-encode'))); + } + #[Test, Expect(IllegalArgumentException::class)] public function cannot_write_closures() { $this->write(function() { });