1#!/usr/bin/perl
2#
3# Test Pod::Text UTF-8 handling, with and without PerlIO.
4#
5# Copyright 2002, 2004, 2006-2010, 2012, 2014, 2018, 2020
6#     Russ Allbery <rra@cpan.org>
7#
8# This program is free software; you may redistribute it and/or modify it
9# under the same terms as Perl itself.
10#
11# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
12
13use 5.008;
14use strict;
15use warnings;
16
17use lib 't/lib';
18
19use Test::More tests => 17;
20use Test::Podlators qw(test_snippet_with_io);
21
22BEGIN {
23    use_ok('Pod::Text');
24}
25
26# Force UTF-8 on all relevant file handles.  Hide this in a string eval so
27# that older versions of Perl don't croak and minimum-version tests still
28# pass.
29#
30## no critic (BuiltinFunctions::ProhibitStringyEval)
31## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
32eval 'binmode(\*STDOUT, ":encoding(utf-8)")';
33my $builder = Test::More->builder;
34eval 'binmode($builder->output, ":encoding(utf-8)")';
35eval 'binmode($builder->failure_output, ":encoding(utf-8)")';
36## use critic
37
38# For each of the UTF-8 snippets, check them with and without PerlIO layers.
39for my $snippet (qw(late-encoding s-whitespace utf8)) {
40    test_snippet_with_io('Pod::Text', "text/$snippet");
41    test_snippet_with_io('Pod::Text', "text/$snippet", { perlio_utf8 => 1 });
42}
43
44# Load a snippet in ISO 8859-1 that forces the output to be in UTF-8.
45test_snippet_with_io('Pod::Text', 'text/utf8-iso',
46    { encoding => 'iso-8859-1' });
47test_snippet_with_io('Pod::Text', 'text/utf8-iso',
48    { encoding => 'iso-8859-1', perlio_utf8 => 1 });
49