#include "repo.h"
#include <format>
using namespace nixpluginpijul;
template<typename T, typename U>
void assert_eq(const T &left, const U &right)
{
if (left != right) {
const std::string &string = std::format("assertion failed: {} == {}", left, right);
fprintf(stderr, "%s\n", string.c_str());
exit(1);
}
}
template<typename F>
void assert_throws(F op)
{
try {
op();
} catch (...) {
return;
}
fprintf(stderr, "%s\n", "assertion failed: `op' didn't throw");
exit(1);
}
int main()
{
auto point = parseRFC3339("1970-01-01T00:00:00.000Z");
assert_eq(0L, point.time_since_epoch().count());
point = parseRFC3339("1970-01-01T00:00:00Z");
assert_eq(0L, point.time_since_epoch().count());
point = parseRFC3339("1970-01-01T00:30:00+00:30");
assert_eq(0LL, point.time_since_epoch().count());
point = parseRFC3339("1970-01-01T00:00:00.000-01:00");
assert_eq(3600000L, point.time_since_epoch().count());
assert_throws([] {
parseRFC3339("garbage");
});
assert_throws([] {
parseRFC3339("1");
});
assert_throws([] {
parseRFC3339("1970-01-01T00:00:00");
});
// FIXME: this should be an invalid timestamp (at least, I think so) because
// it has both +00:30 and 'Z' but it parses
assert_throws([] {
parseRFC3339("1970-01-01T00:30:00+00:30Z");
});
}