App-Music-ChordPro

 view release on metacpan or  search on metacpan

t/50_encodings.t  view on Meta::CPAN

			   'Sub Títlë',
			  ]
	   };

is_deeply( { %{ $s->{songs}->[0] } }, $song, "Song contents" );

mkdir("out") unless -d "out";

$data = encode("UTF-8", $data);

my @BOMs = qw( UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE );
my @noBOMs = qw( ISO-8859-1 UTF-8 );

my %enc2bom = map { $_ => encode($_, "\x{feff}") } @BOMs;

enctest( $_, 1 ) for @noBOMs;
enctest($_) for @BOMs;

done_testing( 3 * ( 1 + 4*(@noBOMs + @BOMs) ) );

sub enctest {
    my ( $enc, $nobom ) = @_;
    my $encoded = $data;
    _enctest( $encoded, $enc, $nobom );
    $encoded = $data;
    $encoded =~ s/\n/\x0a/g;
    _enctest( $encoded, $enc, $nobom, "LF" );
    $encoded = $data;
    $encoded =~ s/\n/\x0d/g;

t/50_encodings.t  view on Meta::CPAN

    from_to( $encoded, "UTF-8", $enc );
    unless ( $nobom ) {
	BAIL_OUT("Unknown encoding: $enc") unless $enc2bom{$enc};
	$encoded = $enc2bom{$enc} . $encoded;
    }

    my $fn = "out/$enc.cho";
    open( my $fh, ">:raw", $fn ) or die("$fn: $!\n");
    print $fh $encoded;
    close($fh);
    $enc .= " (no BOM)" if $nobom;
    $enc .= " ($crlf)" if $crlf;

    my $s = ChordPro::Songbook->new;
    eval { $s->parse_file($fn) } or diag("$@");
    ok( scalar( @{ $s->{songs} } ) == 1, "$enc: One song" );
    isa_ok( $s->{songs}->[0], 'ChordPro::Song', "It's a song" );
    $song->{source}->{file} = $fn;
    is_deeply( { %{ $s->{songs}->[0] } }, $song, "Song contents" );

    unlink($fn);



( run in 0.531 second using v1.01-cache-2.11-cpan-e9daa2b36ef )