File: utf8.t

package info (click to toggle)
libpod-spell-perl 1.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 288 kB
  • ctags: 23
  • sloc: perl: 493; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,546 bytes parent folder | download | duplicates (2)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use 5.008; # for utf8
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Deep;
use File::Temp;

use Pod::Spell;
use Pod::Wordlist;

my $builder = Test::More->builder;
binmode $builder->output,         ":utf8";
binmode $builder->failure_output, ":utf8";
binmode $builder->todo_output,    ":utf8";
binmode STDOUT, ":utf8";

my $podfile  = File::Temp->new;

binmode($podfile, ":utf8");

print $podfile <<'ENDPOD';
=encoding utf8

=for :stopwords
virtE<ugrave> résumé

=head1 Testing virtE<ugrave> & résumé

Our virtE<ugrave> & virtù & résumé for Mengué in 日本

=cut
ENDPOD

my @cases = (
    {
        label => "wide chars allowed",
        options => {},
        expected => [ qw( Testing Our for Mengué in 日本 ) ],
    },
    {
        label => "wide chars stripped",
        options => { no_wide_chars => 1 },
        expected => [ qw( Testing Our for Mengué in ) ],
    },
);

for my $c ( @cases ) {

    my $textfile = File::Temp->new;
    binmode $textfile, ":utf8";

    # reread from beginning
    $podfile->seek( 0, 0 );

    my $p = new_ok 'Pod::Spell' => [ debug => 1, %{ $c->{options} } ];

    $p->parse_from_filehandle( $podfile, $textfile );

    # reread from beginning
    $textfile->seek( 0, 0 );

    my $in = do { local $/ = undef, <$textfile> };

    my @words = split " ", $in;

    my @expected = @{ $c->{expected} };

    is scalar @words, scalar @expected, "$c->{label}: word count";

    cmp_deeply \@words, bag( @expected ), "$c->{label}: words match"
        or diag "@words";
}

done_testing;