-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunpack_front.test.cc
61 lines (49 loc) · 1.68 KB
/
unpack_front.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
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
#include "snn-core/algo/unpack_front.hh"
#include "snn-core/unittest.hh"
namespace snn::app
{
namespace
{
constexpr bool example()
{
{
char first{};
char third{};
snn_require(algo::unpack_front(cstrrng{"abcdef"}, first, std::ignore, third));
snn_require(first == 'a');
snn_require(third == 'c');
}
{
char x{};
char y{};
snn_require(x == '\0');
snn_require(y == '\0');
snn_require(algo::unpack_front(cstrrng{"abc"}));
snn_require(algo::unpack_front(cstrrng{"abc"}, x));
snn_require(x == 'a');
snn_require(algo::unpack_front(cstrrng{"123"}, x, y));
snn_require(x == '1');
snn_require(y == '2');
// Not enough elements.
snn_require(!algo::unpack_front(cstrrng{""}, x));
snn_require(x == '1'); // Not assigned.
// Not enough elements, some variables are still assigned.
snn_require(!algo::unpack_front(cstrrng{"A"}, x, y));
snn_require(x == 'A');
snn_require(y == '2'); // Not assigned.
snn_require_throws_code(algo::unpack_front(cstrrng{""}, x).or_throw(),
generic::error::no_value);
}
return true;
}
}
}
namespace snn
{
void unittest()
{
snn_static_require(app::example());
}
}