-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathsection_name_builder.h
61 lines (48 loc) · 1.74 KB
/
section_name_builder.h
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
53
54
55
56
57
58
59
60
61
/*******************************************************************************
//
// SYCL 2020 Conformance Test Suite
//
*******************************************************************************/
#ifndef __SYCLCTS_TESTS_COMMON_SECTION_NAME_BUILDER_H
#define __SYCLCTS_TESTS_COMMON_SECTION_NAME_BUILDER_H
#include "string_makers.h"
#include <sstream>
#include <utility>
namespace sycl_cts {
/**
* @brief Builder for a section name with the fluent interface
* @details Be aware that Catch2 doesn't support nested sections with the same
* name, see https://github.com/catchorg/Catch2/issues/816 for details.
* So if you see
* "Assertion `m_parent' failed."
* that's probably the case.
*/
class section_name {
std::string m_description;
std::ostringstream m_parameters;
public:
section_name(const section_name& other)
: m_description(other.m_description),
m_parameters(other.m_parameters.str()) {}
// Avoid implicit move constructor removal
section_name(section_name&& other) = default;
section_name(const std::string& description) : m_description(description) {}
template <typename T>
section_name& with(const std::string& name, T&& value) {
m_parameters << ' ' << name << ": "
<< Catch::StringMaker<T>::convert(std::forward<T>(value))
<< ',';
return *this;
}
std::string create() const {
std::string result(m_description);
const auto parameters = m_parameters.str();
if (!parameters.empty()) {
// remove last comma and re-use first space from parameters
result += " with" + parameters + "\b \b";
}
return result;
}
};
} // namespace sycl_cts
#endif // __SYCLCTS_TESTS_COMMON_SECTION_NAME_BUILDER_H