-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathutils_tests.cc
63 lines (49 loc) · 2.14 KB
/
utils_tests.cc
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
62
63
#include <celerity.h>
#include <catch2/catch_test_macros.hpp>
using namespace celerity;
using namespace celerity::detail;
// dummy definitions for get_simplified_type_name tests
namespace ns::another {
struct name2;
}
template <typename, typename>
class name3;
template <typename>
struct param {
template <typename>
struct nested_param;
};
template <typename, typename>
struct space {
template <typename>
struct nested_kernel;
};
template <typename T>
auto set_identity(queue queue, buffer<T, 2> mat, bool reverse) {
return [](handler& cgh) {
class set_identity_kernel {};
return set_identity_kernel{};
};
}
using set_identity_name = decltype(set_identity(std::declval<queue>(), std::declval<buffer<int, 2>>(), false)(std::declval<handler&>()));
TEST_CASE("name strings are correctly extracted from types", "[utils][get_simplified_type_name]") {
CHECK(utils::get_simplified_type_name<class name>() == "name");
CHECK(utils::get_simplified_type_name<ns::another::name2>() == "name2");
CHECK(utils::get_simplified_type_name<name3<class foo, int>>() == "name3<...>");
CHECK(utils::get_simplified_type_name<space<int, param<int>>::nested_kernel<param<float>::nested_param<int>>>() == "nested_kernel<...>");
CHECK(utils::get_simplified_type_name<set_identity_name>() == "set_identity_kernel");
}
TEST_CASE("escaping of invalid characters for dot labels", "[utils][escape_for_dot_label]") {
CHECK(utils::escape_for_dot_label("hello<bla&>") == "hello<bla&>");
}
TEST_CASE("replace_all replaces all occurrences of a pattern in string", "[utils][replace_all]") {
CHECK(utils::replace_all("hello world", " ", "_") == "hello_world");
CHECK(utils::replace_all("hello world", "l", "") == "heo word");
CHECK(utils::replace_all("hello world", " ", "<-->") == "hello<-->world");
CHECK(utils::replace_all("hello world", "l", "_") == "he__o wor_d");
CHECK(utils::replace_all("hello world", "o", "<->") == "hell<-> w<->rld");
CHECK(utils::replace_all("hello world", "foo", "bar") == "hello world");
CHECK(utils::replace_all("hello world", "", "bar") == "hello world");
CHECK(utils::replace_all("", "", "bar") == "");
CHECK(utils::replace_all("", "", "bar") == "");
}