Skip to content

Commit a3c79d9

Browse files
committed
add testswq
1 parent 8de59d7 commit a3c79d9

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
vendor/
2-
tests/
32
*.swp

tests/test.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
error_reporting(-1);
3+
ini_set('implicit_flush', 0);
4+
require(__DIR__.'/../vendor/autoload.php');
5+
use wrossmann\json_stream\JsonStream;
6+
7+
function test($obj) {
8+
$handle = fopen('php://memory', 'rwb');
9+
$js = new JsonStream($handle);
10+
11+
$js->encode($obj);
12+
rewind($handle);
13+
$js_out = stream_get_contents($handle);
14+
15+
$stock_out = json_encode($obj);
16+
17+
if( $js_out !== $stock_out ) {
18+
printf("FAIL:\n\t%s\n\t%s\n", $js_out, $stock_out);
19+
}
20+
21+
return $js_out === $stock_out;
22+
}
23+
24+
$tests = [
25+
0, 1, 2, true, false, null,
26+
"", "\0", "a", "abc", "klâwen",
27+
[], [0], [1], [0,1,2,3],
28+
[0,1,2,3,4=>4], [0,1,2,3,5=>5]
29+
];
30+
$testobject = new stdClass();
31+
$testobject->foo = $tests;
32+
33+
$tests[] = $testobject;
34+
35+
36+
$res = true;
37+
foreach($tests as $test) {
38+
$res = test($test) && $res;
39+
}
40+
41+
echo ($res ? "PASS" : "FAIL") . PHP_EOL;
42+
43+
exit( $res ? 0 : 1 );

0 commit comments

Comments
 (0)