Commit | Line | Data |
a314697d |
1 | #!/usr/local/bin/perl -w |
2 | |
dc8021d3 |
3 | use strict; |
4 | use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib'; |
5 | use MBTest 'no_plan'; |
a314697d |
6 | |
7 | my ($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 | --- |
51 | abstract: A framework for building dynamic widgets or full applications in Javascript |
52 | author: |
f943a5bf |
53 | - '"Stephen Adkins" <spadkins@gmail.com>' |
a314697d |
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 | |
f943a5bf |
78 | ########################################################## |
79 | # Test a typical-looking Module::Build structure (ordered) |
80 | ########################################################## |
81 | $expected = <<'EOF'; |
a314697d |
82 | --- |
83 | name: js-app |
84 | version: 0.13 |
85 | author: |
f943a5bf |
86 | - '"Stephen Adkins" <spadkins@gmail.com>' |
a314697d |
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 | |
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 | --- |
122 | e |
123 | --- |
124 | 2.71828 |
125 | --- |
126 | - pi |
127 | - is |
128 | - 3.1416 |
129 | --- |
f943a5bf |
130 | 6: ~ |
a314697d |
131 | fun: under_sun |
f943a5bf |
132 | more: ~ |
a314697d |
133 | EOF |
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 |
152 | EOF |
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 | --- |
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 | |
a314697d |
258 | } |
259 | |
260 | |