Remove unused Module::Build tests
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / mbyaml.t
CommitLineData
a314697d 1#!/usr/local/bin/perl -w
2
dc8021d3 3use strict;
4use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5use MBTest 'no_plan';
a314697d 6
7my ($dir);
8$dir = ".";
9$dir = "t" if (-d "t");
10
11{
f943a5bf 12 use_ok("Module::Build::YAML");
13 my ($expected, $got, $var);
14 ##########################################################
15 # Test a typical-looking Module::Build structure (alphabetized)
16 ##########################################################
17 $var = {
a314697d 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 };
f943a5bf 49 $expected = <<'EOF';
a314697d 50---
51abstract: A framework for building dynamic widgets or full applications in Javascript
52author:
f943a5bf 53 - '"Stephen Adkins" <spadkins@gmail.com>'
a314697d 54build_requires:
55 App::Build: 0
56 File::Spec: 0
57 Module::Build: 0
58dynamic_config: 1
59generated_by: Module::Build version 0.2709
60license: lgpl
61meta-spec:
62 url: http://module-build.sourceforge.net/META-spec-v1.2.html
63 version: 1.2
64name: js-app
65provides:
66 JavaScript::App:
67 file: lib/JavaScript/App.pm
68 version: 0
69requires:
70 App::Options: 0
71resources:
72 license: http://opensource.org/licenses/artistic-license.php
73version: 0.13
74EOF
75 $got = &Module::Build::YAML::Dump($var);
76 is($got, $expected, "Dump(): single deep hash");
77
f943a5bf 78 ##########################################################
79 # Test a typical-looking Module::Build structure (ordered)
80 ##########################################################
81 $expected = <<'EOF';
a314697d 82---
83name: js-app
84version: 0.13
85author:
f943a5bf 86 - '"Stephen Adkins" <spadkins@gmail.com>'
a314697d 87abstract: A framework for building dynamic widgets or full applications in Javascript
88license: lgpl
89resources:
90 license: http://opensource.org/licenses/artistic-license.php
91requires:
92 App::Options: 0
93build_requires:
94 App::Build: 0
95 File::Spec: 0
96 Module::Build: 0
97dynamic_config: 1
98provides:
99 JavaScript::App:
100 file: lib/JavaScript/App.pm
101 version: 0
102generated_by: Module::Build version 0.2709
103meta-spec:
104 url: http://module-build.sourceforge.net/META-spec-v1.2.html
105 version: 1.2
106EOF
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
f943a5bf 111 ##########################################################
112 # Test that an array turns into multiple documents
113 ##########################################################
a314697d 114 $var = [
115 "e",
116 2.71828,
117 [ "pi", "is", 3.1416 ],
118 { fun => "under_sun", 6 => undef, "more", undef },
119 ];
f943a5bf 120 $expected = <<'EOF';
a314697d 121---
122e
123---
1242.71828
125---
126- pi
127- is
128- 3.1416
129---
f943a5bf 1306: ~
a314697d 131fun: under_sun
f943a5bf 132more: ~
a314697d 133EOF
134 $got = &Module::Build::YAML::Dump(@$var);
135 is($got, $expected, "Dump(): multiple, various");
136
f943a5bf 137 ##########################################################
138 # Test that a single array ref turns into one document
139 ##########################################################
140 $expected = <<'EOF';
a314697d 141---
142- e
143- 2.71828
144-
145 - pi
146 - is
147 - 3.1416
148-
f943a5bf 149 6: ~
a314697d 150 fun: under_sun
f943a5bf 151 more: ~
a314697d 152EOF
153 $got = &Module::Build::YAML::Dump($var);
154 is($got, $expected, "Dump(): single array of various");
155
f943a5bf 156 ##########################################################
157 # Test Object-Oriented Flavor of the API
158 ##########################################################
a314697d 159 my $y = Module::Build::YAML->new();
160 $got = $y->Dump($var);
161 is($got, $expected, "Dump(): single array of various (OO)");
f943a5bf 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---
175foo01: "`~!@#$%^&*()_+-={}|[]\;':\",./?<>\n<nl>"
176foo02: "~!@#$%^&*()_+-={}|[]\;:,./<>?"
177foo03: ~
178foo04: "~"
179EOF
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---
221foo10: ~
222foo40: "!"
223foo41: '@'
224foo42: "#"
225foo43: $
226foo44: %
227foo45: "^"
228foo47: "&"
229foo48: "*"
230foo49: "("
231foo50: ")"
232foo51: _
233foo52: +
234foo53: -
235foo54: =
236foo55: "{"
237foo56: "}"
238foo57: "|"
239foo58: "["
240foo59: "]"
241foo60: \
242foo61: ;
243foo62: :
244foo63: ,
245foo64: .
246foo65: /
247foo66: '<'
248foo67: '>'
249foo68: "?"
250foo69: "'"
251foo70: '"'
252foo71: "`"
253foo72: "\n"
254EOF
255 $got = &Module::Build::YAML::Dump($var);
256 is($got, $expected, "Dump(): tricky embedded characters (singles)");
257
a314697d 258}
259
260