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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
use strict;
use File::Temp;
use Test;
use Carp;
BEGIN {plan tests => 4}
use Perl::Tidy;
#----------------------------------------------------------------------
## test string->string
#----------------------------------------------------------------------
my $source_template = <<'EOM';
%height=("letter",27.9, "legal",35.6, "arche",121.9, "archd",91.4, "archc",61,
"archb",45.7, "archa",30.5, "flsa",33, "flse",33, "halfletter",21.6,
"11x17",43.2, "ledger",27.9);
%width=("letter",21.6, "legal",21.6, "arche",91.4, "archd",61, "archc",45.7,
"archb",30.5, "archa",22.9, "flsa",21.6, "flse",21.6, "halfletter",14,
"11x17",27.9, "ledger",43.2);
EOM
my $perltidyrc;
my $expected_output_template=<<'EOM';
%height = (
"letter", 27.9, "legal", 35.6, "arche", 121.9,
"archd", 91.4, "archc", 61, "archb", 45.7,
"archa", 30.5, "flsa", 33, "flse", 33,
"halfletter", 21.6, "11x17", 43.2, "ledger", 27.9
);
%width = (
"letter", 21.6, "legal", 21.6, "arche", 91.4,
"archd", 61, "archc", 45.7, "archb", 30.5,
"archa", 22.9, "flsa", 21.6, "flse", 21.6,
"halfletter", 14, "11x17", 27.9, "ledger", 43.2
);
EOM
my $source;
my $output;
my $expected_output;
my $CR = chr(015);
my $LF = chr(012);
$perltidyrc = <<'EOM';
-gnu
--output-line-ending="unix" # use *nix LF EOLs
EOM
$source = $source_template;
$source =~ s/\n/$CR$LF/gmsx;
$expected_output = $expected_output_template;
$expected_output =~ s/\n/$LF/gmsx;
# my ($source_fh, $source_filename) = File::Temp::tempfile(); close $source_filename;
my ($output_fh, $output_filename) = File::Temp::tempfile(); close $output_filename;
# print STDERR "# source_filename = ", $source_filename, "\n";
# print STDERR "# output_filename = ", $output_filename, "\n";
# open $source_fh, ">", $source_filename;
# binmode $source_fh, ":raw";
# print $source_fh $source;
# close $source_fh;
# in-memory output (non-UTF8)
Perl::Tidy::perltidy(
source => \$source,
destination => \$output,
perltidyrc => \$perltidyrc,
argv => '',
);
ok($output, $expected_output, "in-memory EOLs (non-UTF8)");
# file output (non-UTF8)
Perl::Tidy::perltidy(
source => \$source,
destination => $output_filename,
perltidyrc => \$perltidyrc,
argv => '',
);
{# slurp entire file
local $/ = undef;
open $output_fh, "<", $output_filename;
binmode $output_fh, ":raw";
$output = <$output_fh>;
}
ok($output, $expected_output, "output file EOLs (non-UTF8)");
$perltidyrc = <<'EOM';
-gnu
--character-encoding="utf8" # treat files as UTF-8 (decode and encode)
--output-line-ending="unix" # use *nix LF EOLs
EOM
# in-memory (UTF8)
$source = $source_template;
$source =~ s/\n/$CR$LF/gmsx;
$expected_output = $expected_output_template;
$expected_output =~ s/\n/$LF/gmsx;
Perl::Tidy::perltidy(
source => \$source,
destination => \$output,
perltidyrc => \$perltidyrc,
argv => '',
);
ok($output, $expected_output, "in-memory EOLs (UTF8)");
# file output (UTF8)
Perl::Tidy::perltidy(
source => \$source,
destination => $output_filename,
perltidyrc => \$perltidyrc,
argv => '',
);
{# slurp entire file
local $/ = undef;
open $output_fh, "<", $output_filename;
binmode $output_fh, ":raw";
$output = <$output_fh>;
}
ok($output, $expected_output, "output file EOLs (UTF8)");
|