libcruft-util/test/stringid.cpp

28 lines
698 B
C++
Raw Normal View History

2015-04-13 16:45:56 +10:00
#include "stringid.hpp"
#include "debug.hpp"
#include "tap.hpp"
#include <cstdlib>
#include <stdexcept>
int
main (int, char**) {
2016-01-19 18:31:49 +11:00
util::TAP::logger tap;
util::stringid map;
2016-01-19 18:31:49 +11:00
tap.expect_throw<std::out_of_range> ([&] { map.find ("invalid"); }, "find on empty set throws");
auto id1 = map.add ("first");
2016-01-19 18:31:49 +11:00
tap.expect_eq (id1, map.find ("first"), "single entity ID matches");
2016-01-19 18:31:49 +11:00
tap.expect_throw<std::out_of_range> ([&] { map.find ("invalid"); }, "invalid find throws");
auto id2 = map.add ("second");
2016-01-19 18:31:49 +11:00
tap.expect_eq (id1 + 1, id2, "monotonically increasing IDs");
tap.expect_eq (id1, map.find ("first"), "first element still matches");
2016-01-19 18:31:49 +11:00
return tap.status ();
}