libcruft-util/test/version.cpp

74 lines
2.2 KiB
C++
Raw Permalink Normal View History

#include <cruft/util/version.hpp>
2011-05-23 17:18:52 +10:00
#include <cruft/util/tap.hpp>
2011-05-23 17:18:52 +10:00
2016-06-20 13:08:36 +10:00
///////////////////////////////////////////////////////////////////////////////
2016-01-19 18:31:49 +11:00
static const struct {
const char *msg;
const char *str;
unsigned parts[4];
cruft::version::release_t release;
2016-06-20 13:08:36 +10:00
} PARSE_TESTS[] = {
{ "parse 1 component", "1", { 1u }, cruft::version::PRODUCTION },
2011-11-04 17:28:04 +11:00
{ "parse 2component", "1.2", { 1u, 2u }, cruft::version::PRODUCTION },
{ "parse 3component", "1.2.3", { 1u, 2u, 3u }, cruft::version::PRODUCTION },
{ "parse 4component", "1.2.3.4", { 1u, 2u, 3u, 4u }, cruft::version::PRODUCTION },
2011-05-23 17:18:52 +10:00
{ "parse 2 component alpha", "9.5a", { 9u, 5u }, cruft::version::ALPHA },
{ "parse 3 component beta", "8.2.5b", { 8u, 2u, 5u }, cruft::version::BETA },
2016-01-19 18:31:49 +11:00
/*
{ "1.4.1-p8", { 1, 4, 1 } },
{ "4.2.0-r4", { 4, 2, 0 } },
2011-05-23 17:18:52 +10:00
2016-01-19 18:31:49 +11:00
{ "1.4 RC1", { 1, 4 } }
*/
};
2011-05-23 17:18:52 +10:00
2016-06-20 13:08:36 +10:00
///////////////////////////////////////////////////////////////////////////////
static const struct {
cruft::version a, b;
2016-06-20 13:08:36 +10:00
bool eq, lt, gt;
const char *msg;
} CMP_TESTS[] = {
{ { 1u }, { 1u }, true, false, false, "v1 cmp v1" },
{ { 1u }, { 1u, 0u }, true, false, false, "v1 cmp v1.0" },
{ { 1u, 0u }, { 1u }, true, false, false, "v1.0 cmp v1" },
{ { 1u, 1u }, { 1u }, false, false, true, "v1.1 cmp v1" },
{ { 1u, }, { 1u, 1u }, false, true, false, "v1 cmp v1.1" },
};
//-----------------------------------------------------------------------------
2011-05-23 17:18:52 +10:00
int
2015-04-13 16:45:56 +10:00
main () {
2011-05-23 17:18:52 +10:00
cruft::TAP::logger tap;
2011-05-23 17:18:52 +10:00
for (const auto &t: PARSE_TESTS) {
cruft::version v (t.str);
bool parts = std::equal (v.begin (), v.end (), t.parts);
bool release = v.release == t.release;
2011-05-23 17:18:52 +10:00
2021-04-13 16:05:08 +10:00
tap.expect (parts && release, "{:s}", t.msg);
2016-06-20 13:08:36 +10:00
}
for (const auto &t: CMP_TESTS) {
const bool eq = t.a == t.b;
const bool lt = t.a < t.b;
const bool gt = t.a > t.b;
2016-06-20 13:08:36 +10:00
2021-04-13 16:05:08 +10:00
tap.expect (t.eq == eq, "{:s}: equality", t.msg);
tap.expect (t.lt == lt, "{:s}: less-than", t.msg);
tap.expect (t.gt == gt, "{:s}: greater-than", t.msg);
2011-05-23 17:18:52 +10:00
}
2016-01-19 18:31:49 +11:00
return tap.status ();
2011-05-23 17:18:52 +10:00
}