Skip to content

Commit 280dbaa

Browse files
committed
avoid problem with structured bindings and clang, see https://stackoverflow.com/questions/67883701/structured-binding-violations
1 parent f3df50e commit 280dbaa

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

tests/test-base32.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77

88
TEST_CASE("base32") {
99
enum { E=1, D=2, FD=4 };
10-
std::vector<std::tuple<std::vector<uint8_t>, int, std::string>> testcases = {
10+
11+
struct testent {
12+
std::vector<uint8_t> data;
13+
int flags;
14+
std::string txt;
15+
};
16+
17+
std::vector<testent> testcases = {
1118
{ { }, E|D, "" },
1219
{ { }, D, "\n" },
1320
{ { }, D, "\t" },
@@ -24,21 +31,19 @@ TEST_CASE("base32") {
2431
{ { 0x66,0x6f,0x6f,0x62 }, E|D, "MZXW6YQ=" },
2532
{ { 0x66,0x6f,0x6f,0x62,0x61 }, E|D, "MZXW6YTB" },
2633
{ { 0x66,0x6f,0x6f,0x62,0x61,0x72 }, E|D, "MZXW6YTBOI======" },
27-
28-
2934
};
3035
SECTION("cases") {
31-
for (auto& [data, flags, txt] : testcases) {
32-
if (flags&E) {
33-
auto e = base32_encode(data);
34-
CHECK(e == txt);
36+
for (auto& ent : testcases) {
37+
if (ent.flags&E) {
38+
auto e = base32_encode(ent.data);
39+
CHECK(e == ent.txt);
3540
}
36-
if (flags&D) {
37-
auto d = base32_decode(txt);
38-
CHECK(d == data);
41+
if (ent.flags&D) {
42+
auto d = base32_decode(ent.txt);
43+
CHECK(d == ent.data);
3944
}
40-
if (flags&FD) {
41-
CHECK_THROWS(base32_decode(txt));
45+
if (ent.flags&FD) {
46+
CHECK_THROWS(base32_decode(ent.txt));
4247
}
4348
}
4449
}

tests/test-base64.cpp

+20-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ TEST_CASE("base64") {
1212
D=2, // decode must succeed.
1313
FD=4, // decode must fail.
1414
};
15-
std::vector<std::tuple<std::vector<uint8_t>, int, std::string>> testcases = {
15+
struct testent {
16+
std::vector<uint8_t> data;
17+
int flags;
18+
std::string txt;
19+
};
20+
21+
22+
std::vector<testent> testcases = {
1623
{ { }, E|D, "" },
1724
{ { }, E|D|NP, "" },
1825
{ { }, D, "\n" },
@@ -98,23 +105,23 @@ E|D, "//79/Pv6+fj39vX08/Lx8O/u7ezr6uno5+bl5OPi4eDf3t3c29rZ2NfW1dTT0tHQz87NzMvKyc
98105

99106
};
100107
SECTION("cases") {
101-
for (auto& [data, flags, txt] : testcases) {
102-
if (flags&E) {
103-
if (flags&NP) {
104-
auto e = base64_encode_unpadded(data);
105-
CHECK(e == txt);
108+
for (auto& ent : testcases) {
109+
if (ent.flags&E) {
110+
if (ent.flags&NP) {
111+
auto e = base64_encode_unpadded(ent.data);
112+
CHECK(e == ent.txt);
106113
}
107114
else {
108-
auto e = base64_encode(data);
109-
CHECK(e == txt);
115+
auto e = base64_encode(ent.data);
116+
CHECK(e == ent.txt);
110117
}
111118
}
112-
if (flags&D) {
113-
auto d = base64_decode(txt);
114-
CHECK(d == data);
119+
if (ent.flags&D) {
120+
auto d = base64_decode(ent.txt);
121+
CHECK(d == ent.data);
115122
}
116-
if (flags&FD) {
117-
CHECK_THROWS(base64_decode(txt));
123+
if (ent.flags&FD) {
124+
CHECK_THROWS(base64_decode(ent.txt));
118125
}
119126
}
120127
}

0 commit comments

Comments
 (0)