-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamed_tuple_unittest.cpp
More file actions
44 lines (37 loc) · 1.25 KB
/
named_tuple_unittest.cpp
File metadata and controls
44 lines (37 loc) · 1.25 KB
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
34
35
36
37
38
39
40
41
42
43
44
/**
* @file named_tuple_unittest.cpp
* @author Xuhua Huang
* @brief
* @version 0.1
* @date 2023-06-14
*
* @copyright Copyright (c) 2023
*
*/
// https://github.com/boost-ext/ut
#include "named_tuple.hpp"
#include "boost/ut.hpp"
int main(int argc, const char** argv) {
using namespace boost::ut;
using util::type::namedtuple;
"named tuple"_test = [] {
should("allow empty") = [] {
const auto nt = namedtuple{};
expect(not[](auto t) { return requires { t[""_t]; }; }(nt));
};
should("support direct initialization") = [] {
const auto nt = namedtuple{"price"_t = 42, "size"_t = 100};
expect([](auto t) { return requires { t["price"_t]; }; }(nt));
expect([](auto t) { return requires { t["size"_t]; }; }(nt));
expect(not[](auto t) { return requires { t["quantity"_t]; }; }(nt));
expect(42_i == nt["price"_t] and 100_i == nt["size"_t]);
};
should("support modification") = [] {
auto nt = namedtuple{"price"_t = int{}, "size"_t = std::size_t{}};
nt["price"_t] = 12;
nt["size"_t] = 34u;
expect(12_i == nt["price"_t] and 34_u == nt["size"_t]);
};
};
return 0;
}