2016-04-05 11:06:01 +10:00
|
|
|
#include "tap.hpp"
|
|
|
|
#include "string.hpp"
|
|
|
|
#include "types.hpp"
|
2017-09-15 15:22:29 +10:00
|
|
|
#include "iterator.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
2016-03-17 18:13:19 +11:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
|
|
|
util::TAP::logger tap;
|
|
|
|
|
|
|
|
const char csv[] = "\0,a,123,,this is a test,";
|
|
|
|
|
2017-09-15 15:22:29 +10:00
|
|
|
// expected test data must be a std::string so we can check embedded
|
|
|
|
// nulls (which are ambiguous when using a cstr).
|
|
|
|
struct foo {
|
|
|
|
const std::string value;
|
|
|
|
const char *message;
|
|
|
|
} TESTS[] = {
|
|
|
|
{ "\0", "null" },
|
|
|
|
{ "a", "single letter" },
|
|
|
|
{ "123", "three digits" },
|
|
|
|
{ "", "empty string" },
|
|
|
|
{ "this is a test", "string with spaces" },
|
|
|
|
{ "", "trailing empty" }
|
|
|
|
};
|
2016-03-17 18:13:19 +11:00
|
|
|
|
2017-09-15 15:22:29 +10:00
|
|
|
for (const auto &[tok, expected]: util::zip (util::make_tokeniser (csv, ','), TESTS))
|
|
|
|
tap.expect (equal (tok, expected.value), "%s", expected.message);
|
2016-03-17 18:13:19 +11:00
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|