File: UTF8.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (44 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (8)
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
use strict;
use warnings;
# HARNESS-NO-FORMATTER

# Store the default STDOUT and STDERR IO layers for later testing.
# This must happen before we load anything else.
use PerlIO ();
my %Layers;

sub get_layers {
    my $fh = shift;
    return { map {$_ => 1} PerlIO::get_layers($fh) };
}

BEGIN {
    $Layers{STDERR} = get_layers(*STDERR);
    $Layers{STDOUT} = get_layers(*STDOUT);
}

use Test2::Plugin::UTF8;
use Test2::Tools::Basic;
use Test2::Tools::Compare;
use Test2::API qw(test2_stack);

note "pragma"; {
    ok(utf8::is_utf8("癸"), "utf8 pragma is on");
}

note "io_layers"; {
    is get_layers(*STDOUT), $Layers{STDOUT}, "STDOUT encoding is untouched";
    is get_layers(*STDERR), $Layers{STDERR}, "STDERR encoding is untouched";
}

note "format_handles"; {
    my $format = test2_stack()->top->format;
    my $handles = $format->handles or last;
    for my $hn (0 .. @$handles) {
        my $h = $handles->[$hn] || next;
        my $layers = get_layers($h);
        ok($layers->{utf8}, "utf8 is on for formatter handle $hn");
    }
}

done_testing;