From 4baaf52610386ad54fa5d4ab2b8b101d0ada57d7 Mon Sep 17 00:00:00 2001 From: Scott Kostyshak Date: Sat, 20 Oct 2012 13:43:04 -0400 Subject: [PATCH] Bug - Hyphenation is not needed when words are split with commas. - Unit test added. --- ChangeLog | 3 +++ src/text.cpp | 16 ++++++++++++- test/hyphenate.t | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 test/hyphenate.t diff --git a/ChangeLog b/ChangeLog index a8a96c9b3..e7d79bc16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,9 @@ Features + Fixed the mechanism used for selecting translations (thanks to Fidel Mato). Bugs + + Improved hyphenation by splitting on commas (even if no whitespace after). + Leads to better output of, for example, 'task show', where comma-separated + lists are common. + Fixed bug #1031, which kept expanding aliases after the '--' operator (thanks to Jim B). + Fixed bug #1038, which prints blank lines with bulk changes and when the diff --git a/src/text.cpp b/src/text.cpp index c5e141e45..6713490a4 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -300,6 +300,7 @@ int longestLine (const std::string& input) // - EOS // - \n // - last space before 'length' characters +// - last comma before 'length' characters, even if not followed by a space // - first 'length' characters void extractLine ( std::string& text, @@ -310,6 +311,7 @@ void extractLine ( std::string::size_type bytes = 0; std::string::size_type previous = std::string::npos; std::string::size_type last_space = std::string::npos; + std::string::size_type last_comma = std::string::npos; int character; int width = 0; while (width < length) @@ -321,6 +323,10 @@ void extractLine ( if (character == ' ') last_space = previous; + // Record last seen comma. + if (character == ',') + last_comma = previous; + // Newline is an early break point. if (character == '\n') { @@ -371,7 +377,15 @@ void extractLine ( return; } - // Case where a word needs to be split, and there is no last_space. + if (last_comma != std::string::npos) + { + line = text.substr (0, last_comma + 1); + text = text.substr (last_comma + 1); + return; + } + + // Case where a word needs to be split, and there is no last_space + // or last_comma. // Hyphenation becomes the issue. // 012345 // |fiftee|n diff --git a/test/hyphenate.t b/test/hyphenate.t new file mode 100755 index 000000000..737f870f1 --- /dev/null +++ b/test/hyphenate.t @@ -0,0 +1,59 @@ +#! /usr/bin/env perl +################################################################################ +## taskwarrior - a command line task list manager. +## +## Copyright 2006-2012, Paul Beckingham, Federico Hernandez. +## +## Permission is hereby granted, free of charge, to any person obtaining a copy +## of this software and associated documentation files (the "Software"), to deal +## in the Software without restriction, including without limitation the rights +## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +## copies of the Software, and to permit persons to whom the Software is +## furnished to do so, subject to the following conditions: +## +## The above copyright notice and this permission notice shall be included +## in all copies or substantial portions of the Software. +## +## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +## SOFTWARE. +## +## http://www.opensource.org/licenses/mit-license.php +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 3; + +# Create the rc file. +if (open my $fh, '>', 'bug.rc') +{ + print $fh "data.location=.\n"; + print $fh "confirmation=no\n"; + print $fh "defaultwidth=50\n"; + print $fh "detection=off\n"; + close $fh; + ok (-r 'bug.rc', 'Created bug.rc'); +} + +# Split on comma instead of hyphenating + +my $output = qx{../src/task rc:bug.rc show report.next.columns | tail -n +4 2>&1}; +unlike ($output, qr/-/, 'split on comma for comma-separated lists'); + +# Cleanup. +unlink qw(pending.data completed.data undo.data backlog.data synch.key bug.rc); +ok (! -r 'pending.data' && + ! -r 'completed.data' && + ! -r 'undo.data' && + ! -r 'backlog.data' && + ! -r 'synch.key' && + ! -r 'bug.rc', 'Cleanup'); + +exit 0; +