createStub(Func::class); $mc->method('isMacro')->willReturn(true); $fn = $this->createStub(Func::class); $fn->method('isMacro')->willReturn(false); return [ [$mc, ''], [$fn, ''], [new MList([new Symbol('aa'), new Symbol('bb'), new MList([new Symbol('cc')])]), '(aa bb (cc))'], [new Vector([12, 34, new Vector([56])]), '[12 34 [56]]'], [new Hash(['aa' => 'bb', 'cc' => new Hash(['dd' => 'ee'])]), '{aa:bb cc:{dd:ee}}'], [new Symbol('abc'), 'abc'], [new \stdClass(), '>'], [true, 'true'], [false, 'false'], [null, 'null'], [123, '123'], [34.56, '34.56'], // Test strings ['abc', 'abc'], ["a\\b\nc\rd\te\"f", "a\\b\nc\rd\te\"f"], ]; } /** * @dataProvider notReadableProvider */ public function testPrintNotReadable($input, string $expected) { $printer = new Printer(); $result = $printer->pstr($input, false); $this->assertSame($expected, $result); } public function readableProvider(): array { return [ [new Hash(['aa' => 'bb', 'cc' => new Hash(['dd' => 'ee'])]), '{"aa":"bb" "cc":{"dd":"ee"}}'], [new Symbol('abc'), 'abc'], // symbol is not quoted // Test strings ['abc', '"abc"'], ["a\\b\nc\rd\te\"f", "\"a\\\\b\\nc\\rd\\te\\\"f\""], ]; } /** * @dataProvider readableProvider */ public function testPrintReadable($input, string $expected) { $printer = new Printer(); $result = $printer->pstr($input, true); $this->assertSame($expected, $result); } public function testPrintResource() { $file = tmpfile(); $printer = new Printer(); $result = $printer->pstr($file, false); $this->assertSame('', $result); fclose($file); } }