16fb12b70Safresh1use strict; 26fb12b70Safresh1use warnings; 36fb12b70Safresh1use lib 't/lib/'; 4*b8851fccSafresh1use Test::More 0.88; 56fb12b70Safresh1use TestBridge; 6*b8851fccSafresh1use File::Spec::Functions 'catfile'; 7*b8851fccSafresh1use File::Temp 0.19; # newdir 86fb12b70Safresh1 96fb12b70Safresh1#--------------------------------------------------------------------------# 106fb12b70Safresh1# This file test that the YAML.pm compatible Dump/Load/DumpFile/LoadFile 116fb12b70Safresh1# work as documented 126fb12b70Safresh1#--------------------------------------------------------------------------# 136fb12b70Safresh1 146fb12b70Safresh1use CPAN::Meta::YAML; 156fb12b70Safresh1 166fb12b70Safresh1{ 176fb12b70Safresh1 my $scalar = 'this is a string'; 186fb12b70Safresh1 my $arrayref = [ 1 .. 5 ]; 196fb12b70Safresh1 my $hashref = { alpha => 'beta', gamma => 'delta' }; 206fb12b70Safresh1 216fb12b70Safresh1 my $yamldump = CPAN::Meta::YAML::Dump( $scalar, $arrayref, $hashref ); 226fb12b70Safresh1 my @yamldocsloaded = CPAN::Meta::YAML::Load($yamldump); 236fb12b70Safresh1 cmp_deeply( 246fb12b70Safresh1 [ @yamldocsloaded ], 256fb12b70Safresh1 [ $scalar, $arrayref, $hashref ], 266fb12b70Safresh1 "Functional interface: Dump to Load roundtrip works as expected" 276fb12b70Safresh1 ); 286fb12b70Safresh1} 296fb12b70Safresh1 306fb12b70Safresh1{ 316fb12b70Safresh1 my $scalar = 'this is a string'; 326fb12b70Safresh1 my $arrayref = [ 1 .. 5 ]; 336fb12b70Safresh1 my $hashref = { alpha => 'beta', gamma => 'delta' }; 346fb12b70Safresh1 35*b8851fccSafresh1 my $tempdir = File::Temp->newdir("YTXXXXXX", TMPDIR => 1 ); 36*b8851fccSafresh1 my $filename = catfile($tempdir, 'compat'); 376fb12b70Safresh1 386fb12b70Safresh1 my $rv = CPAN::Meta::YAML::DumpFile( 396fb12b70Safresh1 $filename, $scalar, $arrayref, $hashref); 406fb12b70Safresh1 ok($rv, "DumpFile returned true value"); 416fb12b70Safresh1 426fb12b70Safresh1 my @yamldocsloaded = CPAN::Meta::YAML::LoadFile($filename); 436fb12b70Safresh1 cmp_deeply( 446fb12b70Safresh1 [ @yamldocsloaded ], 456fb12b70Safresh1 [ $scalar, $arrayref, $hashref ], 466fb12b70Safresh1 "Functional interface: DumpFile to LoadFile roundtrip works as expected" 476fb12b70Safresh1 ); 486fb12b70Safresh1} 496fb12b70Safresh1 506fb12b70Safresh1{ 516fb12b70Safresh1 my $str = "This is not real YAML"; 526fb12b70Safresh1 my @yamldocsloaded; 536fb12b70Safresh1 eval { @yamldocsloaded = CPAN::Meta::YAML::Load("$str\n"); }; 546fb12b70Safresh1 error_like( 556fb12b70Safresh1 qr/CPAN::Meta::YAML failed to classify line '$str'/, 566fb12b70Safresh1 "Correctly failed to load non-YAML string" 576fb12b70Safresh1 ); 586fb12b70Safresh1} 596fb12b70Safresh1 606fb12b70Safresh1done_testing; 61