test.php4 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. #
  3. # S P Y C
  4. # a simple php yaml class
  5. # v0.3
  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_ALL);
  19. include('spyc.php4');
  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 (isset($yaml['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. if ($yaml['endloop'] != "Does this line in the end indeed make Spyc go to an infinite loop?")
  118. die("[endloop] failed.");
  119. print "spyc.yaml parsed correctly\n";
  120. ?>