]> git.donarmstrong.com Git - perltidy.git/commitdiff
New test files for various UTF-8 scenarios requiring the -eos flag
authorKenneth Olwing <knth@cpan.org>
Tue, 25 Jan 2022 11:30:32 +0000 (12:30 +0100)
committerKenneth Olwing <knth@cpan.org>
Tue, 25 Jan 2022 11:30:32 +0000 (12:30 +0100)
t/testwide-passthrough.pl.src [new file with mode: 0644]
t/testwide-passthrough.t [new file with mode: 0644]
t/testwide-tidy.pl.src [new file with mode: 0644]
t/testwide-tidy.pl.srctdy [new file with mode: 0644]
t/testwide-tidy.t [new file with mode: 0644]

diff --git a/t/testwide-passthrough.pl.src b/t/testwide-passthrough.pl.src
new file mode 100644 (file)
index 0000000..626de45
--- /dev/null
@@ -0,0 +1,5 @@
+# nothing to tidy or run
+"Plain";
+"Zwölf große Boxkämpfer jagen Vik quer über den Sylter.";
+"Jeż wlókł gęś. Uf! Bądź choć przy nim, stań!";
+"Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.";
diff --git a/t/testwide-passthrough.t b/t/testwide-passthrough.t
new file mode 100644 (file)
index 0000000..d48944b
--- /dev/null
@@ -0,0 +1,125 @@
+use strict;\r
+use warnings;\r
+use utf8;\r
+\r
+use FindBin qw($Bin);\r
+use File::Temp qw(tempfile);\r
+use Test::More;\r
+\r
+BEGIN {unshift @INC, "./"}\r
+use Perl::Tidy; \r
+\r
+# The test file has no tidying needs but is UTF-8 encoded, so all passes\r
+# through perltidy should read/write identical contents (previously only\r
+# file test behaved correctly)\r
+\r
+plan(tests => 6);\r
+\r
+test_all();\r
+\r
+sub test_all\r
+{\r
+       my $test_file = "$Bin/testwide-passthrough.pl.src";\r
+       test_file2file($test_file);\r
+       test_scalar2scalar($test_file);\r
+       test_scalararray2scalararray($test_file);\r
+}\r
+\r
+sub test_file2file\r
+{\r
+       my $test_file = shift;\r
+       \r
+       my $tmp_file = File::Temp->new( TMPDIR => 1 );\r
+\r
+       my $source      = $test_file;\r
+       my $destination = $tmp_file->filename();\r
+\r
+       note("Testing file2file: '$source' => '$destination'\n");\r
+\r
+       my $tidyresult = Perl::Tidy::perltidy\r
+                                                                       (\r
+                                                                               argv   => '-utf8',\r
+                                                                               source => $source,\r
+                                                                               destination => $destination\r
+                                                                       );\r
+       ok(!$tidyresult, 'perltidy');\r
+\r
+       my $source_hex = unpack('H*', slurp_raw($source));\r
+       my $destination_hex = unpack('H*', slurp_raw($destination));\r
+\r
+       note("Comparing contents:\n  $source_hex\n  $destination_hex\n");\r
+       ok($source_hex eq $destination_hex, 'file content compare');\r
+}\r
+\r
+sub test_scalar2scalar\r
+{\r
+       my $testfile = shift;\r
+       \r
+       my $source      = slurp_raw($testfile);\r
+       my $destination;\r
+\r
+       note("Testing scalar2scalar\n");\r
+\r
+       my $tidyresult = Perl::Tidy::perltidy\r
+                                                                       (\r
+                                                                               argv   => '-utf8 -eos',\r
+                                                                               source => \$source,\r
+                                                                               destination => \$destination\r
+                                                                       );\r
+       ok(!$tidyresult, 'perltidy');\r
+\r
+       my $source_hex = unpack('H*', $source);\r
+       my $destination_hex = unpack('H*', $destination);\r
+\r
+       note("Comparing contents:\n  $source_hex\n  $destination_hex\n");\r
+       ok($source_hex eq $destination_hex, 'scalar content compare');\r
+}\r
+\r
+sub test_scalararray2scalararray\r
+{\r
+       my $testfile = shift;\r
+       \r
+       my $source      = [ lines_raw($testfile) ];\r
+       my $destination = [];\r
+\r
+       note("Testing scalararray2scalararray\n");\r
+\r
+       my $tidyresult = Perl::Tidy::perltidy\r
+                                                                       (\r
+                                                                               argv   => '-utf8 -eos',\r
+                                                                               source => $source,\r
+                                                                               destination => $destination\r
+                                                                       );\r
+       ok(!$tidyresult, 'perltidy');\r
+\r
+       my $source_hex = join('', map { unpack('H*', $_) } @$source );\r
+       my $destination_hex = join('', map { unpack('H*', $_) } @$destination);\r
+\r
+       note("Comparing contents:\n  $source_hex\n  $destination_hex\n");\r
+       ok($source_hex eq $destination_hex, 'scalararray content compare');\r
+}\r
+\r
+sub slurp_raw\r
+{\r
+       my $filename = shift;\r
+       \r
+    open(TMP, '<', $filename);\r
+    binmode(TMP, ':raw');\r
+       local $/;\r
+       my $contents = <TMP>;\r
+       close(TMP);\r
+       \r
+       return $contents;\r
+}\r
+\r
+sub lines_raw\r
+{\r
+       my $filename = shift;\r
+       \r
+    open(TMP, '<', $filename);\r
+    binmode(TMP, ':raw');\r
+       my @contents = <TMP>;\r
+       close(TMP);\r
+       \r
+       return @contents;\r
+}\r
diff --git a/t/testwide-tidy.pl.src b/t/testwide-tidy.pl.src
new file mode 100644 (file)
index 0000000..30bc8c1
--- /dev/null
@@ -0,0 +1,8 @@
+# really simple
+@a=
+(
+"Plain",
+"Zwölf große Boxkämpfer jagen Vik quer über den Sylter.",
+"Jeż wlókł gęś. Uf! Bądź choć przy nim, stań!",
+"Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.",
+);
diff --git a/t/testwide-tidy.pl.srctdy b/t/testwide-tidy.pl.srctdy
new file mode 100644 (file)
index 0000000..bd478cc
--- /dev/null
@@ -0,0 +1,7 @@
+# really simple
+@a = (
+    "Plain",
+    "Zwölf große Boxkämpfer jagen Vik quer über den Sylter.",
+    "Jeż wlókł gęś. Uf! Bądź choć przy nim, stań!",
+    "Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.",
+);
diff --git a/t/testwide-tidy.t b/t/testwide-tidy.t
new file mode 100644 (file)
index 0000000..dd2b4de
--- /dev/null
@@ -0,0 +1,125 @@
+use strict;\r
+use warnings;\r
+use utf8;\r
+\r
+use FindBin qw($Bin);\r
+use File::Temp qw(tempfile);\r
+use Test::More;\r
+\r
+BEGIN {unshift @INC, "./"}\r
+use Perl::Tidy; \r
+\r
+# The test file is UTF-8 encoded\r
+\r
+plan(tests => 6);\r
+\r
+test_all();\r
+\r
+sub test_all\r
+{\r
+       my $test_file = "$Bin/testwide-tidy.pl.src";\r
+       my $tidy_file = "$Bin/testwide-tidy.pl.srctdy";\r
+       my $tidy_hex = unpack('H*', slurp_raw($tidy_file));\r
+       test_file2file($test_file, $tidy_hex);\r
+       test_scalar2scalar($test_file, $tidy_hex);\r
+       test_scalararray2scalararray($test_file, $tidy_hex);\r
+}\r
+\r
+sub test_file2file\r
+{\r
+       my $test_file = shift;\r
+       my $tidy_hex = shift;\r
+\r
+       my $tmp_file = File::Temp->new( TMPDIR => 1 );\r
+\r
+       my $source      = $test_file;\r
+       my $destination = $tmp_file->filename();\r
+\r
+       note("Testing file2file: '$source' => '$destination'\n");\r
+\r
+       my $tidyresult = Perl::Tidy::perltidy\r
+                                                                       (\r
+                                                                               argv   => '-utf8',\r
+                                                                               source => $source,\r
+                                                                               destination => $destination\r
+                                                                       );\r
+       ok(!$tidyresult, 'perltidy');\r
+\r
+       my $destination_hex = unpack('H*', slurp_raw($destination));\r
+\r
+       note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");\r
+       ok($tidy_hex eq $destination_hex, 'file content compare');\r
+}\r
+\r
+sub test_scalar2scalar\r
+{\r
+       my $test_file = shift;\r
+       my $tidy_hex = shift;\r
+       \r
+       my $source      = slurp_raw($test_file);\r
+       my $destination;\r
+\r
+       note("Testing scalar2scalar\n");\r
+\r
+       my $tidyresult = Perl::Tidy::perltidy\r
+                                                                       (\r
+                                                                               argv   => '-utf8 -eos',\r
+                                                                               source => \$source,\r
+                                                                               destination => \$destination\r
+                                                                       );\r
+       ok(!$tidyresult, 'perltidy');\r
+\r
+       my $destination_hex = unpack('H*', $destination);\r
+\r
+       note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");\r
+       ok($tidy_hex eq $destination_hex, 'scalar content compare');\r
+}\r
+\r
+sub test_scalararray2scalararray\r
+{\r
+       my $test_file = shift;\r
+       my $tidy_hex = shift;\r
+       \r
+       my $source      = [ lines_raw($test_file) ];\r
+       my $destination = [];\r
+\r
+       note("Testing scalararray2scalararray\n");\r
+\r
+       my $tidyresult = Perl::Tidy::perltidy\r
+                                                                       (\r
+                                                                               argv   => '-utf8 -eos',\r
+                                                                               source => $source,\r
+                                                                               destination => $destination\r
+                                                                       );\r
+       ok(!$tidyresult, 'perltidy');\r
+\r
+       my $destination_hex = join('', map { unpack('H*', $_) } @$destination);\r
+\r
+       note("Comparing contents:\n  $tidy_hex\n  $destination_hex\n");\r
+       ok($tidy_hex eq $destination_hex, 'scalararray content compare');\r
+}\r
+\r
+sub slurp_raw\r
+{\r
+       my $filename = shift;\r
+       \r
+    open(TMP, '<', $filename);\r
+    binmode(TMP, ':raw');\r
+       local $/;\r
+       my $contents = <TMP>;\r
+       close(TMP);\r
+       \r
+       return $contents;\r
+}\r
+\r
+sub lines_raw\r
+{\r
+       my $filename = shift;\r
+       \r
+    open(TMP, '<', $filename);\r
+    binmode(TMP, ':raw');\r
+       my @contents = <TMP>;\r
+       close(TMP);\r
+       \r
+       return @contents;\r
+}\r