This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
8b3f4df259c736e0dd5bad5c5bf01a05ad0e4736
[perl5.git] / cpan / CPAN-Meta-YAML / t / 22_comments.t
1 #!/usr/bin/perl
2
3 # Testing of inline comments. These comments can be quite useful in config
4 # files and people will expect them to work.
5
6 use strict;
7 BEGIN {
8         $|  = 1;
9         $^W = 1;
10 }
11
12 use File::Spec::Functions ':ALL';
13 use t::lib::Test;
14 use Test::More tests(2);
15 use CPAN::Meta::YAML;
16
17
18
19
20
21 #####################################################################
22 # Main Tests
23
24 yaml_ok(
25         <<'END_YAML',
26 ---
27 a: b#content
28 c: d #comment
29 e:
30 - f #comment
31 - g# content
32 h: 'single'                 # comment
33 h2: 'single # content'      # comment
34 i: "double"                 # comment
35 i2: "double # content"      # comment
36 j: |        # comment
37     literal # content
38     block   # content
39 k: {}       # comment
40 l: []       # comment
41 m:      # comment
42   n: o
43 END_YAML
44         [
45                 {
46                         a => 'b#content',
47                         c => 'd',
48                         e => [
49                                 'f',
50                                 'g# content',
51                         ],
52                         h => 'single',
53                         h2 => 'single # content',
54                         i => 'double',
55                         i2 => 'double # content',
56                         j => "literal # content\nblock   # content\n",
57                         k => {},
58                         l => [],
59                         m => {
60                                 n => 'o',
61                         },
62                 },
63         ],
64         'Properly ignore comments',
65         noyamlpm => 1,
66 );
67
68 # Repeat, with otherwise illegal characters in the comments
69 yaml_ok(
70         <<'END_YAML',
71 ---
72 a: b#content
73 c: d #comment '"!&@%`
74 e:
75 - f #comment '"!&@%`
76 - g# content
77 h: 'single'                 # comment '"!&@%`
78 h2: 'single # content'      # comment '"!&@%`
79 i: "double"                 # comment '"!&@%`
80 i2: "double # content"      # comment '"!&@%`
81 j: |        # comment '"!&@%`
82     literal # content
83     block   # content
84 k: {}       # comment '"!&@%`
85 l: []       # comment '"!&@%`
86 m:      # comment '"!&@%`
87   n: o
88 END_YAML
89         [
90                 {
91                         a => 'b#content',
92                         c => 'd',
93                         e => [
94                                 'f',
95                                 'g# content',
96                         ],
97                         h => 'single',
98                         h2 => 'single # content',
99                         i => 'double',
100                         i2 => 'double # content',
101                         j => "literal # content\nblock   # content\n",
102                         k => {},
103                         l => [],
104                         m => {
105                                 n => 'o',
106                         },
107                 },
108         ],
109         'Properly ignore comments (with otherwise illegal characters)',
110         noyamlpm => 1,
111 );