diff --git a/util/tests/list-of-keys-test.cc b/util/tests/list-of-keys-test.cc new file mode 100644 index 0000000..0394341 --- /dev/null +++ b/util/tests/list-of-keys-test.cc @@ -0,0 +1,46 @@ +#include + +#include + +#include "util.h" + +TEST_CASE("std::unordered_map with multiple entries", "[list-of-keys]") +{ + std::unordered_map map = { + {"first", 0}, + {"second", 0}, + }; + + auto s = list_of_keys(map); + auto rv = s == "first, second" || s == "second, first"; + REQUIRE(rv == true); +} + +TEST_CASE("std::unordered_map with single entry", "[list-of-keys]") +{ + std::unordered_map map = { + {"first", 0}, + }; + + REQUIRE(list_of_keys(map) == "first"); +} + +TEST_CASE("std::vector with multiple entries", "[list-of-keys]") +{ + std::vector vec = { + "first", + "second", + "third", + }; + + REQUIRE(list_of_keys(vec) == "first, second, third"); +} + +TEST_CASE("std::vector with single entry", "[list-of-keys]") +{ + std::vector vec = { + "first", + }; + + REQUIRE(list_of_keys(vec) == "first"); +} diff --git a/util/tests/meson.build b/util/tests/meson.build index a30f8fc..d4bb290 100644 --- a/util/tests/meson.build +++ b/util/tests/meson.build @@ -4,5 +4,8 @@ test_util_lib = static_library('test-util', test_util_src, dependencies: [utilit copy_test = executable('copy-test', 'copy-test.cc', link_with: [test_util_lib], dependencies: [thread_dep, utilities]) test('copy-test', copy_test) +list_of_keys_test = executable('list-of-keys-test', 'list-of-keys-test.cc', dependencies: [utilities, catch2]) +test('list-of-keys-test', list_of_keys_test) + fixed_test = executable('fixed-test', 'fixed-test.cc', dependencies: [utilities, catch2]) test('fixed-test', fixed_test)