[Rt-commit] rt branch, 4.0/text-wrap-and-quoting-long-lines, updated. rt-4.0.6-251-gf7100a4

Jim Brandt jbrandt at bestpractical.com
Wed Sep 5 08:44:26 EDT 2012


The branch, 4.0/text-wrap-and-quoting-long-lines has been updated
       via  f7100a4b9c4f15446c21575af6c77476a41e2b7b (commit)
      from  b83cb65eca749b21f152cc97f2425a94f6eec414 (commit)

Summary of changes:
 lib/RT/Transaction.pm |  8 +++--
 t/api/transaction.t   | 91 ++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 86 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit f7100a4b9c4f15446c21575af6c77476a41e2b7b
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Aug 30 16:23:20 2012 -0400

    When wrapping, keep existing line breaks
    
    When wrapping, honor existing line breaks and only wrap within
    a line. This avoids combining intentional multi-line text into
    a single paragraph.

diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 59695e1..6b10048 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -430,8 +430,12 @@ sub QuoteWrap {
         my $col = $args{cols} - (length $ref->{quoter});
         my $wrapper = Text::Wrapper->new( columns => $col );
 
-        my $tmp = join ' ', split /\n/, $ref->{text};
-        my $wrap = $wrapper->wrap($tmp);
+        # Wrap on individual lines to honor incoming line breaks
+        # Otherwise deliberate separate lines (like a list or a sig)
+        # all get combined incorrectly into single paragraphs.
+
+        my @lines = split /\n/, $ref->{text};
+        my $wrap = join '', map { $wrapper->wrap($_) } @lines;
         my $quoter = $ref->{quoter};
 
         # Only add the space if actually quoting
diff --git a/t/api/transaction.t b/t/api/transaction.t
index 9bcb536..f903b46 100644
--- a/t/api/transaction.t
+++ b/t/api/transaction.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use RT;
-use RT::Test tests => 16;
+use RT::Test tests => 19;
 
 use_ok('RT::Transaction');
 
@@ -92,20 +92,20 @@ This is a line that is longer than the 70 characters that will demonstrate quoti
     my $txns = $ticket->Transactions;
     my $txn = $txns->Next;
 
-    my $expected = <<'QUOTED';
+    my $expected = <<QUOTED;
+> # # This is a line that is longer than the 70 characters that will
+> # # demonstrate quoting when text is wrapped to multiple lines.
 > # # This is a line that is longer than the 70 characters that will
-> # # demonstrate quoting when text is wrapped to multiple lines. This is
-> # # a line that is longer than the 70 characters that will demonstrate
-> # # quoting when text is wrapped to multiple lines.
+> # # demonstrate quoting when text is wrapped to multiple lines.
+> > This is a line that is longer than the 70 characters that will
+> > demonstrate quoting when text is wrapped to multiple lines.
 > > This is a line that is longer than the 70 characters that will
-> > demonstrate quoting when text is wrapped to multiple lines. This is a
-> > line that is longer than the 70 characters that will demonstrate
-> > quoting when text is wrapped to multiple lines.
+> > demonstrate quoting when text is wrapped to multiple lines.
 > 
 > This is a line that is longer than the 70 characters that will
-> demonstrate quoting when text is wrapped to multiple lines. This is a
-> line that is longer than the 70 characters that will demonstrate
-> quoting when text is wrapped to multiple lines.
+> demonstrate quoting when text is wrapped to multiple lines.
+> This is a line that is longer than the 70 characters that will
+> demonstrate quoting when text is wrapped to multiple lines.
 QUOTED
 
     my ($content) = $txn->Content( Quote => 1 );
@@ -179,3 +179,72 @@ QUOTED
     my ($content) = $txn->Content( ); # Quote defaults to 0
     like( $content, qr/$expected/, 'Text quoted properly');
 }
+
+diag "Test wrapping with no initial quoting";
+{
+    my $content =<<CONTENT;
+This is a line that is longer than the 70 characters that will demonstrate quoting when text is wrapped to multiple lines. It is not already quoted
+This is a line that is exactly 70 characters before it is wrapped here
+This is a line that is exactly 76 characters before it is wrapped by the code
+This is a short line.
+These should remain separate lines.
+
+Line after a line break.
+CONTENT
+
+    my $expected =<<EXPECTED;
+> This is a line that is longer than the 70 characters that will
+> demonstrate quoting when text is wrapped to multiple lines. It is not
+> already quoted
+> This is a line that is exactly 70 characters before it is wrapped here
+> This is a line that is exactly 76 characters before it is wrapped by
+> the code
+> This is a short line.
+> These should remain separate lines.
+> 
+> Line after a line break.
+EXPECTED
+
+    my $txn = RT::Transaction->new(RT->SystemUser);
+    my $result = $txn->ApplyQuoteWrap( content => $content, cols => 70 );
+    is( $result, $expected, 'Text quoted properly after one quoting.');
+
+    $expected =<<EXPECTED;
+> > This is a line that is longer than the 70 characters that will
+> > demonstrate quoting when text is wrapped to multiple lines. It is not
+> > already quoted
+> > This is a line that is exactly 70 characters before it is wrapped here
+> > This is a line that is exactly 76 characters before it is wrapped by
+> > the code
+> > This is a short line.
+> > These should remain separate lines.
+> > 
+> > Line after a line break.
+EXPECTED
+
+    my $result = $txn->ApplyQuoteWrap( content => $result, cols => 70 );
+    is( $result, $expected, 'Text quoted properly after two quotings');
+
+    # Wrapping is only triggered over 76 chars, so quote until 76 is exceeded
+    $result = $txn->ApplyQuoteWrap( content => $result, cols => 70 );
+    $result = $txn->ApplyQuoteWrap( content => $result, cols => 70 );
+    $result = $txn->ApplyQuoteWrap( content => $result, cols => 70 );
+
+    $expected =<<EXPECTED;
+> > > > > This is a line that is longer than the 70 characters that will
+> > > > > demonstrate quoting when text is wrapped to multiple lines. It
+> > > > > is not
+> > > > > already quoted
+> > > > > This is a line that is exactly 70 characters before it is
+> > > > > wrapped here
+> > > > > This is a line that is exactly 76 characters before it is
+> > > > > wrapped by
+> > > > > the code
+> > > > > This is a short line.
+> > > > > These should remain separate lines.
+> > > > >
+> > > > > Line after a line break.
+EXPECTED
+
+    is( $result, $expected, 'Text quoted properly after five quotings');
+}

-----------------------------------------------------------------------


More information about the Rt-commit mailing list