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