]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixed minor problem with -gnu closing brace placement; added test
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 14 May 2020 04:41:51 +0000 (21:41 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 14 May 2020 04:41:51 +0000 (21:41 -0700)
lib/Perl/Tidy/Formatter.pm
t/snippets/expect/gnu6.def [new file with mode: 0644]
t/snippets/expect/gnu6.gnu [new file with mode: 0644]
t/snippets/gnu6.in [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets20.t

index 2568f1ce366872a1d1d4f313dc9689e17ceecbb4..8032b8329bb564c45fba283c3b84cd5cfa1ba20b 100644 (file)
@@ -7213,6 +7213,9 @@ sub copy_token_as_type {
 
         my $in_continued_quote =
           ( $Ktoken_vars == $K_first ) && $line_of_tokens->{_starting_in_quote};
+        if ( $max_index_to_go == 0 ) {
+            $starting_in_quote = $in_continued_quote;
+        }
 
         # Define the indentation that this token would have if it started
         # a new line.  We start by using the default formula.
@@ -7379,7 +7382,6 @@ sub copy_token_as_type {
 
         my $rtok_first = $rLL->[$K_first];
 
-        $starting_in_quote = $line_of_tokens->{_starting_in_quote};
         my $in_quote = $line_of_tokens->{_ending_in_quote};
         $ending_in_quote = $in_quote;
         my $guessed_indentation_level =
diff --git a/t/snippets/expect/gnu6.def b/t/snippets/expect/gnu6.def
new file mode 100644 (file)
index 0000000..cdacc48
--- /dev/null
@@ -0,0 +1,12 @@
+# the closing braces should have the same position for these two hashes with -gnu
+    $var1 = {
+        'foo10' => undef,
+        'foo72' => '
+',
+    };
+    $var2 = {
+        'foo72' => '
+',
+        'foo10' => undef,
+    };
+
diff --git a/t/snippets/expect/gnu6.gnu b/t/snippets/expect/gnu6.gnu
new file mode 100644 (file)
index 0000000..af7299c
--- /dev/null
@@ -0,0 +1,12 @@
+    # the closing braces should have the same position for these two hashes with -gnu
+    $var1 = {
+        'foo10' => undef,
+        'foo72' => '
+',
+            };
+    $var2 = {
+        'foo72' => '
+',
+        'foo10' => undef,
+            };
+
diff --git a/t/snippets/gnu6.in b/t/snippets/gnu6.in
new file mode 100644 (file)
index 0000000..cdacc48
--- /dev/null
@@ -0,0 +1,12 @@
+# the closing braces should have the same position for these two hashes with -gnu
+    $var1 = {
+        'foo10' => undef,
+        'foo72' => '
+',
+    };
+    $var2 = {
+        'foo72' => '
+',
+        'foo10' => undef,
+    };
+
index 1638e6c93b994d6b271a380262b7377aa2c1c94d..3e63a2d9af468ee9c250cfa66269ee63e5962573 100644 (file)
 ../snippets20.t        wc.def
 ../snippets20.t        wc.wc1
 ../snippets20.t        wc.wc2
+../snippets20.t        ce2.ce
+../snippets20.t        ce2.def
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets20.t        ce2.ce
-../snippets20.t        ce2.def
+../snippets20.t        gnu6.def
+../snippets20.t        gnu6.gnu
index 1845695ff18d9596ea5cf25c277e00a33abdbdc6..4be39332116f7dc8a4c3d30f4f2d002df083b737 100644 (file)
@@ -9,6 +9,8 @@
 #6 wc.wc2
 #7 ce2.ce
 #8 ce2.def
+#9 gnu6.def
+#10 gnu6.gnu
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -28,6 +30,7 @@ BEGIN {
     $rparams = {
         'ce'     => "-cuddled-blocks",
         'def'    => "",
+        'gnu'    => "-gnu",
         'space6' => <<'----------',
 -nwrs="+ - / *"
 -nwls="+ - / *"
@@ -62,6 +65,21 @@ else {
     # Is Perl being run from a slave editor or graphical debugger?
     ...
 }
+----------
+
+        'gnu6' => <<'----------',
+# the closing braces should have the same position for these two hashes with -gnu
+    $var1 = {
+        'foo10' => undef,
+        'foo72' => '
+',
+    };
+    $var2 = {
+        'foo72' => '
+',
+        'foo10' => undef,
+    };
+
 ----------
 
         'space6' => <<'----------',
@@ -279,6 +297,44 @@ else {
 }
 #8...........
         },
+
+        'gnu6.def' => {
+            source => "gnu6",
+            params => "def",
+            expect => <<'#9...........',
+# the closing braces should have the same position for these two hashes with -gnu
+    $var1 = {
+        'foo10' => undef,
+        'foo72' => '
+',
+    };
+    $var2 = {
+        'foo72' => '
+',
+        'foo10' => undef,
+    };
+
+#9...........
+        },
+
+        'gnu6.gnu' => {
+            source => "gnu6",
+            params => "gnu",
+            expect => <<'#10...........',
+    # the closing braces should have the same position for these two hashes with -gnu
+    $var1 = {
+        'foo10' => undef,
+        'foo72' => '
+',
+            };
+    $var2 = {
+        'foo72' => '
+',
+        'foo10' => undef,
+            };
+
+#10...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};