-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With that YAML::PP will automatically decode input and encode output when using load_string and dump_string. Default is off for backwards compatibility.
- Loading branch information
Showing
8 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Data::Dumper; | ||
use YAML::PP; | ||
use Encode; | ||
|
||
my $p_utf8 = YAML::PP->new( | ||
header => 0, | ||
utf8 => 1, | ||
); | ||
my $p_perl = YAML::PP->new( | ||
header => 0, | ||
utf8 => 0, | ||
); | ||
my $p_default = YAML::PP->new(header => 0); | ||
|
||
|
||
my $utf8 = <<'EOM'; | ||
[bär] | ||
EOM | ||
|
||
my $perl = decode_utf8 $utf8; | ||
|
||
my $bear = "bär"; | ||
my $bear_perl = decode_utf8 $bear; | ||
|
||
subtest 'load unicode' => sub { | ||
my $data = $p_utf8->load_string($utf8); | ||
is $data->[0], $bear_perl, 'load utf8'; | ||
|
||
eval { | ||
$data = $p_utf8->load_string($perl); | ||
}; | ||
my $err = $@; | ||
like $err, qr{does not map to Unicode}, 'load decoded with utf8 loader fails'; | ||
|
||
$data = $p_perl->load_string($perl); | ||
is $data->[0], $bear_perl, 'load decoded with perl loader'; | ||
|
||
$data = $p_perl->load_string($utf8); | ||
is $data->[0], $bear, 'load utf8 with perl loader'; | ||
|
||
$data = $p_default->load_string($perl); | ||
is $data->[0], $bear_perl, 'load decoded with default loader'; | ||
|
||
$data = $p_default->load_string($utf8); | ||
is $data->[0], 'bär', 'load utf8 with default loader'; | ||
}; | ||
|
||
subtest 'dump unicode' => sub { | ||
my $yaml = $p_utf8->dump_string([$bear_perl]); | ||
$yaml =~ s/^- //; chomp $yaml; | ||
is $yaml, $bear, 'dump perl data with utf8 dumper -> utf8'; | ||
|
||
$yaml = $p_utf8->dump_string([$bear]); | ||
$yaml =~ s/^- //; chomp $yaml; | ||
is $yaml, encode_utf8($bear), 'dump utf8 data with utf8 dumper -> rubbish'; | ||
|
||
$yaml = $p_perl->dump_string([$bear_perl]); | ||
$yaml =~ s/^- //; chomp $yaml; | ||
is $yaml, $bear_perl, 'dump perl data with perl dumper -> perl'; | ||
|
||
$yaml = $p_perl->dump_string([$bear]); | ||
$yaml =~ s/^- //; chomp $yaml; | ||
$yaml, $bear, 'dump utf8 data with perl dumper -> utf8'; | ||
}; | ||
|
||
done_testing; |