mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - caseless compare
- Fixed bug in text.cpp:find that failed to locate a substring if it occurred at the end of the string.
This commit is contained in:
parent
0c5a71b02f
commit
4f1183a358
3 changed files with 62 additions and 43 deletions
|
@ -35,72 +35,89 @@ if (open my $fh, '>', 'caseless.rc')
|
|||
{
|
||||
print $fh "data.location=.\n";
|
||||
close $fh;
|
||||
ok (-r 'append.rc', 'Created append.rc');
|
||||
ok (-r 'caseless.rc', 'Created caseless.rc');
|
||||
}
|
||||
|
||||
# Attempt case-sensitive and case-insensitive substitutions and filters.
|
||||
qx{../task add one two three};
|
||||
qx{../task 1 annotate four five six};
|
||||
qx{../task rc:caseless.rc add one two three};
|
||||
qx{../task rc:caseless.rc 1 annotate four five six};
|
||||
my $output;
|
||||
|
||||
# Description substitution.
|
||||
qx{../task rc.search.case.sensitive=yes 1 /One/ONE/};
|
||||
my $output = qx{../task info 1};
|
||||
# 2
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:yes 1 /One/ONE/};
|
||||
$output = qx{../task rc:caseless.rc 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};
|
||||
# 3
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:no 1 /One/ONE/};
|
||||
$output = qx{../task rc:caseless.rc 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};
|
||||
# 4
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:yes 1 /one/One/};
|
||||
$output = qx{../task rc:caseless.rc 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};
|
||||
# 5
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:no 1 /one/one/};
|
||||
$output = qx{../task rc:caseless.rc 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');
|
||||
# 6
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:yes 1 /Five/FIVE/};
|
||||
$output = qx{../task rc:caseless.rc 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};
|
||||
# 7
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:no 1 /Five/FIVE/};
|
||||
$output = qx{../task rc:caseless.rc 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');
|
||||
# 8
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:yes 1 /five/Five/};
|
||||
$output = qx{../task rc:caseless.rc 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');
|
||||
# 9
|
||||
qx{../task rc:caseless.rc rc.search.case.sensitive:no 1 /five/five/};
|
||||
$output = qx{../task rc:caseless.rc 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');
|
||||
# 10
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:yes ls One};
|
||||
unlike ($output, qr/one two three/, 'one two three\nfour 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');
|
||||
# 11
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:no ls One};
|
||||
like ($output, qr/one two three/, 'one two three\nfour 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');
|
||||
# 12
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:yes ls Five};
|
||||
unlike ($output, qr/four five six/, 'one two three\nfour 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');
|
||||
# 13
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:no ls Five};
|
||||
like ($output, qr/four five six/, 'one two three\nfour 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');
|
||||
# 14
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:yes ls description.contains:Three};
|
||||
unlike ($output, qr/one two three/, 'one two three\nfour 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');
|
||||
# 15
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:no ls description.contains:Three};
|
||||
like ($output, qr/one two three/, 'one two three\nfour 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');
|
||||
# 16
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:yes ls description.contains:Six};
|
||||
unlike ($output, qr/four five six/, 'one two three\nfour 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');
|
||||
# 17
|
||||
$output = qx{../task rc:caseless.rc rc.search.case.sensitive:no ls description.contains:Six};
|
||||
like ($output, qr/four five six/, 'one two three\nfour five six -> ls description.contains:Six caseless = succeed');
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
|
@ -112,8 +129,8 @@ 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');
|
||||
unlink 'caseless.rc';
|
||||
ok (!-r 'caseless.rc', 'Removed caseless.rc');
|
||||
|
||||
exit 0;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (178);
|
||||
UnitTest t (180);
|
||||
|
||||
// void wrapText (std::vector <std::string>& lines, const std::string& text, const int width)
|
||||
std::string text = "This is a test of the line wrapping code.";
|
||||
|
@ -342,6 +342,7 @@ int main (int argc, char** argv)
|
|||
|
||||
// Test case-sensitive.
|
||||
t.is ((int) find ("foo", "xx", true), (int) std::string::npos, "foo !contains xx");
|
||||
t.is ((int) find ("foo", "oo", true), 1, "foo contains oo");
|
||||
|
||||
t.is ((int) find ("foo", "fo", true), 0, "foo contains fo");
|
||||
t.is ((int) find ("foo", "FO", true), (int) std::string::npos, "foo !contains fo");
|
||||
|
@ -350,6 +351,7 @@ int main (int argc, char** argv)
|
|||
|
||||
// Test case-insensitive.
|
||||
t.is ((int) find ("foo", "xx", false), (int) std::string::npos, "foo !contains xx (caseless)");
|
||||
t.is ((int) find ("foo", "oo", false), 1, "foo contains oo (caseless)");
|
||||
|
||||
t.is ((int) find ("foo", "fo", false), 0, "foo contains fo (caseless)");
|
||||
t.is ((int) find ("foo", "FO", false), 0, "foo contains FO (caseless)");
|
||||
|
|
|
@ -497,7 +497,7 @@ std::string::size_type find (
|
|||
const char* start = t;
|
||||
const char* end = start + text.size ();
|
||||
|
||||
for (; t < end - len; ++t)
|
||||
for (; t <= end - len; ++t)
|
||||
{
|
||||
int diff;
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
|
@ -544,7 +544,7 @@ std::string::size_type find (
|
|||
const char* t = start + begin;
|
||||
const char* end = start + text.size ();
|
||||
|
||||
for (; t < end - len; ++t)
|
||||
for (; t <= end - len; ++t)
|
||||
{
|
||||
int diff;
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue