mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Throw if constructing a non-English multilingual message
This matches the behaviour for when converting from YAML, ensuring that a non-English multilingual message can never be created.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "message.h"
|
||||
#include "../helpers/language.h"
|
||||
#include "../error.h"
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
@@ -42,7 +43,17 @@ namespace loot {
|
||||
}
|
||||
|
||||
Message::Message(const unsigned int type, const std::vector<MessageContent>& content,
|
||||
const std::string& condition) : _type(type), _content(content), ConditionalMetadata(condition) {}
|
||||
const std::string& condition) : _type(type), _content(content), ConditionalMetadata(condition) {
|
||||
if (content.size() > 1) {
|
||||
bool englishStringExists = false;
|
||||
for (const auto &mc : content) {
|
||||
if (mc.Language() == loot::Language::english)
|
||||
englishStringExists = true;
|
||||
}
|
||||
if (!englishStringExists)
|
||||
throw loot::error(error::invalid_args, "bad conversion: multilingual messages must contain an English content string");
|
||||
}
|
||||
}
|
||||
|
||||
bool Message::operator < (const Message& rhs) const {
|
||||
if (!_content.empty() && !rhs.Content().empty())
|
||||
|
||||
@@ -71,6 +71,14 @@ namespace loot {
|
||||
EXPECT_EQ("condition1", message.Condition());
|
||||
}
|
||||
|
||||
TEST_P(MessageTest, vectorContentConstructorShouldThrowIfMultipleContentStringsAreGivenAndNoneAreEnglish) {
|
||||
MessageContents contents({
|
||||
MessageContent("content1", Language::german),
|
||||
MessageContent("content2", Language::french),
|
||||
});
|
||||
EXPECT_ANY_THROW(Message(Message::error, contents, "condition1"));
|
||||
}
|
||||
|
||||
TEST_P(MessageTest, messagesWithDifferentContentStringsShouldBeUnequal) {
|
||||
Message message1(Message::say, "content1", "condition1");
|
||||
Message message2(Message::say, "content2", "condition1");
|
||||
|
||||
Reference in New Issue
Block a user