Commit | Line | Data |
be96f5c3 |
1 | #!/usr/bin/perl |
2 | |
3 | # Testing of common META.yml examples |
4 | |
5 | BEGIN { |
6 | if( $ENV{PERL_CORE} ) { |
7 | chdir 't'; |
8 | @INC = ('../lib', 'lib'); |
9 | } |
10 | else { |
11 | unshift @INC, 't/lib/'; |
12 | } |
13 | } |
14 | |
15 | use strict; |
16 | BEGIN { |
17 | $| = 1; |
18 | $^W = 1; |
19 | } |
20 | |
21 | use File::Spec::Functions ':ALL'; |
22 | use Parse::CPAN::Meta::Test; |
de044c36 |
23 | use Test::More tests(37); |
be96f5c3 |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | ##################################################################### |
30 | # In META.yml files, some hash keys contain module names |
31 | |
32 | # Hash key legally containing a colon |
33 | yaml_ok( |
34 | "---\nFoo::Bar: 1\n", |
35 | [ { 'Foo::Bar' => 1 } ], |
36 | 'module_hash_key', |
37 | ); |
38 | |
39 | # Hash indented |
40 | yaml_ok( |
41 | "---\n" |
42 | . " foo: bar\n", |
43 | [ { foo => "bar" } ], |
44 | 'hash_indented', |
45 | ); |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | ##################################################################### |
52 | # Support for literal multi-line scalars |
53 | |
54 | # Declarative multi-line scalar |
55 | yaml_ok( |
56 | "---\n" |
57 | . " foo: >\n" |
58 | . " bar\n" |
59 | . " baz\n", |
60 | [ { foo => "bar baz\n" } ], |
61 | 'simple_multiline', |
62 | ); |
63 | |
64 | # Piped multi-line scalar |
de044c36 |
65 | yaml_ok( |
66 | <<'END_YAML', |
be96f5c3 |
67 | --- |
68 | - | |
69 | foo |
70 | bar |
71 | - 1 |
72 | END_YAML |
de044c36 |
73 | [ [ "foo\nbar\n", 1 ] ], |
74 | 'indented', |
75 | ); |
be96f5c3 |
76 | |
77 | # ... with a pointless hyphen |
de044c36 |
78 | yaml_ok( <<'END_YAML', |
be96f5c3 |
79 | --- |
80 | - |- |
81 | foo |
82 | bar |
83 | - 1 |
84 | END_YAML |
de044c36 |
85 | [ [ "foo\nbar", 1 ] ], |
86 | 'indented', |
87 | ); |
be96f5c3 |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | ##################################################################### |
de044c36 |
94 | # Support for YAML version directives |
be96f5c3 |
95 | |
de044c36 |
96 | # Simple inline case (comment variant) |
be96f5c3 |
97 | yaml_ok( |
98 | <<'END_YAML', |
99 | --- #YAML:1.0 |
100 | foo: bar |
101 | END_YAML |
102 | [ { foo => 'bar' } ], |
de044c36 |
103 | 'simple_doctype_comment', |
104 | nosyck => 1, |
105 | ); |
106 | |
107 | # Simple inline case (percent variant) |
108 | yaml_ok( |
109 | <<'END_YAML', |
110 | --- %YAML:1.0 |
111 | foo: bar |
112 | END_YAML |
113 | [ { foo => 'bar' } ], |
114 | 'simple_doctype_percent', |
115 | noyamlpm => 1, |
116 | noxs => 1, |
117 | noyamlperl => 1, |
118 | ); |
119 | |
120 | # Simple header (comment variant) |
121 | yaml_ok( |
122 | <<'END_YAML', |
123 | %YAML:1.0 |
124 | --- |
125 | foo: bar |
126 | END_YAML |
127 | [ { foo => 'bar' } ], |
128 | 'predocument_1_0', |
129 | noyamlpm => 1, |
130 | nosyck => 1, |
131 | noxs => 1, |
132 | noyamlperl => 1, |
be96f5c3 |
133 | ); |
134 | |
de044c36 |
135 | # Simple inline case (comment variant) |
136 | yaml_ok( |
137 | <<'END_YAML', |
138 | %YAML 1.1 |
139 | --- |
140 | foo: bar |
141 | END_YAML |
142 | [ { foo => 'bar' } ], |
143 | 'predocument_1_1', |
144 | noyamlpm => 1, |
145 | nosyck => 1, |
146 | noyamlperl => 1, |
147 | ); |
148 | |
149 | # Multiple inline documents (comment variant) |
be96f5c3 |
150 | yaml_ok( |
151 | <<'END_YAML', |
152 | --- #YAML:1.0 |
153 | foo: bar |
154 | --- #YAML:1.0 |
155 | - 1 |
156 | --- #YAML:1.0 |
157 | foo: bar |
158 | END_YAML |
159 | [ { foo => 'bar' }, [ 1 ], { foo => 'bar' } ], |
de044c36 |
160 | 'multi_doctype_comment', |
161 | ); |
162 | |
163 | # Simple pre-document case (comment variant) |
164 | yaml_ok( |
165 | <<'END_YAML', |
166 | %YAML 1.1 |
167 | --- |
168 | foo: bar |
169 | END_YAML |
170 | [ { foo => 'bar' } ], |
171 | 'predocument_percent', |
172 | noyamlpm => 1, |
173 | nosyck => 1, |
174 | noyamlperl => 1, |
175 | ); |
176 | |
177 | # Simple pre-document case (comment variant) |
178 | yaml_ok( |
179 | <<'END_YAML', |
180 | #YAML 1.1 |
181 | --- |
182 | foo: bar |
183 | END_YAML |
184 | [ { foo => 'bar' } ], |
185 | 'predocument_comment', |
be96f5c3 |
186 | ); |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | ##################################################################### |
193 | # Hitchhiker Scalar |
194 | |
195 | yaml_ok( |
196 | <<'END_YAML', |
197 | --- 42 |
198 | END_YAML |
199 | [ 42 ], |
200 | 'hitchhiker scalar', |
201 | serializes => 1, |
202 | ); |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | ##################################################################### |
209 | # Null HASH/ARRAY |
210 | |
211 | yaml_ok( |
212 | <<'END_YAML', |
213 | --- |
214 | - foo |
215 | - {} |
216 | - bar |
217 | END_YAML |
218 | [ [ 'foo', {}, 'bar' ] ], |
219 | 'null hash in array', |
220 | ); |
221 | |
222 | yaml_ok( |
223 | <<'END_YAML', |
224 | --- |
225 | - foo |
226 | - [] |
227 | - bar |
228 | END_YAML |
229 | [ [ 'foo', [], 'bar' ] ], |
230 | 'null array in array', |
231 | ); |
232 | |
233 | yaml_ok( |
234 | <<'END_YAML', |
235 | --- |
236 | foo: {} |
237 | bar: 1 |
238 | END_YAML |
239 | [ { foo => {}, bar => 1 } ], |
240 | 'null hash in hash', |
241 | ); |
242 | |
243 | yaml_ok( |
244 | <<'END_YAML', |
245 | --- |
246 | foo: [] |
247 | bar: 1 |
248 | END_YAML |
249 | [ { foo => [], bar => 1 } ], |
250 | 'null array in hash', |
251 | ); |
252 | |
253 | |
254 | |
255 | |
256 | ##################################################################### |
257 | # Trailing Whitespace |
258 | |
259 | yaml_ok( |
260 | <<'END_YAML', |
261 | --- |
262 | abstract: Generate fractal curves |
263 | foo: ~ |
264 | arr: |
265 | - foo |
266 | - ~ |
267 | - 'bar' |
268 | END_YAML |
de044c36 |
269 | [ { |
270 | abstract => 'Generate fractal curves', |
271 | foo => undef, |
272 | arr => [ 'foo', undef, 'bar' ], |
273 | } ], |
be96f5c3 |
274 | 'trailing whitespace', |
de044c36 |
275 | noyamlperl => 1, |
be96f5c3 |
276 | ); |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | ##################################################################### |
283 | # Quote vs Hash |
284 | |
285 | yaml_ok( |
286 | <<'END_YAML', |
287 | --- |
288 | author: |
289 | - 'mst: Matt S. Trout <mst@shadowcatsystems.co.uk>' |
290 | END_YAML |
291 | [ { author => [ 'mst: Matt S. Trout <mst@shadowcatsystems.co.uk>' ] } ], |
292 | 'hash-like quote', |
293 | ); |
294 | |
295 | |
296 | |
297 | |
298 | |
299 | ##################################################################### |
de044c36 |
300 | # Quote and Escaping Idiosyncracies |
301 | |
302 | yaml_ok( |
303 | <<'END_YAML', |
304 | --- |
305 | name1: 'O''Reilly' |
306 | name2: 'O''Reilly O''Tool' |
307 | name3: 'Double '''' Quote' |
308 | END_YAML |
309 | [ { |
310 | name1 => "O'Reilly", |
311 | name2 => "O'Reilly O'Tool", |
312 | name3 => "Double '' Quote", |
313 | } ], |
314 | 'single quote subtleties', |
315 | ); |
be96f5c3 |
316 | |
317 | yaml_ok( |
318 | <<'END_YAML', |
319 | --- |
de044c36 |
320 | slash1: '\\' |
321 | slash2: '\\foo' |
322 | slash3: '\\foo\\\\' |
be96f5c3 |
323 | END_YAML |
de044c36 |
324 | [ { |
325 | slash1 => "\\\\", |
326 | slash2 => "\\\\foo", |
327 | slash3 => "\\\\foo\\\\\\\\", |
328 | } ], |
be96f5c3 |
329 | 'single quote subtleties', |
330 | ); |
331 | |
332 | |
333 | |
334 | |
335 | |
336 | ##################################################################### |
337 | # Empty Values and Premature EOF |
338 | |
339 | yaml_ok( |
340 | <<'END_YAML', |
341 | --- |
342 | foo: 0 |
343 | requires: |
344 | build_requires: |
345 | END_YAML |
346 | [ { foo => 0, requires => undef, build_requires => undef } ], |
347 | 'empty hash keys', |
de044c36 |
348 | noyamlpm => 1, |
349 | noyamlperl => 1, |
be96f5c3 |
350 | ); |
351 | |
352 | yaml_ok( |
353 | <<'END_YAML', |
354 | --- |
355 | - foo |
356 | - |
357 | - |
358 | END_YAML |
359 | [ [ 'foo', undef, undef ] ], |
360 | 'empty array keys', |
de044c36 |
361 | noyamlpm => 1, |
362 | noyamlperl => 1, |
be96f5c3 |
363 | ); |
364 | |
365 | |
366 | |
367 | |
368 | |
369 | ##################################################################### |
370 | # Comment on the Document Line |
371 | |
372 | yaml_ok( |
373 | <<'END_YAML', |
374 | --- # Comment |
375 | foo: bar |
376 | END_YAML |
377 | [ { foo => 'bar' } ], |
378 | 'comment header', |
de044c36 |
379 | noyamlpm => 1, |
380 | noyamlperl => 1, |
be96f5c3 |
381 | ); |
382 | |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | ##################################################################### |
389 | # Newlines and tabs |
390 | |
391 | yaml_ok( |
392 | <<'END_YAML', |
393 | foo: "foo\\\n\tbar" |
394 | END_YAML |
395 | [ { foo => "foo\\\n\tbar" } ], |
396 | 'special characters', |
397 | ); |
398 | |
399 | |
400 | |
401 | |
402 | |
de044c36 |
403 | ##################################################################### |
404 | # Confirm we can read the synopsis |
405 | |
406 | yaml_ok( |
407 | <<'END_YAML', |
408 | --- |
409 | rootproperty: blah |
410 | section: |
411 | one: two |
412 | three: four |
413 | Foo: Bar |
414 | empty: ~ |
415 | END_YAML |
416 | [ { |
417 | rootproperty => 'blah', |
418 | section => { |
419 | one => 'two', |
420 | three => 'four', |
421 | Foo => 'Bar', |
422 | empty => undef, |
423 | }, |
424 | } ], |
425 | 'synopsis', |
426 | noyamlperl => 1, |
427 | ); |
428 | |
429 | |
430 | |
431 | |
432 | |
433 | ##################################################################### |
434 | # Unprintable Characters |
435 | |
436 | yaml_ok( |
437 | "--- \"foo\\n\\x00\"\n", |
438 | [ "foo\n\0" ], |
439 | 'unprintable', |
440 | ); |
441 | |
442 | |
443 | |
444 | |
445 | |
446 | ##################################################################### |
447 | # Empty Quote Line |
448 | |
449 | yaml_ok( |
450 | <<'END_YAML', |
451 | --- |
452 | - foo |
453 | # |
454 | - bar |
455 | END_YAML |
456 | [ [ "foo", "bar" ] ], |
457 | ); |
458 | |
459 | |
460 | |
461 | |
462 | |
463 | ##################################################################### |
464 | # Indentation after empty hash value |
465 | |
466 | yaml_ok( |
467 | <<'END_YAML', |
468 | --- |
469 | Test: |
470 | optmods: |
471 | Bad: 0 |
472 | Foo: 1 |
473 | Long: 0 |
474 | version: 5 |
475 | Test_IncludeA: |
476 | optmods: |
477 | Test_IncludeB: |
478 | optmods: |
479 | _meta: |
480 | name: 'test profile' |
481 | note: 'note this test profile' |
482 | END_YAML |
483 | [ { |
484 | Test => { |
485 | optmods => { |
486 | Bad => 0, |
487 | Foo => 1, |
488 | Long => 0, |
489 | }, |
490 | version => 5, |
491 | }, |
492 | Test_IncludeA => { |
493 | optmods => undef, |
494 | }, |
495 | Test_IncludeB => { |
496 | optmods => undef, |
497 | }, |
498 | _meta => { |
499 | name => 'test profile', |
500 | note => 'note this test profile', |
501 | }, |
502 | } ], |
503 | 'Indentation after empty hash value', |
504 | noyamlperl => 1, |
505 | ); |
506 | |
507 | |
508 | |
509 | |
510 | |
511 | ##################################################################### |
512 | # Spaces in the Key |
513 | |
514 | yaml_ok( |
515 | <<'END_YAML', |
516 | --- |
517 | the key: the value |
518 | END_YAML |
519 | [ { 'the key' => 'the value' } ], |
520 | ); |
521 | |
522 | |
523 | |
524 | |
525 | |
526 | ##################################################################### |
527 | # Ticker #32402 |
528 | |
529 | # Tests a particular pathological case |
530 | |
531 | yaml_ok( |
532 | <<'END_YAML', |
533 | --- |
534 | - value |
535 | - '><' |
536 | END_YAML |
537 | [ [ 'value', '><' ] ], |
538 | 'Pathological >< case', |
539 | ); |
540 | |
541 | |
542 | |
543 | |
544 | |
545 | ##################################################################### |
546 | # Special Characters |
547 | |
548 | #yaml_ok( |
549 | # <<'END_YAML', |
550 | #--- |
551 | #- "Ingy d\xC3\xB6t Net" |
552 | #END_YAML |
553 | # [ [ "Ingy d\xC3\xB6t Net" ] ], |
554 | #); |
555 | |
556 | |
557 | |
558 | |
559 | |
be96f5c3 |
560 | |
561 | ###################################################################### |
562 | # Non-Indenting Sub-List |
563 | |
564 | yaml_ok( |
565 | <<'END_YAML', |
566 | --- |
567 | foo: |
568 | - list |
569 | bar: value |
570 | END_YAML |
571 | [ { foo => [ 'list' ], bar => 'value' } ], |
572 | 'Non-indenting sub-list', |
de044c36 |
573 | noyamlpm => 1, |
574 | noyamlperl => 1, |
575 | ); |
576 | |
577 | |
578 | |
579 | |
580 | |
581 | |
582 | ##################################################################### |
583 | # Check Multiple-Escaping |
584 | |
585 | # RT #42119: write of two single quotes |
586 | yaml_ok( |
587 | "--- \"A'B'C\"\n", |
588 | [ "A'B'C" ], |
589 | 'Multiple escaping of quote ok', |
590 | ); |
591 | |
592 | # Escapes without whitespace |
593 | yaml_ok( |
594 | "--- A\\B\\C\n", |
595 | [ "A\\B\\C" ], |
596 | 'Multiple escaping of escape ok', |
597 | ); |
598 | |
599 | # Escapes with whitespace |
600 | yaml_ok( |
601 | "--- 'A\\B \\C'\n", |
602 | [ "A\\B \\C" ], |
603 | 'Multiple escaping of escape with whitespace ok', |
604 | ); |
605 | |
606 | |
607 | |
608 | |
609 | |
610 | ###################################################################### |
611 | # Check illegal characters that are in legal places |
612 | |
613 | yaml_ok( |
614 | "--- 'Wow!'\n", |
615 | [ "Wow!" ], |
616 | 'Bang in a quote', |
617 | ); |
618 | yaml_ok( |
619 | "--- 'This&that'\n", |
620 | [ "This&that" ], |
621 | 'Ampersand in a quote', |
be96f5c3 |
622 | ); |