ref: c9bce433f7481ccb2412b9914f6e92703341f4bf
converter/server/vendor/mustangostang/spyc/tests/DumpTest.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
<?php require_once ("../Spyc.php"); class DumpTest extends PHPUnit_Framework_TestCase { private $files_to_test = array(); public function setUp() { $this->files_to_test = array ('../spyc.yaml', 'failing1.yaml', 'indent_1.yaml', 'quotes.yaml'); } public function testShortSyntax() { $dump = spyc_dump(array ('item1', 'item2', 'item3')); $awaiting = "- item1\n- item2\n- item3\n"; $this->assertEquals ($awaiting, $dump); } public function testDump() { foreach ($this->files_to_test as $file) { $yaml = spyc_load(file_get_contents($file)); $dump = Spyc::YAMLDump ($yaml); $yaml_after_dump = Spyc::YAMLLoad ($dump); $this->assertEquals ($yaml, $yaml_after_dump); } } public function testDumpWithQuotes() { $Spyc = new Spyc(); $Spyc->setting_dump_force_quotes = true; foreach ($this->files_to_test as $file) { $yaml = $Spyc->load(file_get_contents($file)); $dump = $Spyc->dump ($yaml); $yaml_after_dump = Spyc::YAMLLoad ($dump); $this->assertEquals ($yaml, $yaml_after_dump); } } public function testDumpArrays() { $dump = Spyc::YAMLDump(array ('item1', 'item2', 'item3')); $awaiting = "---\n- item1\n- item2\n- item3\n"; $this->assertEquals ($awaiting, $dump); } public function testNull() { $dump = Spyc::YAMLDump(array('a' => 1, 'b' => null, 'c' => 3)); $awaiting = "---\na: 1\nb: null\nc: 3\n"; $this->assertEquals ($awaiting, $dump); } public function testNext() { $array = array("aaa", "bbb", "ccc"); #set arrays internal pointer to next element next($array); $dump = Spyc::YAMLDump($array); $awaiting = "---\n- aaa\n- bbb\n- ccc\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpingMixedArrays() { $array = array(); $array[] = 'Sequence item'; $array['The Key'] = 'Mapped value'; $array[] = array('A sequence','of a sequence'); $array[] = array('first' => 'A sequence','second' => 'of mapped values'); $array['Mapped'] = array('A sequence','which is mapped'); $array['A Note'] = 'What if your text is too long?'; $array['Another Note'] = 'If that is the case, the dumper will probably fold your text by using a block. Kinda like this.'; $array['The trick?'] = 'The trick is that we overrode the default indent, 2, to 4 and the default wordwrap, 40, to 60.'; $array['Old Dog'] = "And if you want\n to preserve line breaks, \ngo ahead!"; $array['key:withcolon'] = "Should support this to"; $yaml = Spyc::YAMLDump($array,4,60); } public function testMixed() { $dump = Spyc::YAMLDump(array(0 => 1, 'b' => 2, 1 => 3)); $awaiting = "---\n0: 1\nb: 2\n1: 3\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpNumerics() { $dump = Spyc::YAMLDump(array ('404', '405', '500')); $awaiting = "---\n- \"404\"\n- \"405\"\n- \"500\"\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpAsterisks() { $dump = Spyc::YAMLDump(array ('*')); $awaiting = "---\n- '*'\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpAmpersands() { $dump = Spyc::YAMLDump(array ('some' => '&foo')); $awaiting = "---\nsome: '&foo'\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpExclamations() { $dump = Spyc::YAMLDump(array ('some' => '!foo')); $awaiting = "---\nsome: '!foo'\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpExclamations2() { $dump = Spyc::YAMLDump(array ('some' => 'foo!')); $awaiting = "---\nsome: foo!\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpApostrophes() { $dump = Spyc::YAMLDump(array ('some' => "'Biz' pimpt bedrijventerreinen")); $awaiting = "---\nsome: \"'Biz' pimpt bedrijventerreinen\"\n"; $this->assertEquals ($awaiting, $dump); } public function testDumpNumericHashes() { $dump = Spyc::YAMLDump(array ("titel"=> array("0" => "", 1 => "Dr.", 5 => "Prof.", 6 => "Prof. Dr."))); $awaiting = "---\ntitel:\n 0: \"\"\n 1: Dr.\n 5: Prof.\n 6: Prof. Dr.\n"; $this->assertEquals ($awaiting, $dump); } public function testEmpty() { $dump = Spyc::YAMLDump(array("foo" => array())); $awaiting = "---\nfoo: [ ]\n"; $this->assertEquals ($awaiting, $dump); } public function testHashesInKeys() { $dump = Spyc::YAMLDump(array ('#color' => '#ffffff')); $awaiting = "---\n\"#color\": '#ffffff'\n"; $this->assertEquals ($awaiting, $dump); } public function testParagraph() { $dump = Spyc::YAMLDump(array ('key' => "|\n value")); $awaiting = "---\nkey: |\n value\n"; $this->assertEquals ($awaiting, $dump); } public function testParagraphTwo() { $dump = Spyc::YAMLDump(array ('key' => 'Congrats, pimpt bedrijventerreinen pimpt bedrijventerreinen pimpt bedrijventerreinen!')); $awaiting = "---\nkey: >\n Congrats, pimpt bedrijventerreinen pimpt\n bedrijventerreinen pimpt\n bedrijventerreinen!\n"; $this->assertEquals ($awaiting, $dump); } public function testString() { $dump = Spyc::YAMLDump(array ('key' => array('key_one' => 'Congrats, pimpt bedrijventerreinen!'))); $awaiting = "---\nkey:\n key_one: Congrats, pimpt bedrijventerreinen!\n"; $this->assertEquals ($awaiting, $dump); } public function testStringLong() { $dump = Spyc::YAMLDump(array ('key' => array('key_one' => 'Congrats, pimpt bedrijventerreinen pimpt bedrijventerreinen pimpt bedrijventerreinen!'))); $awaiting = "---\nkey:\n key_one: >\n Congrats, pimpt bedrijventerreinen pimpt\n bedrijventerreinen pimpt\n bedrijventerreinen!\n"; $this->assertEquals ($awaiting, $dump); } public function testStringDoubleQuote() { $dump = Spyc::YAMLDump(array ('key' => array('key_one' => array('key_two' => '"Système d\'e-réservation"')))); $awaiting = "---\nkey:\n key_one:\n key_two: |\n Système d'e-réservation\n"; $this->assertEquals ($awaiting, $dump); } public function testLongStringDoubleQuote() { $dump = Spyc::YAMLDump(array ('key' => array('key_one' => array('key_two' => '"Système d\'e-réservation bedrijventerreinen pimpt" bedrijventerreinen!')))); $awaiting = "---\nkey:\n key_one:\n key_two: |\n \"Système d'e-réservation bedrijventerreinen pimpt\" bedrijventerreinen!\n"; $this->assertEquals ($awaiting, $dump); } public function testStringStartingWithSpace() { $dump = Spyc::YAMLDump(array ('key' => array('key_one' => " Congrats, pimpt bedrijventerreinen \n pimpt bedrijventerreinen pimpt bedrijventerreinen!"))); $awaiting = "---\nkey:\n key_one: |\n Congrats, pimpt bedrijventerreinen\n pimpt bedrijventerreinen pimpt bedrijventerreinen!\n"; $this->assertEquals ($awaiting, $dump); } public function testPerCentOne() { $dump = Spyc::YAMLDump(array ('key' => "%name%, pimpts bedrijventerreinen!")); $awaiting = "---\nkey: '%name%, pimpts bedrijventerreinen!'\n"; $this->assertEquals ($awaiting, $dump); } public function testPerCentAndSimpleQuote() { $dump = Spyc::YAMLDump(array ('key' => "%name%, pimpt's bedrijventerreinen!")); $awaiting = "---\nkey: \"%name%, pimpt's bedrijventerreinen!\"\n"; $this->assertEquals ($awaiting, $dump); } public function testPerCentAndDoubleQuote() { $dump = Spyc::YAMLDump(array ('key' => '%name%, pimpt\'s "bed"rijventerreinen!')); $awaiting = "---\nkey: |\n %name%, pimpt's \"bed\"rijventerreinen!\n"; $this->assertEquals ($awaiting, $dump); } } |