libcruft-util/test/view.cpp
Danny Robson 202c22eee8 view: simplify logical comparator implementation
we remove some duplicate and specific logical comparator specialisations
and instead rely on a base view/view comparator implementation by way of
make_view.
2017-12-20 12:31:52 +11:00

48 lines
1.3 KiB
C++

#include "tap.hpp"
#include "view.hpp"
#include <algorithm>
///////////////////////////////////////////////////////////////////////////////
int
main (int, char**)
{
util::TAP::logger tap;
const std::string s = "this is a test string";
const std::string t = "not the same string";
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");
};
return tap.status ();
}