-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlower_wrapper.test.cc
70 lines (65 loc) · 2.35 KB
/
lower_wrapper.test.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
64
65
66
67
68
69
70
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
#include "snn-core/ascii/lower_wrapper.hh"
#include "snn-core/unittest.hh"
namespace snn::app
{
namespace
{
constexpr bool example()
{
// {
// // This will not compile (in debug mode):
// constexpr auto lw = ascii::as_lower("ABC");
// }
{
auto lw = ascii::as_lower("");
static_assert(std::is_same_v<decltype(lw), ascii::lower_wrapper<cstrview>>);
snn_require(lw.get().size() == 0);
snn_require(lw.get() == "");
}
{
auto lw = ascii::as_lower("abcdefghijklmnopqrstuvwxyz");
static_assert(std::is_same_v<decltype(lw), ascii::lower_wrapper<cstrview>>);
snn_require(lw.get().size() == 26);
snn_require(lw.get() == "abcdefghijklmnopqrstuvwxyz");
}
{
// Only ASCII bytes are required to be lowercase.
auto lw = ascii::as_lower("abcÅÄÖ");
static_assert(std::is_same_v<decltype(lw), ascii::lower_wrapper<cstrview>>);
snn_require(lw.get().size() == 9);
snn_require(lw.get() == "abcÅÄÖ");
}
{
cstrview s{"abc"};
auto lw = ascii::as_lower(s);
static_assert(std::is_same_v<decltype(lw), ascii::lower_wrapper<cstrview>>);
snn_require(lw.get().size() == 3);
snn_require(lw.get() == "abc");
}
{
str s{"abc"};
auto lw = ascii::as_lower<cstrview>(s);
static_assert(std::is_same_v<decltype(lw), ascii::lower_wrapper<cstrview>>);
snn_require(lw.get().size() == 3);
snn_require(lw.get() == "abc");
}
{
str s{"abc"};
auto lw = ascii::as_lower(s.view());
static_assert(std::is_same_v<decltype(lw), ascii::lower_wrapper<strview>>);
snn_require(lw.get().size() == 3);
snn_require(lw.get() == "abc");
}
return true;
}
}
}
namespace snn
{
void unittest()
{
snn_static_require(app::example());
}
}