-
Notifications
You must be signed in to change notification settings - Fork 9
/
snitch_capture.hpp
52 lines (41 loc) · 1.49 KB
/
snitch_capture.hpp
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
45
46
47
48
49
50
51
52
#ifndef SNITCH_CAPTURE_HPP
#define SNITCH_CAPTURE_HPP
#include "snitch/snitch_config.hpp"
#include "snitch/snitch_string.hpp"
#include "snitch/snitch_string_utility.hpp"
#include "snitch/snitch_test_data.hpp"
#include <cstddef>
#include <string_view>
namespace snitch::impl {
struct scoped_capture {
capture_state& captures;
std::size_t count = 0;
~scoped_capture() {
captures.resize(captures.size() - count);
}
};
SNITCH_EXPORT std::string_view extract_next_name(std::string_view& names) noexcept;
struct test_state;
// Requires: number of captures < max_captures.
SNITCH_EXPORT small_string<max_capture_length>& add_capture(test_state& state);
// Requires: number of captures < max_captures.
template<string_appendable T>
void add_capture(test_state& state, std::string_view& names, const T& arg) {
auto& capture = add_capture(state);
append_or_truncate(capture, extract_next_name(names), " := ", arg);
}
// Requires: number of captures < max_captures.
template<string_appendable... Args>
scoped_capture add_captures(test_state& state, std::string_view names, const Args&... args) {
(add_capture(state, names, args), ...);
return {state.captures, sizeof...(args)};
}
// Requires: number of captures < max_captures.
template<string_appendable... Args>
scoped_capture add_info(test_state& state, const Args&... args) {
auto& capture = add_capture(state);
append_or_truncate(capture, args...);
return {state.captures, 1};
}
} // namespace snitch::impl
#endif