| 1 | #!/usr/bin/env perl |
| 2 | |
| 3 | use strictscip-perl cpan Catmandu 1.2025 strict/; |
| 4 | use warningsscip-perl cpan Catmandu 1.2025 warnings/; |
| 5 | use Test::Morescip-perl cpan Catmandu 1.2025 Test/More/; |
| 6 | use Test::Exceptionscip-perl cpan Catmandu 1.2025 Test/Exception/; |
| 7 | use utf8scip-perl cpan Catmandu 1.2025 utf8/; |
| 8 | |
| 9 | my $pkg; |
| 10 | |
| 11 | BEGIN { |
| 12 | $pkg = 'Catmandu::Importer::YAML'; |
| 13 | use_okscip-perl cpan Catmandu 1.2025 main/use_ok(). $pkg; |
| 14 | } |
| 15 | require_okscip-perl cpan Catmandu 1.2025 main/require_ok(). $pkg; |
| 16 | |
| 17 | my $data = [ |
| 18 | {name => 'Patrick', age => '39'}, |
| 19 | {name => 'Nicolas', age => '34'}, |
| 20 | {name => '村上 春樹', age => '65'}, |
| 21 | ]; |
| 22 | |
| 23 | my $yaml = <<EOF; |
| 24 | --- |
| 25 | name: Patrick |
| 26 | age: 39 |
| 27 | --- |
| 28 | name: Nicolas |
| 29 | age: 34 |
| 30 | --- |
| 31 | name: 村上 春樹 |
| 32 | age: 65 |
| 33 | |
| 34 | EOF |
| 35 | |
| 36 | my $importer = $pkg->newscip-perl cpan Catmandu 1.2025 main/new().(file => \$yaml); |
| 37 | |
| 38 | isa_okscip-perl cpan Catmandu 1.2025 main/isa_ok(). $importer, $pkg; |
| 39 | |
| 40 | my $arr = $importer->to_arrayscip-perl cpan Catmandu 1.2025 main/to_array().; |
| 41 | is_deeplyscip-perl cpan Catmandu 1.2025 main/is_deeply(). $arr, $data, 'checking correct import'; |
| 42 | |
| 43 | isscip-perl cpan Catmandu 1.2025 main/is(). $arr->[2]->{name}, '村上 春樹', 'checking utf8 issues'; |
| 44 | |
| 45 | $importer = $pkg->newscip-perl cpan Catmandu 1.2025 main/new().(file => 't/non_ascii.yaml'); |
| 46 | |
| 47 | isscip-perl cpan Catmandu 1.2025 main/is(). $importer->countscip-perl cpan Catmandu 1.2025 main/count()., 1000, 'parsed non ascii file'; |
| 48 | |
| 49 | done_testing 6; |
| 50 |