Skip to content

Commit a194154

Browse files
committed
test_pray: don't return pointer to local object in matchEvent
1 parent 52686a4 commit a194154

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

tests/test_pray.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ static std::string eventsToString(const std::vector<PraySourceParser::Event>& ev
1717
}
1818

1919
template <typename T, typename F>
20-
T* matchEvent(const std::vector<PraySourceParser::Event>& events, F f) {
21-
for (auto e : events) {
20+
const T* matchEvent(const std::vector<PraySourceParser::Event>& events, F f) {
21+
for (auto& e : events) {
2222
auto matched = mpark::get_if<T>(&e);
2323
if (matched && f(*matched)) {
2424
return matched;
@@ -28,8 +28,8 @@ T* matchEvent(const std::vector<PraySourceParser::Event>& events, F f) {
2828
}
2929

3030
template <typename T>
31-
T* matchEvent(const std::vector<PraySourceParser::Event>& events) {
32-
return matchEvent<T>(events, [](T&) { return true; });
31+
const T* matchEvent(const std::vector<PraySourceParser::Event>& events) {
32+
return matchEvent<T>(events, [](const T&) { return true; });
3333
}
3434

3535
TEST(praysourceparser, character_escapes) {
@@ -48,7 +48,7 @@ TEST(caos2prayparser, character_escapes) {
4848
*# DS-Name "My Agent"
4949
*# Agent Description = "A \"really cool\" agent\nThis is a backslash\\"
5050
)", nullptr);
51-
auto string_tag = matchEvent<PraySourceParser::StringTag>(events, [](PraySourceParser::StringTag &e) {
51+
auto string_tag = matchEvent<PraySourceParser::StringTag>(events, [](const PraySourceParser::StringTag &e) {
5252
return e.key == "Agent Description";
5353
});
5454
if (!string_tag) FAIL() << "No such event in:\n" + eventsToString(events);
@@ -112,7 +112,7 @@ TEST(caos2prayparser, cp1252_to_utf8) {
112112
*# DS-Name "My Agent"
113113
*# Agent Description-fr = )") + "\"Un tr\xe8s cool agent\"",
114114
nullptr);
115-
auto string_tag = matchEvent<PraySourceParser::StringTag>(events, [](PraySourceParser::StringTag &e) {
115+
auto string_tag = matchEvent<PraySourceParser::StringTag>(events, [](const PraySourceParser::StringTag &e) {
116116
return e.key == "Agent Description-fr";
117117
});
118118
if (!string_tag) FAIL() << "No such event in:\n" + eventsToString(events);
@@ -124,7 +124,7 @@ TEST(caos2prayparser, utf8_to_utf8) {
124124
*# DS-Name "My Agent"
125125
*# Agent Description-fr = )") + "\"Un tr\xc3\xa8s cool agent\"",
126126
nullptr);
127-
auto string_tag = matchEvent<PraySourceParser::StringTag>(events, [](PraySourceParser::StringTag &e) {
127+
auto string_tag = matchEvent<PraySourceParser::StringTag>(events, [](const PraySourceParser::StringTag &e) {
128128
return e.key == "Agent Description-fr";
129129
});
130130
if (!string_tag) FAIL() << "No such event in:\n" + eventsToString(events);
@@ -176,4 +176,4 @@ TEST(prayreader, windows1252_to_utf8) {
176176
EXPECT_EQ(reader.getBlockName(0), "Agent tr\xc3\xa8s cool");
177177
ASSERT_EQ(stringValues.size(), 1);
178178
EXPECT_EQ(stringValues["Repr\xc3\xa8sentation"], "Mon agent est tr\xc3\xa8s cool");
179-
}
179+
}

0 commit comments

Comments
 (0)