mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 17:07:19 +02:00
Enhancement - caseless substitution
- Substitutions "task <id> /from/to/" now obey the rc.search.case.sensitive setting.
This commit is contained in:
parent
9cab749016
commit
0c5a71b02f
5 changed files with 203 additions and 20 deletions
119
src/tests/caseless.t
Executable file
119
src/tests/caseless.t
Executable file
|
@ -0,0 +1,119 @@
|
|||
#! /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 => 21;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'caseless.rc')
|
||||
{
|
||||
print $fh "data.location=.\n";
|
||||
close $fh;
|
||||
ok (-r 'append.rc', 'Created append.rc');
|
||||
}
|
||||
|
||||
# Attempt case-sensitive and case-insensitive substitutions and filters.
|
||||
qx{../task add one two three};
|
||||
qx{../task 1 annotate four five six};
|
||||
|
||||
# Description substitution.
|
||||
qx{../task rc.search.case.sensitive=yes 1 /One/ONE/};
|
||||
my $output = qx{../task info 1};
|
||||
unlike ($output, qr/One two three/, 'one two three\nfour five six -> /One/ONE/ = fail');
|
||||
|
||||
qx{../task rc.search.case.sensitive=no 1 /One/ONE/};
|
||||
$output = qx{../task info 1};
|
||||
like ($output, qr/ONE two three/, 'one two three\nfour five six -> /One/ONE/ = caseless succeed');
|
||||
|
||||
qx{../task rc.search.case.sensitive=yes 1 /one/One/};
|
||||
$output = qx{../task info 1};
|
||||
unlike ($output, qr/One two three/, 'ONE two three\nfour five six -> /one/ONE/ = fail');
|
||||
|
||||
qx{../task rc.search.case.sensitive=no 1 /one/one/};
|
||||
$output = qx{../task info 1};
|
||||
like ($output, qr/one two three/, 'ONE two three\nfour five six -> /one/one/ = caseless succeed');
|
||||
|
||||
# Annotation substitution.
|
||||
qx{../task rc.search.case.sensitive=yes 1 /Five/FIVE/};
|
||||
$output = qx{../task info 1};
|
||||
unlike ($output, qr/four five six/, 'one two three\nfour five six -> /Five/FIVE/ = fail');
|
||||
|
||||
qx{../task rc.search.case.sensitive=no 1 /Five/FIVE/};
|
||||
$output = qx{../task info 1};
|
||||
like ($output, qr/four FIVE six/, 'one two three\nfour five six -> /Five/FIVE/ = caseless succeed');
|
||||
|
||||
qx{../task rc.search.case.sensitive=yes 1 /five/Five/};
|
||||
$output = qx{../task info 1};
|
||||
unlike ($output, qr/four five six/, 'one two three\nfour FIVE six -> /five/Five/ = fail');
|
||||
|
||||
qx{../task rc.search.case.sensitive=no 1 /five/five/};
|
||||
$output = qx{../task info 1};
|
||||
like ($output, qr/four FIVE six/, 'one two three\nfour FIVE six -> /five/five/ = caseless succeed');
|
||||
|
||||
# Description filter.
|
||||
$output = qx{../task rc.search.case.sensitive=yes ls One};
|
||||
unlike ($output, qr/one two three/, 'one two three\bfour five six -> ls One = fail');
|
||||
|
||||
$output = qx{../task rc.search.case.sensitive=no ls One};
|
||||
like ($output, qr/one two three/, 'one two three\bfour five six -> ls One caseless = succeed');
|
||||
|
||||
$output = qx{../task rc.search.case.sensitive=yes ls Five};
|
||||
unlike ($output, qr/four five six/, 'one two three\bfour five six -> ls Five = fail');
|
||||
|
||||
$output = qx{../task rc.search.case.sensitive=no ls Five};
|
||||
like ($output, qr/four five six/, 'one two three\bfour five six -> ls Five caseless = succeed');
|
||||
|
||||
# Annotation filter.
|
||||
$output = qx{../task rc.search.case.sensitive=yes ls description.contains:Three};
|
||||
unlike ($output, qr/one two three/, 'one two three\bfour five six -> ls description.contains:Three = fail');
|
||||
|
||||
$output = qx{../task rc.search.case.sensitive=no ls description.contains:Three};
|
||||
like ($output, qr/one two three/, 'one two three\bfour five six -> ls description.contains:Three caseless = succeed');
|
||||
|
||||
$output = qx{../task rc.search.case.sensitive=yes ls description.contains:Six};
|
||||
unlike ($output, qr/four five six/, 'one two three\bfour five six -> ls description.contains:Six = fail');
|
||||
|
||||
$output = qx{../task rc.search.case.sensitive=no ls description.contains:Six};
|
||||
like ($output, qr/four five six/, 'one two three\bfour five six -> ls description.contains:Six caseless = succeed');
|
||||
|
||||
# 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 'append.rc';
|
||||
ok (!-r 'append.rc', 'Removed append.rc');
|
||||
|
||||
exit 0;
|
||||
|
|
@ -34,11 +34,13 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (15);
|
||||
UnitTest t (19);
|
||||
|
||||
Task task;
|
||||
task.set ("description", "one two three four");
|
||||
|
||||
context.config.set ("search.case.sensitive", "yes");
|
||||
|
||||
Subst s;
|
||||
t.ok (s.valid ("/a/b/x"), "valid /a/b/x");
|
||||
t.ok (s.valid ("/a/b/"), "valid /a/b/");
|
||||
|
@ -90,6 +92,43 @@ int main (int argc, char** argv)
|
|||
t.fail ("failed to parse '/e /E /g'");
|
||||
}
|
||||
|
||||
// Now repeat the last two tests with a case-insensitive setting.
|
||||
context.config.set ("search.case.sensitive", "no");
|
||||
good = true;
|
||||
try { s.parse ("/tWo/TWO/"); } catch (...) { good = false; }
|
||||
t.ok (good, "parsed /tWo/TWO/ (rc.search.case.sensitive=no)");
|
||||
if (good)
|
||||
{
|
||||
std::string description = task.get ("description");
|
||||
std::vector <Att> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
|
||||
s.apply (description, annotations);
|
||||
t.is (description, "one TWO three four", "single word subst (rc.search.case.sensitive=no)");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.fail ("failed to parse '/tWo/TWO/' (rc.search.case.sensitive=no)");
|
||||
}
|
||||
|
||||
good = true;
|
||||
try { s.parse ("/E /E /g"); } catch (...) { good = false; }
|
||||
t.ok (good, "parsed /E /E /g (rc.search.case.sensitive=no)");
|
||||
if (good)
|
||||
{
|
||||
std::string description = task.get ("description");
|
||||
std::vector <Att> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
|
||||
s.apply (description, annotations);
|
||||
t.is (description, "onE two threE four", "multiple word subst (rc.search.case.sensitive=no)");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.fail ("failed to parse '/E /E /g' (rc.search.case.sensitive=no)");
|
||||
}
|
||||
|
||||
context.config.set ("search.case.sensitive", "yes");
|
||||
good = true;
|
||||
try { s.parse ("/from/to/g"); } catch (...) { good = false; }
|
||||
t.ok (good, "parsed /from/to/g");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue