From 6ea6c7937513a01b2fc9b1bfdd0f783d78891fab Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 28 Jun 2010 17:45:42 -0400 Subject: [PATCH] Bug - Fixed bug that prevented 'task list priority.above:L' from working. - Added unit tests. --- ChangeLog | 1 + src/Att.cpp | 19 ++++++++ src/tests/pri_sort.t | 109 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100755 src/tests/pri_sort.t diff --git a/ChangeLog b/ChangeLog index b127e0f7a..6c9c03ba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -48,6 +48,7 @@ + Fixed bug #405, which incorrectly compared dates on tasks created by versions earlier than 1.9.1 to those created by 1.9.1 or later (thanks to Ivo Jimenez). + + Fixed bug that prevented 'task list priority.above:L' from working. ------ old releases ------------------------------ diff --git a/src/Att.cpp b/src/Att.cpp index 5576919d8..3a7e36d68 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -405,6 +405,9 @@ std::string Att::type (const std::string& name) const else if (name == "limit") return "number"; + else if (name == "priority") + return "priority"; + else return "text"; } @@ -604,6 +607,14 @@ bool Att::match (const Att& other) const if (mValue <= other.mValue) return false; } + else if (which == "priority") + { + if (mValue == "" || + other.mValue == "H" || + mValue == other.mValue || + (mValue == "L" && other.mValue == "M")) + return false; + } } // after = over = above = > @@ -634,6 +645,14 @@ bool Att::match (const Att& other) const if (mValue >= other.mValue) return false; } + else if (which == "priority") + { + if (mValue == "H" || + other.mValue == "" || + mValue == other.mValue || + (mValue == "M" && other.mValue == "L")) + return false; + } } // word = contains as a substring, with word boundaries. diff --git a/src/tests/pri_sort.t b/src/tests/pri_sort.t new file mode 100755 index 000000000..ed6692568 --- /dev/null +++ b/src/tests/pri_sort.t @@ -0,0 +1,109 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 37; + +# Create the rc file. +if (open my $fh, '>', 'pri.rc') +{ + print $fh "data.location=.\n"; + close $fh; + ok (-r 'pri.rc', 'Created pri.rc'); +} + +# Verify that priorities can be select with the 'over' and 'under' modifiers. +qx{../task rc:pri.rc add H pri:H}; +qx{../task rc:pri.rc add M pri:M}; +qx{../task rc:pri.rc add L pri:L}; +qx{../task rc:pri.rc add _}; + +my $output = qx{../task rc:pri.rc ls priority.under:H}; +unlike ($output, qr/H/, 'pri H !< H'); + like ($output, qr/M/, 'pri M < H'); + like ($output, qr/L/, 'pri L < H'); + like ($output, qr/_/, 'pri _ < H'); + +$output = qx{../task rc:pri.rc ls priority.under:M}; +unlike ($output, qr/H/, 'pri H !< M'); +unlike ($output, qr/M/, 'pri M !< M'); + like ($output, qr/L/, 'pri L < M'); + like ($output, qr/_/, 'pri _ < M'); + +$output = qx{../task rc:pri.rc ls priority.under:L}; +unlike ($output, qr/H/, 'pri H !< L'); +unlike ($output, qr/M/, 'pri M !< L'); +unlike ($output, qr/L/, 'pri L !< L'); + like ($output, qr/_/, 'pri _ < L'); + +$output = qx{../task rc:pri.rc ls priority.under:}; +unlike ($output, qr/H/, 'pri H !< _'); +unlike ($output, qr/M/, 'pri M !< _'); +unlike ($output, qr/L/, 'pri L !< _'); +unlike ($output, qr/_/, 'pri _ !< _'); + +$output = qx{../task rc:pri.rc ls priority.over:H}; +unlike ($output, qr/H/, 'pri H !> H'); +unlike ($output, qr/M/, 'pri M !> H'); +unlike ($output, qr/L/, 'pri L !> H'); +unlike ($output, qr/_/, 'pri _ !> H'); + +$output = qx{../task rc:pri.rc ls priority.over:M}; + like ($output, qr/H/, 'pri H > M'); +unlike ($output, qr/M/, 'pri M !> M'); +unlike ($output, qr/L/, 'pri L !> M'); +unlike ($output, qr/_/, 'pri _ !> M'); + +$output = qx{../task rc:pri.rc ls priority.over:L}; + like ($output, qr/H/, 'pri H > L'); + like ($output, qr/M/, 'pri M > L'); +unlike ($output, qr/L/, 'pri L !> L'); +unlike ($output, qr/_/, 'pri _ !> L'); + +$output = qx{../task rc:pri.rc ls priority.over:}; + like ($output, qr/H/, 'pri H > _'); + like ($output, qr/M/, 'pri M > _'); + like ($output, qr/L/, 'pri L > _'); +unlike ($output, qr/_/, 'pri _ !> _'); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'completed.data'; +ok (!-r 'completed.data', 'Removed completed.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'pri.rc'; +ok (!-r 'pri.rc', 'Removed pri.rc'); + +exit 0; +