Upgrade to Parse::CPAN::Meta 1.38
[p5sagit/p5-mst-13.2.git] / lib / Parse / CPAN / Meta / t / 02_basic.t
CommitLineData
be96f5c3 1#!/usr/bin/perl
2
3# Testing of basic document structures
4
5BEGIN {
6 if( $ENV{PERL_CORE} ) {
7 chdir 't';
8 @INC = ('../lib', 'lib');
9 }
10 else {
11 unshift @INC, 't/lib/';
12 }
13}
14
15use strict;
16BEGIN {
17 $| = 1;
18 $^W = 1;
19}
20
21use File::Spec::Functions ':ALL';
22use Parse::CPAN::Meta::Test;
23use Test::More tests(30);
24
25
26
27
28
29#####################################################################
30# Sample Testing
31
32# Test a completely empty document
33yaml_ok(
34 '',
35 [ ],
36 'empty',
37);
38
39# Just a newline
40### YAML.pm has a bug where it dies on a single newline
41yaml_ok(
42 "\n\n",
43 [ ],
44 'only_newlines',
45);
46
47# Just a comment
48yaml_ok(
49 "# comment\n",
50 [ ],
51 'only_comment',
52);
53
54# Empty documents
55yaml_ok(
56 "---\n",
57 [ undef ],
58 'only_header',
de044c36 59 noyamlperl => 1,
be96f5c3 60);
61yaml_ok(
62 "---\n---\n",
63 [ undef, undef ],
64 'two_header',
de044c36 65 noyamlperl => 1,
be96f5c3 66);
67yaml_ok(
68 "--- ~\n",
69 [ undef ],
70 'one_undef',
de044c36 71 noyamlperl => 1,
be96f5c3 72);
73yaml_ok(
74 "--- ~\n",
75 [ undef ],
76 'one_undef2',
de044c36 77 noyamlperl => 1,
be96f5c3 78);
79yaml_ok(
80 "--- ~\n---\n",
81 [ undef, undef ],
82 'two_undef',
de044c36 83 noyamlperl => 1,
be96f5c3 84);
85
86# Just a scalar
87yaml_ok(
88 "--- foo\n",
89 [ 'foo' ],
90 'one_scalar',
91);
92yaml_ok(
93 "--- foo\n",
94 [ 'foo' ],
95 'one_scalar2',
96);
97yaml_ok(
98 "--- foo\n--- bar\n",
99 [ 'foo', 'bar' ],
100 'two_scalar',
101);
102
103# Simple lists
104yaml_ok(
105 "---\n- foo\n",
106 [ [ 'foo' ] ],
107 'one_list1',
108);
109yaml_ok(
110 "---\n- foo\n- bar\n",
111 [ [ 'foo', 'bar' ] ],
112 'one_list2',
113);
114yaml_ok(
115 "---\n- ~\n- bar\n",
116 [ [ undef, 'bar' ] ],
117 'one_listundef',
de044c36 118 noyamlperl => 1,
be96f5c3 119);
120
121# Simple hashs
122yaml_ok(
123 "---\nfoo: bar\n",
124 [ { foo => 'bar' } ],
125 'one_hash1',
126);
127
128yaml_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
136yaml_ok(
137 <<'END_YAML',
138---
139foo:
140 - bar
141 - ~
142 - baz
143END_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
150yaml_ok(
151 <<'END_YAML',
152---
153foo: ~
154bar:
155 foo: bar
156END_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
163yaml_ok(
164 <<'END_YAML',
165---
166-
167 foo: ~
168 this: that
169- foo
170- ~
171-
172 foo: bar
173 this: that
174END_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
186yaml_ok(
187 "---\n- 'foo'\n",
188 [ [ 'foo' ] ],
189 'single_quote1',
190);
191yaml_ok(
192 "---\n- ' '\n",
193 [ [ ' ' ] ],
194 'single_spaces',
195);
196yaml_ok(
197 "---\n- ''\n",
198 [ [ '' ] ],
199 'single_null',
200);
201
202# Double quotes
203yaml_ok(
204 "--- \" \"\n",
205 [ ' ' ],
206 "only_spaces",
de044c36 207 noyamlpm => 1,
208 noyamlperl => 1,
be96f5c3 209);
210
211yaml_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
220yaml_ok(
221 "foo: bar\n",
222 [ { foo => 'bar' } ],
223 'implicit_hash',
224);
225yaml_ok(
226 "- foo\n",
227 [ [ 'foo' ] ],
228 'implicit_array',
229);
230
231# Inline nested hash
232yaml_ok(
233 <<'END_YAML',
234---
235- ~
236- foo: bar
237 this: that
238- baz
239END_YAML
240 [ [ undef, { foo => 'bar', this => 'that' }, 'baz' ] ],
241 'inline_nested_hash',
de044c36 242 noyamlperl => 1,
be96f5c3 243);
244
245# Empty comments
246yaml_ok(
247 "---\n- foo\n#\n- bar\n",
248 [ [ 'foo', 'bar' ] ],
249 'empty_comment_in_list',
250);
251
252yaml_ok(
253 "---\nfoo: bar\n# foo\none: two\n",
254 [ { foo => 'bar', one => 'two' } ],
255 'empty_comment_in_hash',
256);
257
258# Complex keys
259yaml_ok(
260 "---\na b: c d\n",
261 [ { 'a b' => 'c d' } ],
262 'key_with_whitespace',
263);