2019-03-18 14:08:06 +11:00
|
|
|
#include "tap.hpp"
|
2019-03-19 12:38:22 +11:00
|
|
|
#include "parse/si.hpp"
|
2019-03-18 14:08:06 +11:00
|
|
|
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char const *str;
|
|
|
|
std::size_t val;
|
|
|
|
} const TESTS[] = {
|
|
|
|
{ "0", 0u },
|
|
|
|
{ "1", 1u },
|
|
|
|
{ "1K", 1024u },
|
|
|
|
{ "1M", 1024u * 1024u },
|
|
|
|
{ "1G" , 1024u * 1024u * 1024u },
|
|
|
|
{ "1T", 1024ul * 1024u * 1024u * 1024u },
|
|
|
|
{ "3M", 3u * 1024u * 1024u },
|
|
|
|
{ "3k", 3u * 1024u },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto const &t: TESTS) {
|
2019-03-19 12:38:22 +11:00
|
|
|
auto res = cruft::parse::si<std::size_t> (t.str);
|
2019-03-18 14:08:06 +11:00
|
|
|
if (!res) {
|
2021-04-14 10:23:33 +10:00
|
|
|
tap.fail ("SI parsing {}", t.str);
|
2019-03-18 14:08:06 +11:00
|
|
|
} else {
|
2021-04-13 16:05:08 +10:00
|
|
|
tap.expect_eq (t.val, *res, "SI parsing '{}'", t.str);
|
2019-03-18 14:08:06 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|