mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-30 22:43:24 +02:00
Unit Tests - fixing broken tests
- The split tests are all broken after a recent change. They need to be extended to accommodate the new split_minimal functions.
This commit is contained in:
parent
8c5508de4b
commit
b246fae889
3 changed files with 65 additions and 8 deletions
|
@ -104,12 +104,19 @@ int main (int argc, char** argv)
|
|||
t.is (items.size (), (size_t) 1, "split 'a' '-' -> 1 item");
|
||||
t.is (items[0], "a", "split 'a' '-' -> 'a'");
|
||||
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 1, "split 'a' '-' -> 1 item");
|
||||
t.is (items[0], "a", "split 'a' '-' -> 'a'");
|
||||
|
||||
unsplit = "-";
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 2, "split '-' '-' -> '' ''");
|
||||
t.is (items[0], "", "split '-' '-' -> [0] ''");
|
||||
t.is (items[1], "", "split '-' '-' -> [1] ''");
|
||||
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 1, "split '-' '-' -> '-'");
|
||||
|
||||
unsplit = "-a-bc-def";
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 4, "split '-a-bc-def' '-' -> '' 'a' 'bc' 'def'");
|
||||
|
@ -118,11 +125,21 @@ int main (int argc, char** argv)
|
|||
t.is (items[2], "bc", "split '-a-bc-def' '-' -> [2] 'bc'");
|
||||
t.is (items[3], "def", "split '-a-bc-def' '-' -> [3] 'def'");
|
||||
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 3, "split '-a-bc-def' '-' -> 'a' 'bc' 'def'");
|
||||
t.is (items[0], "a", "split '-a-bc-def' '-' -> [1] 'a'");
|
||||
t.is (items[1], "bc", "split '-a-bc-def' '-' -> [2] 'bc'");
|
||||
t.is (items[2], "def", "split '-a-bc-def' '-' -> [3] 'def'");
|
||||
|
||||
// void split (std::vector<std::string>& results, const std::string& input, const std::string& delimiter)
|
||||
unsplit = "";
|
||||
split (items, unsplit, "--");
|
||||
t.is (items.size (), (size_t) 0, "split '' '--' -> 0 items");
|
||||
|
||||
split (items, unsplit, "--");
|
||||
t.is (items.size (), (size_t) 1, "split '' '--' -> 1");
|
||||
t.is (items[0], "", "split '' '--' -> [1] ''");
|
||||
|
||||
unsplit = "a";
|
||||
split (items, unsplit, "--");
|
||||
t.is (items.size (), (size_t) 1, "split 'a' '--' -> 1 item");
|
||||
|
|
50
src/text.cpp
50
src/text.cpp
|
@ -57,15 +57,33 @@ void wrapText (
|
|||
void split (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const char delimiter,
|
||||
bool nontrivial /* = true */)
|
||||
const char delimiter)
|
||||
{
|
||||
results.clear ();
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
if (!nontrivial || i != start)
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + 1;
|
||||
}
|
||||
|
||||
if (input.length ())
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split_minimal (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const char delimiter)
|
||||
{
|
||||
results.clear ();
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
if (i != start)
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + 1;
|
||||
}
|
||||
|
@ -78,8 +96,7 @@ void split (
|
|||
void split (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const std::string& delimiter,
|
||||
bool nontrivial /* = true */)
|
||||
const std::string& delimiter)
|
||||
{
|
||||
results.clear ();
|
||||
std::string::size_type length = delimiter.length ();
|
||||
|
@ -88,7 +105,28 @@ void split (
|
|||
std::string::size_type i;
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
if (!nontrivial || i != start)
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + length;
|
||||
}
|
||||
|
||||
if (input.length ())
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split_minimal (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const std::string& delimiter)
|
||||
{
|
||||
results.clear ();
|
||||
std::string::size_type length = delimiter.length ();
|
||||
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
if (i != start)
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + length;
|
||||
}
|
||||
|
|
|
@ -38,8 +38,10 @@ std::string trimRight (const std::string& in, const std::string& t = " ");
|
|||
std::string trim (const std::string& in, const std::string& t = " ");
|
||||
std::string unquoteText (const std::string&);
|
||||
void extractLine (std::string&, std::string&, int);
|
||||
void split (std::vector<std::string>&, const std::string&, const char, bool nontrivial = true);
|
||||
void split (std::vector<std::string>&, const std::string&, const std::string&, bool nontrivial = true);
|
||||
void split (std::vector<std::string>&, const std::string&, const char);
|
||||
void split (std::vector<std::string>&, const std::string&, const std::string&);
|
||||
void split_minimal (std::vector<std::string>&, const std::string&, const char);
|
||||
void split_minimal (std::vector<std::string>&, const std::string&, const std::string&);
|
||||
void join (std::string&, const std::string&, const std::vector<std::string>&);
|
||||
std::string commify (const std::string&);
|
||||
std::string lowerCase (const std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue