summaryrefslogtreecommitdiff
path: root/ext/json/tests
diff options
context:
space:
mode:
authorJuan Basso <jrbasso@gmail.com>2015-01-12 21:29:52 -0500
committerJuan Basso <jrbasso@gmail.com>2015-01-12 21:29:52 -0500
commit95cef47afb0b5329915a178d34cf27efcb54607b (patch)
treef8a1ff72cb29166cbad04df3ec035dc18dad40e0 /ext/json/tests
parente6fb493e5dbafdad37ba5334c986636342b5d9aa (diff)
downloadphp-git-95cef47afb0b5329915a178d34cf27efcb54607b.tar.gz
Porting implementation of RFC json_preserve_fractional_part
Diffstat (limited to 'ext/json/tests')
-rw-r--r--ext/json/tests/bug50224.phpt60
1 files changed, 60 insertions, 0 deletions
diff --git a/ext/json/tests/bug50224.phpt b/ext/json/tests/bug50224.phpt
new file mode 100644
index 0000000000..3408ac906f
--- /dev/null
+++ b/ext/json/tests/bug50224.phpt
@@ -0,0 +1,60 @@
+--TEST--
+bug #50224 (json_encode() does not always encode a float as a float)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+echo "* Testing JSON output\n\n";
+var_dump(json_encode(12.3, JSON_PRESERVE_ZERO_FRACTION));
+var_dump(json_encode(12, JSON_PRESERVE_ZERO_FRACTION));
+var_dump(json_encode(12.0, JSON_PRESERVE_ZERO_FRACTION));
+var_dump(json_encode(0.0, JSON_PRESERVE_ZERO_FRACTION));
+var_dump(json_encode(array(12, 12.0, 12.3), JSON_PRESERVE_ZERO_FRACTION));
+var_dump(json_encode((object)array('float' => 12.0, 'integer' => 12), JSON_PRESERVE_ZERO_FRACTION));
+
+echo "\n* Testing encode/decode symmetry\n\n";
+
+var_dump(json_decode(json_encode(12.3, JSON_PRESERVE_ZERO_FRACTION)));
+var_dump(json_decode(json_encode(12, JSON_PRESERVE_ZERO_FRACTION)));
+var_dump(json_decode(json_encode(12.0, JSON_PRESERVE_ZERO_FRACTION)));
+var_dump(json_decode(json_encode(0.0, JSON_PRESERVE_ZERO_FRACTION)));
+var_dump(json_decode(json_encode(array(12, 12.0, 12.3), JSON_PRESERVE_ZERO_FRACTION)));
+var_dump(json_decode(json_encode((object)array('float' => 12.0, 'integer' => 12), JSON_PRESERVE_ZERO_FRACTION)));
+var_dump(json_decode(json_encode((object)array('float' => 12.0, 'integer' => 12), JSON_PRESERVE_ZERO_FRACTION), true));
+?>
+--EXPECTF--
+* Testing JSON output
+
+string(4) "12.3"
+string(2) "12"
+string(4) "12.0"
+string(3) "0.0"
+string(14) "[12,12.0,12.3]"
+string(27) "{"float":12.0,"integer":12}"
+
+* Testing encode/decode symmetry
+
+float(12.3)
+int(12)
+float(12)
+float(0)
+array(3) {
+ [0]=>
+ int(12)
+ [1]=>
+ float(12)
+ [2]=>
+ float(12.3)
+}
+object(stdClass)#%d (2) {
+ ["float"]=>
+ float(12)
+ ["integer"]=>
+ int(12)
+}
+array(2) {
+ ["float"]=>
+ float(12)
+ ["integer"]=>
+ int(12)
+} \ No newline at end of file