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:
Paul Beckingham 2009-11-29 22:41:55 -05:00
parent 8c5508de4b
commit b246fae889
3 changed files with 65 additions and 8 deletions

View file

@ -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;
}