PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/hphp/test/zend/good/ext/json/tests/pass001.php

http://github.com/facebook/hiphop-php
PHP | 85 lines | 76 code | 8 blank | 1 comment | 0 complexity | 20a46718a642352634c85fdb21fa473d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. // Expect warnings about INF.
  3. <<__EntryPoint>> function main(): void {
  4. ini_set("error_reporting", E_ALL & ~E_WARNING);
  5. $test = "
  6. [
  7. \"JSON Test Pattern pass1\",
  8. {\"object with 1 member\":[\"array with 1 element\"]},
  9. {},
  10. [],
  11. -42,
  12. true,
  13. false,
  14. null,
  15. {
  16. \"integer\": 1234567890,
  17. \"real\": -9876.543210,
  18. \"e\": 0.123456789e-12,
  19. \"E\": 1.234567890E+34,
  20. \"\": 23456789012E666,
  21. \"zero\": 0,
  22. \"one\": 1,
  23. \"space\": \" \",
  24. \"quote\": \"\\\"\",
  25. \"backslash\": \"\\\\\",
  26. \"controls\": \"\\b\\f\\n\\r\\t\",
  27. \"slash\": \"/ & \\/\",
  28. \"alpha\": \"abcdefghijklmnopqrstuvwyz\",
  29. \"ALPHA\": \"ABCDEFGHIJKLMNOPQRSTUVWYZ\",
  30. \"digit\": \"0123456789\",
  31. \"special\": \"`1~!@#$%^&*()_+-={':[,]}|;.</>?\",
  32. \"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\",
  33. \"true\": true,
  34. \"false\": false,
  35. \"null\": null,
  36. \"array\":[ ],
  37. \"object\":{ },
  38. \"address\": \"50 St. James Street\",
  39. \"url\": \"http://www.JSON.org/\",
  40. \"comment\": \"// /* <!-- --\",
  41. \"# -- --> */\": \" \",
  42. \" s p a c e d \" :[1,2 , 3
  43. ,
  44. 4 , 5 , 6 ,7 ],
  45. \"compact\": [1,2,3,4,5,6,7],
  46. \"jsontext\": \"{\\\"object with 1 member\\\":[\\\"array with 1 element\\\"]}\",
  47. \"quotes\": \"&#34; \\u0022 %22 0x22 034 &#x22;\",
  48. \"\\/\\\\\\\"\\uCAFE\\uBABE\\uAB98\\uFCDE\\ubcda\\uef4A\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?\"
  49. : \"A key can be any string\"
  50. },
  51. 0.5 ,98.6
  52. ,
  53. 99.44
  54. ,
  55. 1066
  56. ,\"rosebud\"]
  57. ";
  58. echo 'Testing: ' . $test . "\n";
  59. echo "DECODE: AS OBJECT\n";
  60. $obj = json_decode($test);
  61. var_dump($obj);
  62. echo "DECODE: AS ARRAY\n";
  63. $arr = json_decode($test, true);
  64. var_dump($arr);
  65. echo "ENCODE: FROM OBJECT\n";
  66. $obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR);
  67. echo $obj_enc . "\n";
  68. echo "ENCODE: FROM ARRAY\n";
  69. $arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR);
  70. echo $arr_enc . "\n";
  71. echo "DECODE AGAIN: AS OBJECT\n";
  72. $obj = json_decode($obj_enc);
  73. var_dump($obj);
  74. echo "DECODE AGAIN: AS ARRAY\n";
  75. $arr = json_decode($arr_enc, true);
  76. var_dump($arr);
  77. }