2016-04-05 11:06:01 +10:00
|
|
|
#include "tap.hpp"
|
|
|
|
#include "view.hpp"
|
2017-12-20 12:31:52 +11:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2016-03-17 18:12:34 +11:00
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
|
|
|
util::TAP::logger tap;
|
|
|
|
|
2017-12-26 17:29:32 +11:00
|
|
|
tap.expect_eq (
|
2018-01-10 18:49:00 +11:00
|
|
|
std::size (util::make_view ("foo")), 3u,
|
2017-12-26 17:29:32 +11:00
|
|
|
"character array view does not include trailing null"
|
|
|
|
);
|
|
|
|
|
2016-03-17 18:12:34 +11:00
|
|
|
const std::string s = "this is a test string";
|
|
|
|
const std::string t = "not the same string";
|
|
|
|
|
2017-12-20 12:31:52 +11:00
|
|
|
tap.expect_eq (s, util::make_view(s), "string/view equality");
|
|
|
|
tap.expect_neq (s, util::make_view(t), "string/view inequality");
|
|
|
|
tap.expect_eq (s.data (), util::make_view (s), "c-str/view equality");
|
|
|
|
tap.expect_eq (
|
|
|
|
s,
|
|
|
|
util::view<const char*> (&*s.cbegin (), &*s.cend ()),
|
|
|
|
"string/pointer-view equality");
|
|
|
|
|
|
|
|
{
|
|
|
|
// comparator tests
|
|
|
|
static const struct {
|
|
|
|
util::view<const char*> a;
|
|
|
|
util::view<const char*> b;
|
|
|
|
bool less;
|
|
|
|
} TESTS[] = {
|
|
|
|
{ "b", "b", false },
|
|
|
|
{ "b", "a", false },
|
|
|
|
{ "b", "c", true },
|
|
|
|
{ "foo", "bar", false },
|
|
|
|
{ "bar", "foo", true },
|
|
|
|
{ "banana", "banana", false },
|
|
|
|
{ "banana", "banan", false },
|
|
|
|
{ "banan", "banana", true },
|
|
|
|
};
|
|
|
|
|
|
|
|
tap.expect (std::all_of (std::begin (TESTS), std::end (TESTS), [] (const auto &x) {
|
|
|
|
return (x.a < x.b) == x.less;
|
|
|
|
}), "comparator less-than");
|
|
|
|
};
|
2016-03-17 18:12:34 +11:00
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|