PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/include/spyc/test.php5

https://github.com/radicaldesigns/amp
PHP | 160 lines | 123 code | 14 blank | 23 comment | 22 complexity | ea540295aafe1a154271a82fa4a5bdec MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. #
  3. # S P Y C
  4. # a simple php yaml class
  5. # v0.2(.5)
  6. #
  7. # author: [chris wanstrath, chris@ozmm.org]
  8. # websites: [http://www.yaml.org, http://spyc.sourceforge.net/]
  9. # license: [MIT License, http://www.opensource.org/licenses/mit-license.php]
  10. # copyright: (c) 2005-2006 Chris Wanstrath
  11. #
  12. # We're gonna load a file into memory and see if we get what we expect.
  13. # If not, we're gonna complain.
  14. #
  15. # Pretty lo-fi. Let's see if we can't get some unit testing going in the next,
  16. # I dunno, 20 months? Alright. Go team.
  17. #
  18. error_reporting(E_STRICT);
  19. include('spyc.php5');
  20. $yaml = Spyc::YAMLLoad('spyc.yaml');
  21. // print_r ($yaml);
  22. # Added in .2
  23. if ($yaml[1040] != "Ooo, a numeric key!")
  24. die('Key: 1040 failed');
  25. # Test mappings / types
  26. if ($yaml['String'] != "Anyone's name, really.")
  27. die('Key: String failed');
  28. if ($yaml['Int'] !== 13)
  29. die('Key: Int failed');
  30. if ($yaml['True'] !== true)
  31. die('Key: True failed');
  32. if ($yaml['False'] !== false)
  33. die('Key: False failed');
  34. if ($yaml['Zero'] !== 0)
  35. die('Key: Zero failed');
  36. if ($yaml['Null'] !== NULL)
  37. die('Key: Null failed');
  38. if ($yaml['Float'] !== 5.34)
  39. die('Key: Float failed');
  40. # Test sequences
  41. if ($yaml[0] != "PHP Class")
  42. die('Sequence 0 failed');
  43. if ($yaml[1] != "Basic YAML Loader")
  44. die('Sequence 1 failed');
  45. if ($yaml[2] != "Very Basic YAML Dumper")
  46. die('Sequence 2 failed');
  47. # A sequence of a sequence
  48. if ($yaml[3] != array("YAML is so easy to learn.",
  49. "Your config files will never be the same."))
  50. die('Sequence 3 failed');
  51. # Sequence of mappings
  52. if ($yaml[4] != array("cpu" => "1.5ghz", "ram" => "1 gig",
  53. "os" => "os x 10.4.1"))
  54. die('Sequence 4 failed');
  55. # Mapped sequence
  56. if ($yaml['domains'] != array("yaml.org", "php.net"))
  57. die("Key: 'domains' failed");
  58. # A sequence like this.
  59. if ($yaml[5] != array("program" => "Adium", "platform" => "OS X",
  60. "type" => "Chat Client"))
  61. die('Sequence 5 failed');
  62. # A folded block as a mapped value
  63. if ($yaml['no time'] != "There isn't any time for your tricks! \nDo you understand?")
  64. die("Key: 'no time' failed");
  65. # A literal block as a mapped value
  66. if ($yaml['some time'] != "There is nothing but time\nfor your tricks.")
  67. die("Key: 'some time' failed");
  68. # Crazy combinations
  69. if ($yaml['databases'] != array( array("name" => "spartan", "notes" =>
  70. array( "Needs to be backed up",
  71. "Needs to be normalized" ),
  72. "type" => "mysql" )))
  73. die("Key: 'databases' failed");
  74. # You can be a bit tricky
  75. if ($yaml["if: you'd"] != "like")
  76. die("Key: 'if: you\'d' failed");
  77. # Inline sequences
  78. if ($yaml[6] != array("One", "Two", "Three", "Four"))
  79. die("Sequence 6 failed");
  80. # Nested Inline Sequences
  81. if ($yaml[7] != array("One", array("Two", "And", "Three"), "Four", "Five"))
  82. die("Sequence 7 failed");
  83. # Nested Nested Inline Sequences
  84. if ($yaml[8] != array( "This", array("Is", "Getting", array("Ridiculous", "Guys")),
  85. "Seriously", array("Show", "Mercy")))
  86. die("Sequence 8 failed");
  87. # Inline mappings
  88. if ($yaml[9] != array("name" => "chris", "age" => "young", "brand" => "lucky strike"))
  89. die("Sequence 9 failed");
  90. # Nested inline mappings
  91. if ($yaml[10] != array("name" => "mark", "age" => "older than chris",
  92. "brand" => array("marlboro", "lucky strike")))
  93. die("Sequence 10 failed");
  94. # References -- they're shaky, but functional
  95. if ($yaml['dynamic languages'] != array('Perl', 'Python', 'PHP', 'Ruby'))
  96. die("Key: 'dynamic languages' failed");
  97. if ($yaml['compiled languages'] != array('C/C++', 'Java'))
  98. die("Key: 'compiled languages' failed");
  99. if ($yaml['all languages'] != array(
  100. array('Perl', 'Python', 'PHP', 'Ruby'),
  101. array('C/C++', 'Java')
  102. ))
  103. die("Key: 'all languages' failed");
  104. # Added in .2.2: Escaped quotes
  105. if ($yaml[11] != "you know, this shouldn't work. but it does.")
  106. die("Sequence 11 failed.");
  107. if ($yaml[12] != "that's my value.")
  108. die("Sequence 12 failed.");
  109. if ($yaml[13] != "again, that's my value.")
  110. die("Sequence 13 failed.");
  111. if ($yaml[14] != "here's to \"quotes\", boss.")
  112. die("Sequence 14 failed.");
  113. if ($yaml[15] != array( 'name' => "Foo, Bar's", 'age' => 20))
  114. die("Sequence 15 failed.");
  115. if ($yaml[16] != array( 0 => "a", 1 => array (0 => 1, 1 => 2), 2 => "b"))
  116. die("Sequence 16 failed.");
  117. print "spyc.yaml parsed correctly\n";
  118. ?>