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