RoundTripTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. require_once ("../Spyc.php");
  3. function roundTrip($a) { return Spyc::YAMLLoad(Spyc::YAMLDump(array('x' => $a))); }
  4. class RoundTripTest extends PHPUnit_Framework_TestCase {
  5. protected function setUp() {
  6. }
  7. public function testNull() {
  8. $this->assertEquals (array ('x' => null), roundTrip (null));
  9. }
  10. public function testY() {
  11. $this->assertEquals (array ('x' => 'y'), roundTrip ('y'));
  12. }
  13. public function testExclam() {
  14. $this->assertEquals (array ('x' => '!yeah'), roundTrip ('!yeah'));
  15. }
  16. public function test5() {
  17. $this->assertEquals (array ('x' => '5'), roundTrip ('5'));
  18. }
  19. public function testSpaces() {
  20. $this->assertEquals (array ('x' => 'x '), roundTrip ('x '));
  21. }
  22. public function testApostrophes() {
  23. $this->assertEquals (array ('x' => "'biz'"), roundTrip ("'biz'"));
  24. }
  25. public function testNewLines() {
  26. $this->assertEquals (array ('x' => "\n"), roundTrip ("\n"));
  27. }
  28. public function testHashes() {
  29. $this->assertEquals (array ('x' => array ("#color" => '#fff')), roundTrip (array ("#color" => '#fff')));
  30. }
  31. public function testPreserveString() {
  32. $result1 = roundTrip ('0');
  33. $result2 = roundTrip ('true');
  34. $this->assertTrue (is_string ($result1['x']));
  35. $this->assertTrue (is_string ($result2['x']));
  36. }
  37. public function testPreserveBool() {
  38. $result = roundTrip (true);
  39. $this->assertTrue (is_bool ($result['x']));
  40. }
  41. public function testPreserveInteger() {
  42. $result = roundTrip (0);
  43. $this->assertTrue (is_int ($result['x']));
  44. }
  45. public function testWordWrap() {
  46. $this->assertEquals (array ('x' => "aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), roundTrip ("aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"));
  47. }
  48. public function testABCD() {
  49. $this->assertEquals (array ('a', 'b', 'c', 'd'), Spyc::YAMLLoad(Spyc::YAMLDump(array('a', 'b', 'c', 'd'))));
  50. }
  51. public function testABCD2() {
  52. $a = array('a', 'b', 'c', 'd'); // Create a simple list
  53. $b = Spyc::YAMLDump($a); // Dump the list as YAML
  54. $c = Spyc::YAMLLoad($b); // Load the dumped YAML
  55. $d = Spyc::YAMLDump($c); // Re-dump the data
  56. $this->assertSame($b, $d);
  57. }
  58. }