generated from cpp-best-practices/gui_starter_template
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
constexpr_tests.cpp
33 lines (24 loc) · 979 Bytes
/
constexpr_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "test_json_impl.hpp"
#include <catch2/catch_test_macros.hpp>
TEST_CASE("Can read object size")
{
constexpr auto &document = compiled_json::test_json::impl::document;// NOLINT No, I'm not going to mark this `const`
STATIC_REQUIRE(document.size() == 1);
}
constexpr auto count_elements()
{
constexpr auto &document = compiled_json::test_json::impl::document;// NOLINT No, I'm not going to mark this `const`
std::size_t elements = 0;
for (const auto &json : document) {
// count_if is not constexpr in C++17
// cppcheck-suppress useStlAlgorithm
if (!json.is_null()) { ++elements; }
}
return elements;
}
TEST_CASE("Can iterate object") { STATIC_REQUIRE(count_elements() == compiled_json::test_json::impl::document.size()); }
TEST_CASE("Can read iterator key")
{
constexpr auto &document = compiled_json::test_json::impl::document;// NOLINT No, I'm not going to mark this `const`
STATIC_REQUIRE(document.begin().key() == "glossary");
}