aboutsummaryrefslogtreecommitdiffstats
path: root/Data-YAML-0.0.6/t/30-output.t
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2012-02-15 23:59:42 +0100
committerMatěj Cepl <mcepl@redhat.com>2012-02-16 00:24:01 +0100
commitd7e73ec4c238d0eb1c5493bb90c022d683123296 (patch)
treed81f22a220c40fd7528e098dd0d22060410415e0 /Data-YAML-0.0.6/t/30-output.t
downloadyamlish-d7e73ec4c238d0eb1c5493bb90c022d683123296.tar.gz
Initial commit with skeleton of the project.
Also added original Perl, together with PHP and Javascript ports.
Diffstat (limited to 'Data-YAML-0.0.6/t/30-output.t')
-rw-r--r--Data-YAML-0.0.6/t/30-output.t107
1 files changed, 107 insertions, 0 deletions
diff --git a/Data-YAML-0.0.6/t/30-output.t b/Data-YAML-0.0.6/t/30-output.t
new file mode 100644
index 0000000..56cfb0a
--- /dev/null
+++ b/Data-YAML-0.0.6/t/30-output.t
@@ -0,0 +1,107 @@
+use strict;
+use warnings;
+use Test::More tests => 9;
+use Data::Dumper;
+
+use Data::YAML::Writer;
+
+my $out = [
+ "---",
+ "bill-to:",
+ " address:",
+ " city: 'Royal Oak'",
+ " lines: \"458 Walkman Dr.\\nSuite #292\\n\"",
+ " postal: 48046",
+ " state: MI",
+ " family: Dumars",
+ " given: Chris",
+ "comments: \"Late afternoon is best. Backup contact is Nancy Billsmer \@ 338-4338\\n\"",
+ "date: 2001-01-23",
+ "invoice: 34843",
+ "product:",
+ " -",
+ " description: Basketball",
+ " price: 450.00",
+ " quantity: 4",
+ " sku: BL394D",
+ " -",
+ " description: 'Super Hoop'",
+ " price: 2392.00",
+ " quantity: 1",
+ " sku: BL4438H",
+ "tax: 251.42",
+ "total: 4443.52",
+ "...",
+];
+
+my $in = {
+ 'bill-to' => {
+ 'given' => 'Chris',
+ 'address' => {
+ 'city' => 'Royal Oak',
+ 'postal' => '48046',
+ 'lines' => "458 Walkman Dr.\nSuite #292\n",
+ 'state' => 'MI'
+ },
+ 'family' => 'Dumars'
+ },
+ 'invoice' => '34843',
+ 'date' => '2001-01-23',
+ 'tax' => '251.42',
+ 'product' => [
+ {
+ 'sku' => 'BL394D',
+ 'quantity' => '4',
+ 'price' => '450.00',
+ 'description' => 'Basketball'
+ },
+ {
+ 'sku' => 'BL4438H',
+ 'quantity' => '1',
+ 'price' => '2392.00',
+ 'description' => 'Super Hoop'
+ }
+ ],
+ 'comments' =>
+ "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n",
+ 'total' => '4443.52'
+};
+
+my @buf1 = ();
+my @buf2 = ();
+my $buf3 = '';
+
+my @destination = (
+ {
+ name => 'Array reference',
+ destination => \@buf1,
+ normalise => sub { return \@buf1 },
+ },
+ {
+ name => 'Closure',
+ destination => sub { push @buf2, shift },
+ normalise => sub { return \@buf2 },
+ },
+ {
+ name => 'Scalar',
+ destination => \$buf3,
+ normalise => sub {
+ my @ar = split( /\n/, $buf3 );
+ return \@ar;
+ },
+ },
+);
+
+for my $dest ( @destination ) {
+ my $name = $dest->{name};
+ ok my $yaml = Data::YAML::Writer->new, "$name: Created";
+ isa_ok $yaml, 'Data::YAML::Writer';
+
+ $yaml->write( $in, $dest->{destination} );
+ my $got = $dest->{normalise}->();
+ unless ( is_deeply $got, $out, "$name: Result matches" ) {
+ local $Data::Dumper::Useqq = $Data::Dumper::Useqq = 1;
+ diag( Data::Dumper->Dump( [$got], ['$got'] ) );
+ diag( Data::Dumper->Dump( [$out], ['$expected'] ) );
+ }
+}