1use strict;
2use warnings;
3use lib 't/lib/';
4use Test::More 0.99;
5use TestBridge;
6use File::Temp qw(tempfile);
7
8#--------------------------------------------------------------------------#
9# This file test that the YAML.pm compatible Dump/Load/DumpFile/LoadFile
10# work as documented
11#--------------------------------------------------------------------------#
12
13use CPAN::Meta::YAML;
14
15{
16    my $scalar = 'this is a string';
17    my $arrayref = [ 1 .. 5 ];
18    my $hashref = { alpha => 'beta', gamma => 'delta' };
19
20    my $yamldump = CPAN::Meta::YAML::Dump( $scalar, $arrayref, $hashref );
21    my @yamldocsloaded = CPAN::Meta::YAML::Load($yamldump);
22    cmp_deeply(
23        [ @yamldocsloaded ],
24        [ $scalar, $arrayref, $hashref ],
25        "Functional interface: Dump to Load roundtrip works as expected"
26    );
27}
28
29{
30    my $scalar = 'this is a string';
31    my $arrayref = [ 1 .. 5 ];
32    my $hashref = { alpha => 'beta', gamma => 'delta' };
33
34    my ($fh, $filename) = tempfile;
35    close $fh; # or LOCK_SH will hang
36
37    my $rv = CPAN::Meta::YAML::DumpFile(
38        $filename, $scalar, $arrayref, $hashref);
39    ok($rv, "DumpFile returned true value");
40
41    my @yamldocsloaded = CPAN::Meta::YAML::LoadFile($filename);
42    cmp_deeply(
43        [ @yamldocsloaded ],
44        [ $scalar, $arrayref, $hashref ],
45        "Functional interface: DumpFile to LoadFile roundtrip works as expected"
46    );
47}
48
49{
50    my $str = "This is not real YAML";
51    my @yamldocsloaded;
52    eval { @yamldocsloaded = CPAN::Meta::YAML::Load("$str\n"); };
53    error_like(
54        qr/CPAN::Meta::YAML failed to classify line '$str'/,
55        "Correctly failed to load non-YAML string"
56    );
57}
58
59done_testing;
60