File: 21_yamlpm_compat.t

package info (click to toggle)
libcpan-meta-yaml-perl 0.020-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 412 kB
  • sloc: perl: 1,354; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,757 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use strict;
use warnings;
use lib 't/lib/';
use Test::More 0.88;
use TestBridge;
use File::Spec::Functions 'catfile';
use File::Temp 0.19; # newdir

#--------------------------------------------------------------------------#
# This file test that the YAML.pm compatible Dump/Load/DumpFile/LoadFile
# work as documented
#--------------------------------------------------------------------------#

use CPAN::Meta::YAML;

{
    my $scalar = 'this is a string';
    my $arrayref = [ 1 .. 5 ];
    my $hashref = { alpha => 'beta', gamma => 'delta' };

    my $yamldump = CPAN::Meta::YAML::Dump( $scalar, $arrayref, $hashref );
    my @yamldocsloaded = CPAN::Meta::YAML::Load($yamldump);
    cmp_deeply(
        [ @yamldocsloaded ],
        [ $scalar, $arrayref, $hashref ],
        "Functional interface: Dump to Load roundtrip works as expected"
    );
}

{
    my $scalar = 'this is a string';
    my $arrayref = [ 1 .. 5 ];
    my $hashref = { alpha => 'beta', gamma => 'delta' };

    my $tempdir = File::Temp->newdir("YTXXXXXX", TMPDIR => 1 );
    my $filename = catfile($tempdir, 'compat');

    my $rv = CPAN::Meta::YAML::DumpFile(
        $filename, $scalar, $arrayref, $hashref);
    ok($rv, "DumpFile returned true value");

    my @yamldocsloaded = CPAN::Meta::YAML::LoadFile($filename);
    cmp_deeply(
        [ @yamldocsloaded ],
        [ $scalar, $arrayref, $hashref ],
        "Functional interface: DumpFile to LoadFile roundtrip works as expected"
    );
}

{
    my $str = "This is not real YAML";
    my @yamldocsloaded;
    eval { @yamldocsloaded = CPAN::Meta::YAML::Load("$str\n"); };
    error_like(
        qr/CPAN::Meta::YAML failed to classify line '$str'/,
        "Correctly failed to load non-YAML string"
    );
}

done_testing;