]> git.donarmstrong.com Git - perltidy.git/commitdiff
added alignment test cases
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 1 Dec 2018 01:44:55 +0000 (17:44 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 1 Dec 2018 01:44:55 +0000 (17:44 -0800)
15 files changed:
t/snippets/align24.in [new file with mode: 0644]
t/snippets/align25.in [new file with mode: 0644]
t/snippets/align26.in [new file with mode: 0644]
t/snippets/align27.in [new file with mode: 0644]
t/snippets/else1.in [new file with mode: 0644]
t/snippets/else2.in [new file with mode: 0644]
t/snippets/expect/align12.def
t/snippets/expect/align24.def [new file with mode: 0644]
t/snippets/expect/align25.def [new file with mode: 0644]
t/snippets/expect/align26.def [new file with mode: 0644]
t/snippets/expect/align27.def [new file with mode: 0644]
t/snippets/expect/else1.def [new file with mode: 0644]
t/snippets/expect/else2.def [new file with mode: 0644]
t/snippets/expect/smart.def
t/snippets14.t [new file with mode: 0644]

diff --git a/t/snippets/align24.in b/t/snippets/align24.in
new file mode 100644 (file)
index 0000000..5b78b02
--- /dev/null
@@ -0,0 +1,7 @@
+# Do not align interior fat commas here; differnt container types
+my $p    = TAP::Parser::SubclassTest->new(
+    {
+        exec    => [ $cat            => $file ],
+        sources => { MySourceHandler => { accept_all => 1 } },
+    }
+);
diff --git a/t/snippets/align25.in b/t/snippets/align25.in
new file mode 100644 (file)
index 0000000..ad093b9
--- /dev/null
@@ -0,0 +1,5 @@
+# do not align commas here; different container types
+is_deeply( [ $a,        $a ], [ $b,               $c ] );
+is_deeply( { foo => $a, bar => $a }, { foo => $b, bar => $c } );
+is_deeply( [ \$a,       \$a ], [ \$b,             \$c ] );
+
diff --git a/t/snippets/align26.in b/t/snippets/align26.in
new file mode 100644 (file)
index 0000000..f8a5db8
--- /dev/null
@@ -0,0 +1,3 @@
+#  align first of multiple equals
+$SIG{PIPE}=sub{die"writingtoaclosedpipe"};#1=
+$SIG{HUP}=$SIG{BREAK}=$SIG{INT}=$SIG{TERM};#3=
diff --git a/t/snippets/align27.in b/t/snippets/align27.in
new file mode 100644 (file)
index 0000000..80ff92b
--- /dev/null
@@ -0,0 +1,4 @@
+# do not align first equals here (unmatched commas on left side of =)
+my ( $self, $name, $type ) = @_;
+my $html_toc_fh            = $self->{_html_toc_fh};
+my $html_prelim_fh            = $self->{_html_prelim_fh};
diff --git a/t/snippets/else1.in b/t/snippets/else1.in
new file mode 100644 (file)
index 0000000..981ec27
--- /dev/null
@@ -0,0 +1,4 @@
+# pad after 'if' when followed by 'elsif'
+if    ( not defined $dir or not length $dir ) { $rslt = ''; }
+elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s )    { $rslt = $dir; }
+else                                          { $rslt = vmspath($dir); }
diff --git a/t/snippets/else2.in b/t/snippets/else2.in
new file mode 100644 (file)
index 0000000..b9f934c
--- /dev/null
@@ -0,0 +1,3 @@
+       # no pad after 'if' when followed by 'else'
+        if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() }
+        else                   { print " " }
index 741505508933682a554a410d555659970082f596..7d52a6489661bffb2469e19c2bcbe854fc1f5453 100644 (file)
@@ -1,3 +1,3 @@
-    my $type = shift || "o";
-    my $fname = ( $type eq 'oo' ? 'orte_city' : 'orte' );
+    my $type   = shift || "o";
+    my $fname  = ( $type eq 'oo' ? 'orte_city' : 'orte' );
     my $suffix = ( $coord_system eq 'standard' ? '' : '-orig' );
diff --git a/t/snippets/expect/align24.def b/t/snippets/expect/align24.def
new file mode 100644 (file)
index 0000000..8e3bf60
--- /dev/null
@@ -0,0 +1,7 @@
+# Do not align interior fat commas here; differnt container types
+my $p = TAP::Parser::SubclassTest->new(
+    {
+        exec    => [ $cat => $file ],
+        sources => { MySourceHandler => { accept_all => 1 } },
+    }
+);
diff --git a/t/snippets/expect/align25.def b/t/snippets/expect/align25.def
new file mode 100644 (file)
index 0000000..72d462c
--- /dev/null
@@ -0,0 +1,5 @@
+# do not align commas here; different container types
+is_deeply( [ $a, $a ], [ $b, $c ] );
+is_deeply( { foo => $a, bar => $a }, { foo => $b, bar => $c } );
+is_deeply( [ \$a, \$a ], [ \$b, \$c ] );
+
diff --git a/t/snippets/expect/align26.def b/t/snippets/expect/align26.def
new file mode 100644 (file)
index 0000000..8e0ceef
--- /dev/null
@@ -0,0 +1,3 @@
+#  align first of multiple equals
+$SIG{PIPE} = sub { die "writingtoaclosedpipe" };      #1=
+$SIG{HUP}  = $SIG{BREAK} = $SIG{INT} = $SIG{TERM};    #3=
diff --git a/t/snippets/expect/align27.def b/t/snippets/expect/align27.def
new file mode 100644 (file)
index 0000000..038630d
--- /dev/null
@@ -0,0 +1,4 @@
+# do not align first equals here (unmatched commas on left side of =)
+my ( $self, $name, $type ) = @_;
+my $html_toc_fh    = $self->{_html_toc_fh};
+my $html_prelim_fh = $self->{_html_prelim_fh};
diff --git a/t/snippets/expect/else1.def b/t/snippets/expect/else1.def
new file mode 100644 (file)
index 0000000..981ec27
--- /dev/null
@@ -0,0 +1,4 @@
+# pad after 'if' when followed by 'elsif'
+if    ( not defined $dir or not length $dir ) { $rslt = ''; }
+elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s )    { $rslt = $dir; }
+else                                          { $rslt = vmspath($dir); }
diff --git a/t/snippets/expect/else2.def b/t/snippets/expect/else2.def
new file mode 100644 (file)
index 0000000..4b9d945
--- /dev/null
@@ -0,0 +1,3 @@
+        # no pad after 'if' when followed by 'else'
+        if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() }
+        else                   { print " " }
index 41b03cdf61ff2afc1a682f8843425470748098e2..cf1600c5509b84a84ceb57fa31efebf2222a9cc3 100644 (file)
@@ -46,20 +46,20 @@ b_const      ~~ a_const;
 [ keys %main:: ] ~~ \%::;
 \%::             ~~ [];
 []               ~~ \%::;
-{ "" => 1 } ~~ [undef];
-[undef] ~~ { "" => 1 };
-{ foo => 1 } ~~ qr/^(fo[ox])$/;
-qr/^(fo[ox])$/ ~~ { foo => 1 };
-+{ 0 .. 100 }  ~~ qr/[13579]$/;
-qr/[13579]$/   ~~ +{ 0 .. 100 };
+{ "" => 1 }      ~~ [undef];
+[undef]          ~~ { "" => 1 };
+{ foo => 1 }     ~~ qr/^(fo[ox])$/;
+qr/^(fo[ox])$/   ~~ { foo => 1 };
++{ 0 .. 100 }    ~~ qr/[13579]$/;
+qr/[13579]$/     ~~ +{ 0 .. 100 };
 +{ foo => 1, bar => 2 } ~~ "foo";
 "foo" ~~ +{ foo => 1, bar => 2 };
 +{ foo => 1, bar => 2 } ~~ "baz";
 "baz" ~~ +{ foo => 1, bar => 2 };
-[]    ~~ [];
-[]    ~~ [];
-[]    ~~ [1];
-[1]   ~~ [];
+[]  ~~ [];
+[]  ~~ [];
+[]  ~~ [1];
+[1] ~~ [];
 [ ["foo"], ["bar"] ] ~~ [ qr/o/, qr/a/ ];
 [ qr/o/, qr/a/ ] ~~ [ ["foo"], ["bar"] ];
 [ "foo", "bar" ] ~~ [ qr/o/, qr/a/ ];
diff --git a/t/snippets14.t b/t/snippets14.t
new file mode 100644 (file)
index 0000000..013585e
--- /dev/null
@@ -0,0 +1,121 @@
+# Created with: ./make_t.pl
+
+# Contents:
+#1 else1.def
+#2 else2.def
+
+# To locate test #13 you can search for its name or the string '#13'
+
+use strict;
+use Test;
+use Carp;
+use Perl::Tidy;
+my $rparams;
+my $rsources;
+my $rtests;
+
+BEGIN {
+
+    ###########################################
+    # BEGIN SECTION 1: Parameter combinations #
+    ###########################################
+    $rparams = { 'def' => "", };
+
+    ############################
+    # BEGIN SECTION 2: Sources #
+    ############################
+    $rsources = {
+
+        'else1' => <<'----------',
+# pad after 'if' when followed by 'elsif'
+if    ( not defined $dir or not length $dir ) { $rslt = ''; }
+elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s )    { $rslt = $dir; }
+else                                          { $rslt = vmspath($dir); }
+----------
+
+        'else2' => <<'----------',
+       # no pad after 'if' when followed by 'else'
+        if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() }
+        else                   { print " " }
+----------
+    };
+
+    ####################################
+    # BEGIN SECTION 3: Expected output #
+    ####################################
+    $rtests = {
+
+        'else1.def' => {
+            source => "else1",
+            params => "def",
+            expect => <<'#1...........',
+# pad after 'if' when followed by 'elsif'
+if    ( not defined $dir or not length $dir ) { $rslt = ''; }
+elsif ( $dir =~ /^\$\([^\)]+\)\Z(?!\n)/s )    { $rslt = $dir; }
+else                                          { $rslt = vmspath($dir); }
+#1...........
+        },
+
+        'else2.def' => {
+            source => "else2",
+            params => "def",
+            expect => <<'#2...........',
+        # no pad after 'if' when followed by 'else'
+        if ( $m = $g[$x][$y] ) { print $$m{v}; $$m{i}->() }
+        else                   { print " " }
+#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 ) {
+        if ($err) {
+            print STDERR
+"This error received calling Perl::Tidy with '$sname' + '$pname'\n";
+            ok( !$err );
+        }
+        if ($stderr_string) {
+            print STDERR "---------------------\n";
+            print STDERR "<<STDERR>>\n$stderr_string\n";
+            print STDERR "---------------------\n";
+            print STDERR
+"This error received calling Perl::Tidy with '$sname' + '$pname'\n";
+            ok( !$stderr_string );
+        }
+        if ($errorfile_string) {
+            print STDERR "---------------------\n";
+            print STDERR "<<.ERR file>>\n$errorfile_string\n";
+            print STDERR "---------------------\n";
+            print STDERR
+"This error received calling Perl::Tidy with '$sname' + '$pname'\n";
+            ok( !$errorfile_string );
+        }
+    }
+    else {
+        ok( $output, $expect );
+    }
+}