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;
|
2017-11-22 17:03:00 +11:00
|
|
|
|
|
|
|
// the string_literal prefix is required to (easily) construct a string
|
|
|
|
// with an internal null character.
|
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
const std::string csv = "\0,a,123,,this is a test,"s;
|
|
|
|
|
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[] = {
|
2017-11-23 17:24:11 +11:00
|
|
|
{ "\0"s, "null" },
|
2017-09-15 15:22:29 +10:00
|
|
|
{ "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
|
|
|
};
|
|
|
|
|
2018-01-31 19:33:42 +11:00
|
|
|
util::view src { csv.c_str (), csv.size () };
|
|
|
|
for (const auto &[tok, expected]: util::zip (util::tokeniser (src, ','), TESTS))
|
|
|
|
tap.expect (equal (tok, expected.value), "%s", expected.message);
|
2016-03-17 18:13:19 +11:00
|
|
|
|
|
|
|
return tap.status ();
|
2018-01-30 11:31:40 +11:00
|
|
|
}
|