Add ExtUtils::Miniperl to the list of core modules for all versions >= 5.00504
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / mbyaml.t
1 #!/usr/local/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest 'no_plan';
6
7 use_ok 'Module::Build::YAML';
8 ensure_blib('Module::Build::YAML');
9
10 my ($dir);
11 $dir = ".";
12 $dir = "t" if (-d "t");
13
14 {
15     my ($expected, $got, $var);
16     ##########################################################
17     # Test a typical-looking Module::Build structure (alphabetized)
18     ##########################################################
19     $var = {
20           'resources' => {
21                            'license' => 'http://opensource.org/licenses/artistic-license.php'
22                          },
23           'meta-spec' => {
24                            'version' => '1.2',
25                            'url' => 'http://module-build.sourceforge.net/META-spec-v1.2.html'
26                          },
27           'generated_by' => 'Module::Build version 0.2709',
28           'version' => '0.13',
29           'name' => 'js-app',
30           'dynamic_config' => '1',
31           'author' => [
32                         '"Stephen Adkins" <spadkins@gmail.com>'
33                       ],
34           'license' => 'lgpl',
35           'build_requires' => {
36                                 'App::Build' => '0',
37                                 'File::Spec' => '0',
38                                 'Module::Build' => '0'
39                               },
40           'provides' => {
41                           'JavaScript::App' => {
42                                                  'version' => '0',
43                                                  'file' => 'lib/JavaScript/App.pm'
44                                                }
45                         },
46           'requires' => {
47                           'App::Options' => '0'
48                         },
49           'abstract' => 'A framework for building dynamic widgets or full applications in Javascript'
50         };
51     $expected = <<'EOF';
52 ---
53 abstract: A framework for building dynamic widgets or full applications in Javascript
54 author:
55   - '"Stephen Adkins" <spadkins@gmail.com>'
56 build_requires:
57   App::Build: 0
58   File::Spec: 0
59   Module::Build: 0
60 dynamic_config: 1
61 generated_by: Module::Build version 0.2709
62 license: lgpl
63 meta-spec:
64   url: http://module-build.sourceforge.net/META-spec-v1.2.html
65   version: 1.2
66 name: js-app
67 provides:
68   JavaScript::App:
69     file: lib/JavaScript/App.pm
70     version: 0
71 requires:
72   App::Options: 0
73 resources:
74   license: http://opensource.org/licenses/artistic-license.php
75 version: 0.13
76 EOF
77     $got = &Module::Build::YAML::Dump($var);
78     is($got, $expected, "Dump(): single deep hash");
79
80     ##########################################################
81     # Test a typical-looking Module::Build structure (ordered)
82     ##########################################################
83     $expected = <<'EOF';
84 ---
85 name: js-app
86 version: 0.13
87 author:
88   - '"Stephen Adkins" <spadkins@gmail.com>'
89 abstract: A framework for building dynamic widgets or full applications in Javascript
90 license: lgpl
91 resources:
92   license: http://opensource.org/licenses/artistic-license.php
93 requires:
94   App::Options: 0
95 build_requires:
96   App::Build: 0
97   File::Spec: 0
98   Module::Build: 0
99 dynamic_config: 1
100 provides:
101   JavaScript::App:
102     file: lib/JavaScript/App.pm
103     version: 0
104 generated_by: Module::Build version 0.2709
105 meta-spec:
106   url: http://module-build.sourceforge.net/META-spec-v1.2.html
107   version: 1.2
108 EOF
109     $var->{_order} = [qw(name version author abstract license resources requires build_requires dynamic_config provides)];
110     $got = &Module::Build::YAML::Dump($var);
111     is($got, $expected, "Dump(): single deep hash, ordered");
112
113     ##########################################################
114     # Test that an array turns into multiple documents
115     ##########################################################
116     $var = [
117         "e",
118         2.71828,
119         [ "pi", "is", 3.1416 ],
120         { fun => "under_sun", 6 => undef, "more", undef },
121     ];
122     $expected = <<'EOF';
123 ---
124 e
125 ---
126 2.71828
127 ---
128 - pi
129 - is
130 - 3.1416
131 ---
132 6: ~
133 fun: under_sun
134 more: ~
135 EOF
136     $got = &Module::Build::YAML::Dump(@$var);
137     is($got, $expected, "Dump(): multiple, various");
138
139     ##########################################################
140     # Test that a single array ref turns into one document
141     ##########################################################
142     $expected = <<'EOF';
143 ---
144 - e
145 - 2.71828
146 -
147   - pi
148   - is
149   - 3.1416
150 -
151   6: ~
152   fun: under_sun
153   more: ~
154 EOF
155     $got = &Module::Build::YAML::Dump($var);
156     is($got, $expected, "Dump(): single array of various");
157
158     ##########################################################
159     # Test Object-Oriented Flavor of the API
160     ##########################################################
161     my $y = Module::Build::YAML->new();
162     $got = $y->Dump($var);
163     is($got, $expected, "Dump(): single array of various (OO)");
164
165     ##########################################################
166     # Test Quoting Conditions (newlines, quotes, tildas, undefs)
167     ##########################################################
168     $var = {
169         'foo01' => '`~!@#$%^&*()_+-={}|[]\\;\':",./?<>
170 <nl>',
171         'foo02' => '~!@#$%^&*()_+-={}|[]\\;:,./<>?',
172         'foo03' => undef,
173         'foo04' => '~',
174     };
175     $expected = <<'EOF';
176 ---
177 foo01: "`~!@#$%^&*()_+-={}|[]\;':\",./?<>\n<nl>"
178 foo02: "~!@#$%^&*()_+-={}|[]\;:,./<>?"
179 foo03: ~
180 foo04: "~"
181 EOF
182     $got = &Module::Build::YAML::Dump($var);
183     is($got, $expected, "Dump(): tricky embedded characters");
184
185     $var = {
186         'foo10' => undef,
187         'foo40' => '!',
188         'foo41' => '@',
189         'foo42' => '#',
190         'foo43' => '$',
191         'foo44' => '%',
192         'foo45' => '^',
193         'foo47' => '&',
194         'foo48' => '*',
195         'foo49' => '(',
196         'foo50' => ')',
197         'foo51' => '_',
198         'foo52' => '+',
199         'foo53' => '-',
200         'foo54' => '=',
201         'foo55' => '{',
202         'foo56' => '}',
203         'foo57' => '|',
204         'foo58' => '[',
205         'foo59' => ']',
206         'foo60' => '\\',
207         'foo61' => ';',
208         'foo62' => ':',
209         'foo63' => ',',
210         'foo64' => '.',
211         'foo65' => '/',
212         'foo66' => '<',
213         'foo67' => '>',
214         'foo68' => '?',
215         'foo69' => '\'',
216         'foo70' => '"',
217         'foo71' => '`',
218         'foo72' => '
219 ',
220     };
221     $expected = <<'EOF';
222 ---
223 foo10: ~
224 foo40: "!"
225 foo41: '@'
226 foo42: "#"
227 foo43: $
228 foo44: %
229 foo45: "^"
230 foo47: "&"
231 foo48: "*"
232 foo49: "("
233 foo50: ")"
234 foo51: _
235 foo52: +
236 foo53: -
237 foo54: =
238 foo55: "{"
239 foo56: "}"
240 foo57: "|"
241 foo58: "["
242 foo59: "]"
243 foo60: \
244 foo61: ;
245 foo62: :
246 foo63: ,
247 foo64: .
248 foo65: /
249 foo66: '<'
250 foo67: '>'
251 foo68: "?"
252 foo69: "'"
253 foo70: '"'
254 foo71: "`"
255 foo72: "\n"
256 EOF
257     $got = &Module::Build::YAML::Dump($var);
258     is($got, $expected, "Dump(): tricky embedded characters (singles)");
259
260 }
261
262