]> git.donarmstrong.com Git - perltidy.git/blob - t/testwide.t
New upstream version 20210717
[perltidy.git] / t / testwide.t
1 use strict;
2 use utf8;
3 use Test;
4 use Carp;
5 use FindBin;
6 BEGIN {unshift @INC, "./"}
7 BEGIN {plan tests => 3}
8 use Perl::Tidy; 
9
10
11 my $source = <<'EOM';
12 %pangrams=("Plain","ASCII",
13 "Zwölf große Boxkämpfer jagen Vik quer über den Sylter.","DE",
14 "Jeż wlókł gęś. Uf! Bądź choć przy nim, stań!","PL",
15 "Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.","RU");
16 EOM
17
18 my $expected_output=<<'EOM';
19 %pangrams = (
20              "Plain",                                                  "ASCII",
21              "Zwölf große Boxkämpfer jagen Vik quer über den Sylter.", "DE",
22              "Jeż wlókł gęś. Uf! Bądź choć przy nim, stań!",           "PL",
23              "Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.",        "RU"
24             );
25 EOM
26
27 my $perltidyrc = <<'EOM';
28 -gnu -enc=utf8
29 EOM
30
31 my $output;
32
33 Perl::Tidy::perltidy(
34     source      => \$source,
35     destination => \$output,
36     perltidyrc  => \$perltidyrc,
37     argv        => '-nsyn',
38 );
39
40 ok($output, $expected_output);
41
42 Perl::Tidy::perltidy(
43     source      => $FindBin::Bin . '/testwide.pl.src',
44     destination => \$output,
45     perltidyrc  => \$perltidyrc,
46     argv        => '-nsyn',
47 );
48
49 ok($output, $expected_output);
50
51 # Test writing encoded output to stdout with the -st flag
52 # References: RT #133166, RT #133171, git #35
53 $output = "";
54 do {
55
56     # Send STDOUT to a temporary file
57     use File::Temp ();
58     my $fh      = new File::Temp();
59     my $tmpfile = $fh->filename;
60
61     # Note that we are not specifying an encoding here. Perltidy should do that.
62     local *STDOUT;
63     open STDOUT, '>', $tmpfile or die "Can't open tmpfile: $!";
64
65     Perl::Tidy::perltidy(
66         source => \$source,
67         ##destination => ... we are using -st, so no destination is specified
68         perltidyrc => \$perltidyrc,
69         argv       => '-nsyn -st',  # added -st
70     );
71     close STDOUT;
72
73     # Read the temporary file back in. Note that here we need to specify
74     # the encoding.
75     open TMP, '<', $tmpfile;
76     binmode TMP, ":raw:encoding(UTF-8)";
77     while ( my $line = <TMP> ) { $output .= $line }
78 };
79
80 ok($output, $expected_output);
81