Commit | Line | Data |
be96f5c3 |
1 | #!/usr/bin/perl |
2 | |
3 | # Testing of basic document structures |
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; |
23 | use Test::More tests(30); |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | ##################################################################### |
30 | # Sample Testing |
31 | |
32 | # Test a completely empty document |
33 | yaml_ok( |
34 | '', |
35 | [ ], |
36 | 'empty', |
37 | ); |
38 | |
39 | # Just a newline |
40 | ### YAML.pm has a bug where it dies on a single newline |
41 | yaml_ok( |
42 | "\n\n", |
43 | [ ], |
44 | 'only_newlines', |
45 | ); |
46 | |
47 | # Just a comment |
48 | yaml_ok( |
49 | "# comment\n", |
50 | [ ], |
51 | 'only_comment', |
52 | ); |
53 | |
54 | # Empty documents |
55 | yaml_ok( |
56 | "---\n", |
57 | [ undef ], |
58 | 'only_header', |
de044c36 |
59 | noyamlperl => 1, |
be96f5c3 |
60 | ); |
61 | yaml_ok( |
62 | "---\n---\n", |
63 | [ undef, undef ], |
64 | 'two_header', |
de044c36 |
65 | noyamlperl => 1, |
be96f5c3 |
66 | ); |
67 | yaml_ok( |
68 | "--- ~\n", |
69 | [ undef ], |
70 | 'one_undef', |
de044c36 |
71 | noyamlperl => 1, |
be96f5c3 |
72 | ); |
73 | yaml_ok( |
74 | "--- ~\n", |
75 | [ undef ], |
76 | 'one_undef2', |
de044c36 |
77 | noyamlperl => 1, |
be96f5c3 |
78 | ); |
79 | yaml_ok( |
80 | "--- ~\n---\n", |
81 | [ undef, undef ], |
82 | 'two_undef', |
de044c36 |
83 | noyamlperl => 1, |
be96f5c3 |
84 | ); |
85 | |
86 | # Just a scalar |
87 | yaml_ok( |
88 | "--- foo\n", |
89 | [ 'foo' ], |
90 | 'one_scalar', |
91 | ); |
92 | yaml_ok( |
93 | "--- foo\n", |
94 | [ 'foo' ], |
95 | 'one_scalar2', |
96 | ); |
97 | yaml_ok( |
98 | "--- foo\n--- bar\n", |
99 | [ 'foo', 'bar' ], |
100 | 'two_scalar', |
101 | ); |
102 | |
103 | # Simple lists |
104 | yaml_ok( |
105 | "---\n- foo\n", |
106 | [ [ 'foo' ] ], |
107 | 'one_list1', |
108 | ); |
109 | yaml_ok( |
110 | "---\n- foo\n- bar\n", |
111 | [ [ 'foo', 'bar' ] ], |
112 | 'one_list2', |
113 | ); |
114 | yaml_ok( |
115 | "---\n- ~\n- bar\n", |
116 | [ [ undef, 'bar' ] ], |
117 | 'one_listundef', |
de044c36 |
118 | noyamlperl => 1, |
be96f5c3 |
119 | ); |
120 | |
121 | # Simple hashs |
122 | yaml_ok( |
123 | "---\nfoo: bar\n", |
124 | [ { foo => 'bar' } ], |
125 | 'one_hash1', |
126 | ); |
127 | |
128 | yaml_ok( |
129 | "---\nfoo: bar\nthis: ~\n", |
130 | [ { this => undef, foo => 'bar' } ], |
131 | 'one_hash2', |
de044c36 |
132 | noyamlperl => 1, |
be96f5c3 |
133 | ); |
134 | |
135 | # Simple array inside a hash with an undef |
136 | yaml_ok( |
137 | <<'END_YAML', |
138 | --- |
139 | foo: |
140 | - bar |
141 | - ~ |
142 | - baz |
143 | END_YAML |
144 | [ { foo => [ 'bar', undef, 'baz' ] } ], |
145 | 'array_in_hash', |
de044c36 |
146 | noyamlperl => 1, |
be96f5c3 |
147 | ); |
148 | |
149 | # Simple hash inside a hash with an undef |
150 | yaml_ok( |
151 | <<'END_YAML', |
152 | --- |
153 | foo: ~ |
154 | bar: |
155 | foo: bar |
156 | END_YAML |
157 | [ { foo => undef, bar => { foo => 'bar' } } ], |
158 | 'hash_in_hash', |
de044c36 |
159 | noyamlperl => 1, |
be96f5c3 |
160 | ); |
161 | |
162 | # Mixed hash and scalars inside an array |
163 | yaml_ok( |
164 | <<'END_YAML', |
165 | --- |
166 | - |
167 | foo: ~ |
168 | this: that |
169 | - foo |
170 | - ~ |
171 | - |
172 | foo: bar |
173 | this: that |
174 | END_YAML |
175 | [ [ |
176 | { foo => undef, this => 'that' }, |
177 | 'foo', |
178 | undef, |
179 | { foo => 'bar', this => 'that' }, |
180 | ] ], |
181 | 'hash_in_array', |
de044c36 |
182 | noyamlperl => 1, |
be96f5c3 |
183 | ); |
184 | |
185 | # Simple single quote |
186 | yaml_ok( |
187 | "---\n- 'foo'\n", |
188 | [ [ 'foo' ] ], |
189 | 'single_quote1', |
190 | ); |
191 | yaml_ok( |
192 | "---\n- ' '\n", |
193 | [ [ ' ' ] ], |
194 | 'single_spaces', |
195 | ); |
196 | yaml_ok( |
197 | "---\n- ''\n", |
198 | [ [ '' ] ], |
199 | 'single_null', |
200 | ); |
201 | |
202 | # Double quotes |
203 | yaml_ok( |
204 | "--- \" \"\n", |
205 | [ ' ' ], |
206 | "only_spaces", |
de044c36 |
207 | noyamlpm => 1, |
208 | noyamlperl => 1, |
be96f5c3 |
209 | ); |
210 | |
211 | yaml_ok( |
212 | "--- \" foo\"\n--- \"bar \"\n", |
213 | [ " foo", "bar " ], |
214 | "leading_trailing_spaces", |
de044c36 |
215 | noyamlpm => 1, |
216 | noyamlperl => 1, |
be96f5c3 |
217 | ); |
218 | |
219 | # Implicit document start |
220 | yaml_ok( |
221 | "foo: bar\n", |
222 | [ { foo => 'bar' } ], |
223 | 'implicit_hash', |
224 | ); |
225 | yaml_ok( |
226 | "- foo\n", |
227 | [ [ 'foo' ] ], |
228 | 'implicit_array', |
229 | ); |
230 | |
231 | # Inline nested hash |
232 | yaml_ok( |
233 | <<'END_YAML', |
234 | --- |
235 | - ~ |
236 | - foo: bar |
237 | this: that |
238 | - baz |
239 | END_YAML |
240 | [ [ undef, { foo => 'bar', this => 'that' }, 'baz' ] ], |
241 | 'inline_nested_hash', |
de044c36 |
242 | noyamlperl => 1, |
be96f5c3 |
243 | ); |
244 | |
245 | # Empty comments |
246 | yaml_ok( |
247 | "---\n- foo\n#\n- bar\n", |
248 | [ [ 'foo', 'bar' ] ], |
249 | 'empty_comment_in_list', |
250 | ); |
251 | |
252 | yaml_ok( |
253 | "---\nfoo: bar\n# foo\none: two\n", |
254 | [ { foo => 'bar', one => 'two' } ], |
255 | 'empty_comment_in_hash', |
256 | ); |
257 | |
258 | # Complex keys |
259 | yaml_ok( |
260 | "---\na b: c d\n", |
261 | [ { 'a b' => 'c d' } ], |
262 | 'key_with_whitespace', |
263 | ); |