scratch – Blame information for rev 72
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
66 | office | 1 | <?php |
2 | |||
3 | require_once ("../Spyc.php"); |
||
4 | |||
5 | class ParseTest extends PHPUnit_Framework_TestCase { |
||
6 | |||
7 | protected $yaml; |
||
8 | |||
9 | protected function setUp() { |
||
10 | $this->yaml = spyc_load_file('../spyc.yaml'); |
||
11 | } |
||
12 | |||
13 | public function testMergeHashKeys() { |
||
14 | $Expected = array ( |
||
15 | array ('step' => array('instrument' => 'Lasik 2000', 'pulseEnergy' => 5.4, 'pulseDuration' => 12, 'repetition' => 1000, 'spotSize' => '1mm')), |
||
16 | array ('step' => array('instrument' => 'Lasik 2000', 'pulseEnergy' => 5.4, 'pulseDuration' => 12, 'repetition' => 1000, 'spotSize' => '2mm')), |
||
17 | ); |
||
18 | $Actual = spyc_load_file ('indent_1.yaml'); |
||
19 | $this->assertEquals ($Expected, $Actual['steps']); |
||
20 | } |
||
21 | |||
22 | public function testDeathMasks() { |
||
23 | $Expected = array ('sad' => 2, 'magnificent' => 4); |
||
24 | $Actual = spyc_load_file ('indent_1.yaml'); |
||
25 | $this->assertEquals ($Expected, $Actual['death masks are']); |
||
26 | } |
||
27 | |||
28 | public function testDevDb() { |
||
29 | $Expected = array ('adapter' => 'mysql', 'host' => 'localhost', 'database' => 'rails_dev'); |
||
30 | $Actual = spyc_load_file ('indent_1.yaml'); |
||
31 | $this->assertEquals ($Expected, $Actual['development']); |
||
32 | } |
||
33 | |||
34 | public function testNumericKey() { |
||
35 | $this->assertEquals ("Ooo, a numeric key!", $this->yaml[1040]); |
||
36 | } |
||
37 | |||
38 | public function testMappingsString() { |
||
39 | $this->assertEquals ("Anyone's name, really.", $this->yaml['String']); |
||
40 | } |
||
41 | |||
42 | public function testMappingsInt() { |
||
43 | $this->assertSame (13, $this->yaml['Int']); |
||
44 | } |
||
45 | |||
46 | public function testMappingsHex() { |
||
47 | $this->assertSame (243, $this->yaml['Hex']); |
||
48 | $this->assertSame ('f0xf3', $this->yaml['BadHex']); |
||
49 | } |
||
50 | |||
51 | public function testMappingsBooleanTrue() { |
||
52 | $this->assertSame (true, $this->yaml['True']); |
||
53 | } |
||
54 | |||
55 | public function testMappingsBooleanFalse() { |
||
56 | $this->assertSame (false, $this->yaml['False']); |
||
57 | } |
||
58 | |||
59 | public function testMappingsZero() { |
||
60 | $this->assertSame (0, $this->yaml['Zero']); |
||
61 | } |
||
62 | |||
63 | public function testMappingsNull() { |
||
64 | $this->assertSame (null, $this->yaml['Null']); |
||
65 | } |
||
66 | |||
67 | public function testMappingsNotNull() { |
||
68 | $this->assertSame ('null', $this->yaml['NotNull']); |
||
69 | } |
||
70 | |||
71 | public function testMappingsFloat() { |
||
72 | $this->assertSame (5.34, $this->yaml['Float']); |
||
73 | } |
||
74 | |||
75 | public function testMappingsNegative() { |
||
76 | $this->assertSame (-90, $this->yaml['Negative']); |
||
77 | } |
||
78 | |||
79 | public function testMappingsSmallFloat() { |
||
80 | $this->assertSame (0.7, $this->yaml['SmallFloat']); |
||
81 | } |
||
82 | |||
83 | public function testNewline() { |
||
84 | $this->assertSame ('\n', $this->yaml['NewLine']); |
||
85 | } |
||
86 | |||
87 | public function testQuotedNewline() { |
||
88 | $this->assertSame ("\n", $this->yaml['QuotedNewLine']); |
||
89 | } |
||
90 | |||
91 | public function testSeq0() { |
||
92 | $this->assertEquals ("PHP Class", $this->yaml[0]); |
||
93 | } |
||
94 | |||
95 | public function testSeq1() { |
||
96 | $this->assertEquals ("Basic YAML Loader", $this->yaml[1]); |
||
97 | } |
||
98 | |||
99 | public function testSeq2() { |
||
100 | $this->assertEquals ("Very Basic YAML Dumper", $this->yaml[2]); |
||
101 | } |
||
102 | |||
103 | public function testSeq3() { |
||
104 | $this->assertEquals (array("YAML is so easy to learn.", |
||
105 | "Your config files will never be the same."), $this->yaml[3]); |
||
106 | } |
||
107 | |||
108 | public function testSeqMap() { |
||
109 | $this->assertEquals (array("cpu" => "1.5ghz", "ram" => "1 gig", |
||
110 | "os" => "os x 10.4.1"), $this->yaml[4]); |
||
111 | } |
||
112 | |||
113 | public function testMappedSequence() { |
||
114 | $this->assertEquals (array("yaml.org", "php.net"), $this->yaml['domains']); |
||
115 | } |
||
116 | |||
117 | public function testAnotherSequence() { |
||
118 | $this->assertEquals (array("program" => "Adium", "platform" => "OS X", |
||
119 | "type" => "Chat Client"), $this->yaml[5]); |
||
120 | } |
||
121 | |||
122 | public function testFoldedBlock() { |
||
123 | $this->assertEquals ("There isn't any time for your tricks!\nDo you understand?", $this->yaml['no time']); |
||
124 | } |
||
125 | |||
126 | public function testLiteralAsMapped() { |
||
127 | $this->assertEquals ("There is nothing but time\nfor your tricks.", $this->yaml['some time']); |
||
128 | } |
||
129 | |||
130 | public function testCrazy() { |
||
131 | $this->assertEquals (array( array("name" => "spartan", "notes" => |
||
132 | array( "Needs to be backed up", |
||
133 | "Needs to be normalized" ), |
||
134 | "type" => "mysql" )), $this->yaml['databases']); |
||
135 | } |
||
136 | |||
137 | public function testColons() { |
||
138 | $this->assertEquals ("like", $this->yaml["if: you'd"]); |
||
139 | } |
||
140 | |||
141 | public function testInline() { |
||
142 | $this->assertEquals (array("One", "Two", "Three", "Four"), $this->yaml[6]); |
||
143 | } |
||
144 | |||
145 | public function testNestedInline() { |
||
146 | $this->assertEquals (array("One", array("Two", "And", "Three"), "Four", "Five"), $this->yaml[7]); |
||
147 | } |
||
148 | |||
149 | public function testNestedNestedInline() { |
||
150 | $this->assertEquals (array( "This", array("Is", "Getting", array("Ridiculous", "Guys")), |
||
151 | "Seriously", array("Show", "Mercy")), $this->yaml[8]); |
||
152 | } |
||
153 | |||
154 | public function testInlineMappings() { |
||
155 | $this->assertEquals (array("name" => "chris", "age" => "young", "brand" => "lucky strike"), $this->yaml[9]); |
||
156 | } |
||
157 | |||
158 | public function testNestedInlineMappings() { |
||
159 | $this->assertEquals (array("name" => "mark", "age" => "older than chris", |
||
160 | "brand" => array("marlboro", "lucky strike")), $this->yaml[10]); |
||
161 | } |
||
162 | |||
163 | public function testReferences() { |
||
164 | $this->assertEquals (array('Perl', 'Python', 'PHP', 'Ruby'), $this->yaml['dynamic languages']); |
||
165 | } |
||
166 | |||
167 | public function testReferences2() { |
||
168 | $this->assertEquals (array('C/C++', 'Java'), $this->yaml['compiled languages']); |
||
169 | } |
||
170 | |||
171 | public function testReferences3() { |
||
172 | $this->assertEquals (array( |
||
173 | array('Perl', 'Python', 'PHP', 'Ruby'), |
||
174 | array('C/C++', 'Java') |
||
175 | ), $this->yaml['all languages']); |
||
176 | } |
||
177 | |||
178 | public function testEscapedQuotes() { |
||
179 | $this->assertEquals ("you know, this shouldn't work. but it does.", $this->yaml[11]); |
||
180 | } |
||
181 | |||
182 | public function testEscapedQuotes_2() { |
||
183 | $this->assertEquals ( "that's my value.", $this->yaml[12]); |
||
184 | } |
||
185 | |||
186 | public function testEscapedQuotes_3() { |
||
187 | $this->assertEquals ("again, that's my value.", $this->yaml[13]); |
||
188 | } |
||
189 | |||
190 | public function testQuotes() { |
||
191 | $this->assertEquals ("here's to \"quotes\", boss.", $this->yaml[14]); |
||
192 | } |
||
193 | |||
194 | public function testQuoteSequence() { |
||
195 | $this->assertEquals ( array( 'name' => "Foo, Bar's", 'age' => 20), $this->yaml[15]); |
||
196 | } |
||
197 | |||
198 | public function testShortSequence() { |
||
199 | $this->assertEquals (array( 0 => "a", 1 => array (0 => 1, 1 => 2), 2 => "b"), $this->yaml[16]); |
||
200 | } |
||
201 | |||
202 | public function testQuotedNewlines() { |
||
203 | $this->assertEquals ("First line\nSecond line\nThird line", $this->yaml[17]); |
||
204 | } |
||
205 | |||
206 | public function testHash_1() { |
||
207 | $this->assertEquals ("Hash", $this->yaml['hash_1']); |
||
208 | } |
||
209 | |||
210 | public function testHash_2() { |
||
211 | $this->assertEquals ('Hash #and a comment', $this->yaml['hash_2']); |
||
212 | } |
||
213 | |||
214 | public function testHash_3() { |
||
215 | $this->assertEquals ('Hash (#) can appear in key too', $this->yaml['hash#3']); |
||
216 | } |
||
217 | |||
218 | public function testEndloop() { |
||
219 | $this->assertEquals ("Does this line in the end indeed make Spyc go to an infinite loop?", $this->yaml['endloop']); |
||
220 | } |
||
221 | |||
222 | public function testReallyLargeNumber() { |
||
223 | $this->assertEquals ('115792089237316195423570985008687907853269984665640564039457584007913129639936', $this->yaml['a_really_large_number']); |
||
224 | } |
||
225 | |||
226 | public function testFloatWithZeros() { |
||
227 | $this->assertSame ('1.0', $this->yaml['float_test']); |
||
228 | } |
||
229 | |||
230 | public function testFloatWithQuotes() { |
||
231 | $this->assertSame ('1.0', $this->yaml['float_test_with_quotes']); |
||
232 | } |
||
233 | |||
234 | public function testFloatInverse() { |
||
235 | $this->assertEquals ('001', $this->yaml['float_inverse_test']); |
||
236 | } |
||
237 | |||
238 | public function testIntArray() { |
||
239 | $this->assertEquals (array (1, 2, 3), $this->yaml['int array']); |
||
240 | } |
||
241 | |||
242 | public function testArrayOnSeveralLines() { |
||
243 | $this->assertEquals (array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19), $this->yaml['array on several lines']); |
||
244 | } |
||
245 | |||
246 | public function testArrayWithCommas() { |
||
247 | $this->assertEquals(array (0, 1), $this->yaml['array with commas']); |
||
248 | } |
||
249 | |||
250 | public function testmoreLessKey() { |
||
251 | $this->assertEquals ('<value>', $this->yaml['morelesskey']); |
||
252 | } |
||
253 | |||
254 | public function testArrayOfZero() { |
||
255 | $this->assertSame (array(0), $this->yaml['array_of_zero']); |
||
256 | } |
||
257 | |||
258 | public function testSophisticatedArrayOfZero() { |
||
259 | $this->assertSame (array('rx' => array ('tx' => array (0))), $this->yaml['sophisticated_array_of_zero']); |
||
260 | } |
||
261 | |||
262 | public function testSwitches() { |
||
263 | $this->assertEquals (array (array ('row' => 0, 'col' => 0, 'func' => array ('tx' => array(0, 1)))), $this->yaml['switches']); |
||
264 | } |
||
265 | |||
266 | public function testEmptySequence() { |
||
267 | $this->assertSame (array(), $this->yaml['empty_sequence']); |
||
268 | } |
||
269 | |||
270 | public function testEmptyHash() { |
||
271 | $this->assertSame (array(), $this->yaml['empty_hash']); |
||
272 | } |
||
273 | |||
274 | public function testEmptykey() { |
||
275 | $this->assertSame (array('' => array ('key' => 'value')), $this->yaml['empty_key']); |
||
276 | } |
||
277 | |||
278 | public function testMultilines() { |
||
279 | $this->assertSame (array(array('type' => 'SomeItem', 'values' => array ('blah', 'blah', 'blah', 'blah'), 'ints' => array(2, 54, 12, 2143))), $this->yaml['multiline_items']); |
||
280 | } |
||
281 | |||
282 | public function testManyNewlines() { |
||
283 | $this->assertSame ('A quick |
||
284 | fox |
||
285 | |||
286 | |||
287 | jumped |
||
288 | over |
||
289 | |||
290 | |||
291 | |||
292 | |||
293 | |||
294 | a lazy |
||
295 | |||
296 | |||
297 | |||
298 | dog', $this->yaml['many_lines']); |
||
299 | } |
||
300 | |||
301 | public function testWerte() { |
||
302 | $this->assertSame (array ('1' => 'nummer 1', '0' => 'Stunde 0'), $this->yaml['werte']); |
||
303 | } |
||
304 | |||
305 | /* public function testNoIndent() { |
||
306 | $this->assertSame (array( |
||
307 | array ('record1'=>'value1'), |
||
308 | array ('record2'=>'value2') |
||
309 | ) |
||
310 | , $this->yaml['noindent_records']); |
||
311 | } */ |
||
312 | |||
313 | public function testColonsInKeys() { |
||
314 | $this->assertSame (array (1000), $this->yaml['a:1']); |
||
315 | } |
||
316 | |||
317 | public function testColonsInKeys2() { |
||
318 | $this->assertSame (array (2000), $this->yaml['a:2']); |
||
319 | } |
||
320 | |||
321 | public function testUnquotedColonsInKeys() { |
||
322 | $this->assertSame (array (3000), $this->yaml['a:3']); |
||
323 | } |
||
324 | |||
325 | public function testComplicatedKeyWithColon() { |
||
326 | $this->assertSame(array("a:b:''test'" => 'value'), $this->yaml['complex_unquoted_key']); |
||
327 | } |
||
328 | |||
329 | public function testKeysInMappedValueException() { |
||
330 | $this->setExpectedException('Exception'); |
||
331 | Spyc::YAMLLoad('x: y: z:'); |
||
332 | } |
||
333 | |||
334 | public function testKeysInValueException() { |
||
335 | $this->setExpectedException('Exception'); |
||
336 | Spyc::YAMLLoad('x: y: z'); |
||
337 | } |
||
338 | |||
339 | public function testSpecialCharacters() { |
||
340 | $this->assertSame ('[{]]{{]]', $this->yaml['special_characters']); |
||
341 | } |
||
342 | |||
343 | public function testAngleQuotes() { |
||
344 | $Quotes = Spyc::YAMLLoad('quotes.yaml'); |
||
345 | $this->assertEquals (array ('html_tags' => array ('<br>', '<p>'), 'html_content' => array ('<p>hello world</p>', 'hello<br>world'), 'text_content' => array ('hello world')), |
||
346 | $Quotes); |
||
347 | } |
||
348 | |||
349 | public function testFailingColons() { |
||
350 | $Failing = Spyc::YAMLLoad('failing1.yaml'); |
||
351 | $this->assertSame (array ('MyObject' => array ('Prop1' => array ('key1:val1'))), |
||
352 | $Failing); |
||
353 | } |
||
354 | |||
355 | public function testQuotesWithComments() { |
||
356 | $Expected = 'bar'; |
||
357 | $Actual = spyc_load_file ('comments.yaml'); |
||
358 | $this->assertEquals ($Expected, $Actual['foo']); |
||
359 | } |
||
360 | |||
361 | public function testArrayWithComments() { |
||
362 | $Expected = array ('x', 'y', 'z'); |
||
363 | $Actual = spyc_load_file ('comments.yaml'); |
||
364 | $this->assertEquals ($Expected, $Actual['arr']); |
||
365 | } |
||
366 | |||
367 | public function testAfterArrayWithKittens() { |
||
368 | $Expected = 'kittens'; |
||
369 | $Actual = spyc_load_file ('comments.yaml'); |
||
370 | $this->assertEquals ($Expected, $Actual['bar']); |
||
371 | } |
||
372 | |||
373 | // Plain characters http://www.yaml.org/spec/1.2/spec.html#id2789510 |
||
374 | public function testKai() { |
||
375 | $Expected = array('-example' => 'value'); |
||
376 | $Actual = spyc_load_file ('indent_1.yaml'); |
||
377 | $this->assertEquals ($Expected, $Actual['kai']); |
||
378 | } |
||
379 | |||
380 | public function testKaiList() { |
||
381 | $Expected = array ('-item', '-item', '-item'); |
||
382 | $Actual = spyc_load_file ('indent_1.yaml'); |
||
383 | $this->assertEquals ($Expected, $Actual['kai_list_of_items']); |
||
384 | } |
||
385 | |||
386 | public function testDifferentQuoteTypes() { |
||
387 | $expected = array ('Something', "", "", "Something else"); |
||
388 | $this->assertSame ($expected, $this->yaml['invoice']); |
||
389 | } |
||
390 | |||
391 | public function testDifferentQuoteTypes2() { |
||
392 | $expected = array ('Something', "Nothing", "Anything", "Thing"); |
||
393 | $this->assertSame ($expected, $this->yaml['quotes']); |
||
394 | } |
||
395 | |||
396 | // Separation spaces http://www.yaml.org/spec/1.2/spec.html#id2778394 |
||
397 | public function testMultipleArrays() { |
||
398 | $expected = array(array(array('x'))); |
||
399 | $this->assertSame($expected, Spyc::YAMLLoad("- - - x")); |
||
400 | } |
||
401 | } |