5 BEGIN {plan tests => 4}
9 #----------------------------------------------------------------------
10 ## test string->string
11 #----------------------------------------------------------------------
12 my $source_template = <<'EOM';
13 %height=("letter",27.9, "legal",35.6, "arche",121.9, "archd",91.4, "archc",61,
14 "archb",45.7, "archa",30.5, "flsa",33, "flse",33, "halfletter",21.6,
15 "11x17",43.2, "ledger",27.9);
16 %width=("letter",21.6, "legal",21.6, "arche",91.4, "archd",61, "archc",45.7,
17 "archb",30.5, "archa",22.9, "flsa",21.6, "flse",21.6, "halfletter",14,
18 "11x17",27.9, "ledger",43.2);
23 my $expected_output_template=<<'EOM';
25 "letter", 27.9, "legal", 35.6, "arche", 121.9,
26 "archd", 91.4, "archc", 61, "archb", 45.7,
27 "archa", 30.5, "flsa", 33, "flse", 33,
28 "halfletter", 21.6, "11x17", 43.2, "ledger", 27.9
31 "letter", 21.6, "legal", 21.6, "arche", 91.4,
32 "archd", 61, "archc", 45.7, "archb", 30.5,
33 "archa", 22.9, "flsa", 21.6, "flse", 21.6,
34 "halfletter", 14, "11x17", 27.9, "ledger", 43.2
45 $perltidyrc = <<'EOM';
47 --output-line-ending="unix" # use *nix LF EOLs
50 $source = $source_template;
51 $source =~ s/\n/$CR$LF/gmsx;
52 $expected_output = $expected_output_template;
53 $expected_output =~ s/\n/$LF/gmsx;
55 # my ($source_fh, $source_filename) = File::Temp::tempfile(); close $source_filename;
56 my ($output_fh, $output_filename) = File::Temp::tempfile(); close $output_filename;
58 # print STDERR "# source_filename = ", $source_filename, "\n";
59 # print STDERR "# output_filename = ", $output_filename, "\n";
61 # open $source_fh, ">", $source_filename;
62 # binmode $source_fh, ":raw";
63 # print $source_fh $source;
66 # in-memory output (non-UTF8)
70 destination => \$output,
71 perltidyrc => \$perltidyrc,
75 ok($output, $expected_output, "in-memory EOLs (non-UTF8)");
77 # file output (non-UTF8)
80 destination => $output_filename,
81 perltidyrc => \$perltidyrc,
87 open $output_fh, "<", $output_filename;
88 binmode $output_fh, ":raw";
89 $output = <$output_fh>;
92 ok($output, $expected_output, "output file EOLs (non-UTF8)");
94 $perltidyrc = <<'EOM';
96 --character-encoding="utf8" # treat files as UTF-8 (decode and encode)
97 --output-line-ending="unix" # use *nix LF EOLs
101 $source = $source_template;
102 $source =~ s/\n/$CR$LF/gmsx;
103 $expected_output = $expected_output_template;
104 $expected_output =~ s/\n/$LF/gmsx;
106 Perl::Tidy::perltidy(
108 destination => \$output,
109 perltidyrc => \$perltidyrc,
113 ok($output, $expected_output, "in-memory EOLs (UTF8)");
117 Perl::Tidy::perltidy(
119 destination => $output_filename,
120 perltidyrc => \$perltidyrc,
126 open $output_fh, "<", $output_filename;
127 binmode $output_fh, ":raw";
128 $output = <$output_fh>;
131 ok($output, $expected_output, "output file EOLs (UTF8)");
133 # Try to delete the tmpfile;
134 # Comment this out if it causes a failure at Appveyor
135 if ( -e $output_filename ) { unlink $output_filename }