6 BEGIN { unshift @INC, "./" }
7 BEGIN { plan tests => 3 }
11 %pangrams=("Plain","ASCII",
12 "Zwölf große Boxkämpfer jagen Vik quer über den Sylter.","DE",
13 "Jeż wlókł gęś. Uf! Bądź choć przy nim, stań!","PL",
14 "Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.","RU");
17 my $expected_output = <<'EOM';
20 "Zwölf große Boxkämpfer jagen Vik quer über den Sylter.", "DE",
21 "Jeż wlókł gęś. Uf! Bądź choć przy nim, stań!", "PL",
22 "Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.", "RU"
26 my $perltidyrc = <<'EOM';
32 # The source is in character mode here, so perltidy will not decode.
33 # So here we do not need to set -eos or -neos
36 destination => \$output,
37 perltidyrc => \$perltidyrc,
41 ok( $output, $expected_output );
44 source => $FindBin::Bin . '/testwide.pl.src',
45 destination => \$output,
46 perltidyrc => \$perltidyrc,
50 # We have to be careful here ... In this test we are comparing $output to a
51 # source string which is in character mode (since it is in this file declared
52 # with 'use utf8'). We need to compare strings which have the same storage
55 # The internal storage mode of $output was character mode (decoded) for
56 # vesions prior to 20220217.02, but is byte mode (encoded) for the latest
57 # version of perltidy.
59 # The following statement will decode $output if it is stored in byte mode,
60 # and leave it unchanged (and return an error) otherwise. So this will work
61 # with all version of perltidy. See https://perldoc.perl.org/utf8
62 utf8::decode($output);
64 ok( $output, $expected_output );
66 # Test writing encoded output to stdout with the -st flag
67 # References: RT #133166, RT #133171, git #35
71 # Send STDOUT to a temporary file
73 my $fh = new File::Temp();
74 my $tmpfile = $fh->filename;
76 # Note that we are not specifying an encoding here. Perltidy should do that.
78 open STDOUT, '>', $tmpfile or die "Can't open tmpfile: $!";
82 ##destination => ... we are using -st, so no destination is specified
83 perltidyrc => \$perltidyrc,
84 argv => '-nsyn -st', # added -st
88 # Read the temporary file back in. Note that here we need to specify
90 open TMP, '<', $tmpfile;
91 binmode TMP, ":raw:encoding(UTF-8)";
92 while ( my $line = <TMP> ) { $output .= $line }
95 ok( $output, $expected_output );