]> git.donarmstrong.com Git - perltidy.git/commitdiff
added test for -novalign and update manual
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 11 Sep 2021 01:07:33 +0000 (18:07 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 11 Sep 2021 01:07:33 +0000 (18:07 -0700)
bin/perltidy
t/snippets/expect/novalign.def [new file with mode: 0644]
t/snippets/expect/novalign.novalign [new file with mode: 0644]
t/snippets/novalign.in [new file with mode: 0644]
t/snippets/novalign.par [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets25.t [new file with mode: 0644]

index 7041cf67e759421d8472429800620c1f803524ec..49c7411a940f80d38ed0a6054ca5023c2f674281 100755 (executable)
@@ -3130,20 +3130,22 @@ will flatten this down to one line:
     # perltidy (default)
     my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
-This formatting loses important information.  If we place a side comment on one
-of the lines, for example, we get the following result with with default formatting 
-parameters:
+This formatting loses the nice structure.  If we place a side comment anywhere
+between the opening and closing parens, the original line break points are
+retained.  For example,
 
     my @list = (
-        1,    # a side comment, comment, or blank keeps list intact
+        1,    # a side comment forces the original line breakpoints to be kept
         1, 1,
         1, 2, 1,
         1, 3, 3, 1,
         1, 4, 6, 4, 1,
     );
 
+The side comment can be a single hash symbol without any text.
 We could achieve the same result with a blank line or full comment
-anywhere between the opening and closing parens.
+anywhere between the opening and closing parens.  Vertical alignment
+of the list items will still occur if possible.
 
 For another possibility see
 the -fs flag in L<Skipping Selected Sections of Code>.
@@ -3163,9 +3165,8 @@ the original style, yields
                 1, 3, 3, 1,
                 1, 4, 6, 4, 1,);
 
-A disadvantage of this flag is that all tables in the file
-must already be nicely formatted.  
-
+A disadvantage of this flag compared to the methods discussed above is that all
+tables in the file must already be nicely formatted.
 
 =item B<-mft=n>,  B<--maximum-fields-per-table=n>
 
@@ -4018,8 +4019,8 @@ aligned in the following statement:
             Proto    => 'tcp'
         );
 
-Vertical alignment can be completely turned off using B<-novalign>, a flag
-mainly intended for debugging.  However, vertical alignment can be forced to
+Vertical alignment can be completely turned off using the B<-novalign> flag
+mentioned below.  However, vertical alignment can be forced to
 stop and restart by selectively introducing blank lines.  For example, a blank
 has been inserted in the following code to keep somewhat similar things
 aligned.
@@ -4050,6 +4051,15 @@ For example,
             Proto=> 'tcp'
         );
 
+=over 4
+
+=item B<Completely turning off vertical alignment with -novalign>
+
+The default is to use vertical alignment, but bertical alignment can be
+completely turned of with the B<-novalign> flag.
+
+=back
+
 =head2 Other Controls
 
 =over 4
diff --git a/t/snippets/expect/novalign.def b/t/snippets/expect/novalign.def
new file mode 100644 (file)
index 0000000..61f326d
--- /dev/null
@@ -0,0 +1,9 @@
+# simple vertical alignment of '=' and '#'
+my $lines     = 0;    # checksum: #lines
+my $bytes     = 0;    # checksum: #bytes
+my $sum       = 0;    # checksum: system V sum
+my $patchdata = 0;    # saw patch data
+my $pos       = 0;    # start of patch data
+my $endkit    = 0;    # saw end of kit
+my $fail      = 0;    # failed
+
diff --git a/t/snippets/expect/novalign.novalign b/t/snippets/expect/novalign.novalign
new file mode 100644 (file)
index 0000000..ee672bc
--- /dev/null
@@ -0,0 +1,9 @@
+# simple vertical alignment of '=' and '#'
+my $lines = 0;    # checksum: #lines
+my $bytes = 0;    # checksum: #bytes
+my $sum = 0;    # checksum: system V sum
+my $patchdata = 0;    # saw patch data
+my $pos = 0;    # start of patch data
+my $endkit = 0;    # saw end of kit
+my $fail = 0;    # failed
+
diff --git a/t/snippets/novalign.in b/t/snippets/novalign.in
new file mode 100644 (file)
index 0000000..ee672bc
--- /dev/null
@@ -0,0 +1,9 @@
+# simple vertical alignment of '=' and '#'
+my $lines = 0;    # checksum: #lines
+my $bytes = 0;    # checksum: #bytes
+my $sum = 0;    # checksum: system V sum
+my $patchdata = 0;    # saw patch data
+my $pos = 0;    # start of patch data
+my $endkit = 0;    # saw end of kit
+my $fail = 0;    # failed
+
diff --git a/t/snippets/novalign.par b/t/snippets/novalign.par
new file mode 100644 (file)
index 0000000..230ed03
--- /dev/null
@@ -0,0 +1 @@
+-novalign
index 147bab5c76b18644ff4b45b1d93663e3c7179011..bffe841de199b1fdf461c40fedb4cfc2d4e08dd6 100644 (file)
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
+../snippets25.t        novalign.def
+../snippets25.t        novalign.novalign
diff --git a/t/snippets25.t b/t/snippets25.t
new file mode 100644 (file)
index 0000000..cd91e97
--- /dev/null
@@ -0,0 +1,141 @@
+# Created with: ./make_t.pl
+
+# Contents:
+#1 novalign.def
+#2 novalign.novalign
+
+# To locate test #13 you can search for its name or the string '#13'
+
+use strict;
+use Test::More;
+use Carp;
+use Perl::Tidy;
+my $rparams;
+my $rsources;
+my $rtests;
+
+BEGIN {
+
+    ###########################################
+    # BEGIN SECTION 1: Parameter combinations #
+    ###########################################
+    $rparams = {
+        'def'      => "",
+        'novalign' => "-novalign",
+    };
+
+    ############################
+    # BEGIN SECTION 2: Sources #
+    ############################
+    $rsources = {
+
+        'novalign' => <<'----------',
+# simple vertical alignment of '=' and '#'
+my $lines = 0;    # checksum: #lines
+my $bytes = 0;    # checksum: #bytes
+my $sum = 0;    # checksum: system V sum
+my $patchdata = 0;    # saw patch data
+my $pos = 0;    # start of patch data
+my $endkit = 0;    # saw end of kit
+my $fail = 0;    # failed
+
+----------
+    };
+
+    ####################################
+    # BEGIN SECTION 3: Expected output #
+    ####################################
+    $rtests = {
+
+        'novalign.def' => {
+            source => "novalign",
+            params => "def",
+            expect => <<'#1...........',
+# simple vertical alignment of '=' and '#'
+my $lines     = 0;    # checksum: #lines
+my $bytes     = 0;    # checksum: #bytes
+my $sum       = 0;    # checksum: system V sum
+my $patchdata = 0;    # saw patch data
+my $pos       = 0;    # start of patch data
+my $endkit    = 0;    # saw end of kit
+my $fail      = 0;    # failed
+
+#1...........
+        },
+
+        'novalign.novalign' => {
+            source => "novalign",
+            params => "novalign",
+            expect => <<'#2...........',
+# simple vertical alignment of '=' and '#'
+my $lines = 0;    # checksum: #lines
+my $bytes = 0;    # checksum: #bytes
+my $sum = 0;    # checksum: system V sum
+my $patchdata = 0;    # saw patch data
+my $pos = 0;    # start of patch data
+my $endkit = 0;    # saw end of kit
+my $fail = 0;    # failed
+
+#2...........
+        },
+    };
+
+    my $ntests = 0 + keys %{$rtests};
+    plan tests => $ntests;
+}
+
+###############
+# EXECUTE TESTS
+###############
+
+foreach my $key ( sort keys %{$rtests} ) {
+    my $output;
+    my $sname  = $rtests->{$key}->{source};
+    my $expect = $rtests->{$key}->{expect};
+    my $pname  = $rtests->{$key}->{params};
+    my $source = $rsources->{$sname};
+    my $params = defined($pname) ? $rparams->{$pname} : "";
+    my $stderr_string;
+    my $errorfile_string;
+    my $err = Perl::Tidy::perltidy(
+        source      => \$source,
+        destination => \$output,
+        perltidyrc  => \$params,
+        argv        => '',             # for safety; hide any ARGV from perltidy
+        stderr      => \$stderr_string,
+        errorfile   => \$errorfile_string,    # not used when -se flag is set
+    );
+    if ( $err || $stderr_string || $errorfile_string ) {
+        print STDERR "Error output received for test '$key'\n";
+        if ($err) {
+            print STDERR "An error flag '$err' was returned\n";
+            ok( !$err );
+        }
+        if ($stderr_string) {
+            print STDERR "---------------------\n";
+            print STDERR "<<STDERR>>\n$stderr_string\n";
+            print STDERR "---------------------\n";
+            ok( !$stderr_string );
+        }
+        if ($errorfile_string) {
+            print STDERR "---------------------\n";
+            print STDERR "<<.ERR file>>\n$errorfile_string\n";
+            print STDERR "---------------------\n";
+            ok( !$errorfile_string );
+        }
+    }
+    else {
+        if ( !is( $output, $expect, $key ) ) {
+            my $leno = length($output);
+            my $lene = length($expect);
+            if ( $leno == $lene ) {
+                print STDERR
+"#> Test '$key' gave unexpected output.  Strings differ but both have length $leno\n";
+            }
+            else {
+                print STDERR
+"#> Test '$key' gave unexpected output.  String lengths differ: output=$leno, expected=$lene\n";
+            }
+        }
+    }
+}