Fix formatting in ParseTextDataByte and optimize message handling in ReadAllTextDataV2
This commit is contained in:
@@ -82,9 +82,8 @@ TEST_F(MessageTest, ParseMessageToData_Basic) {
|
||||
|
||||
TEST_F(MessageTest, ReplaceAllDictionaryWords_Success) {
|
||||
std::vector<editor::DictionaryEntry> mock_dict = {
|
||||
editor::DictionaryEntry(0x00, "test"),
|
||||
editor::DictionaryEntry(0x01, "message")
|
||||
};
|
||||
editor::DictionaryEntry(0x00, "test"),
|
||||
editor::DictionaryEntry(0x01, "message")};
|
||||
std::string input = "This is a test message.";
|
||||
auto result = editor::ReplaceAllDictionaryWords(input, mock_dict);
|
||||
EXPECT_EQ(result, "This is a [D:00] [D:01].");
|
||||
@@ -92,8 +91,7 @@ TEST_F(MessageTest, ReplaceAllDictionaryWords_Success) {
|
||||
|
||||
TEST_F(MessageTest, ReplaceAllDictionaryWords_NoMatch) {
|
||||
std::vector<editor::DictionaryEntry> mock_dict = {
|
||||
editor::DictionaryEntry(0x00, "hello")
|
||||
};
|
||||
editor::DictionaryEntry(0x00, "hello")};
|
||||
std::string input = "No matching words.";
|
||||
auto result = editor::ReplaceAllDictionaryWords(input, mock_dict);
|
||||
EXPECT_EQ(result, "No matching words.");
|
||||
@@ -102,12 +100,76 @@ TEST_F(MessageTest, ReplaceAllDictionaryWords_NoMatch) {
|
||||
TEST_F(MessageTest, ParseTextDataByte_Success) {
|
||||
EXPECT_EQ(editor::ParseTextDataByte(0x00), "A");
|
||||
EXPECT_EQ(editor::ParseTextDataByte(0x74), "[1]");
|
||||
EXPECT_EQ(editor::ParseTextDataByte(0x88), "[D:0]");
|
||||
EXPECT_EQ(editor::ParseTextDataByte(0x88), "[D:00]");
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, ParseTextDataByte_Failure) {
|
||||
EXPECT_EQ(editor::ParseTextDataByte(0xFF), "");
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, ParseSingleMessage_EmptyData) {
|
||||
std::vector<uint8_t> mock_data = {0x7F};
|
||||
int pos = 0;
|
||||
|
||||
auto result = editor::ParseSingleMessage(mock_data, &pos);
|
||||
ASSERT_TRUE(result.ok());
|
||||
const auto message_data = result.value();
|
||||
|
||||
EXPECT_EQ(message_data.ContentsParsed, "");
|
||||
EXPECT_EQ(pos, 1);
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, OptimizeMessageForDictionary_Basic) {
|
||||
std::vector<editor::DictionaryEntry> mock_dict = {
|
||||
editor::DictionaryEntry(0x00, "Link"),
|
||||
editor::DictionaryEntry(0x01, "Zelda")};
|
||||
std::string input = "[L] rescued Zelda from danger.";
|
||||
|
||||
editor::MessageData message_data;
|
||||
std::string optimized =
|
||||
message_data.OptimizeMessageForDictionary(input, mock_dict);
|
||||
|
||||
EXPECT_EQ(optimized, "[L] rescued [D:01] from danger.");
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, SetMessage_Success) {
|
||||
std::vector<editor::DictionaryEntry> mock_dict = {
|
||||
editor::DictionaryEntry(0x00, "item")};
|
||||
editor::MessageData message_data;
|
||||
std::string input = "You got an item!";
|
||||
|
||||
message_data.SetMessage(input, mock_dict);
|
||||
|
||||
EXPECT_EQ(message_data.RawString, "You got an item!");
|
||||
EXPECT_EQ(message_data.ContentsParsed, "You got an [D:00]!");
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, FindMatchingElement_CommandWithArgument) {
|
||||
std::string input = "[W:02]";
|
||||
editor::ParsedElement result = editor::FindMatchingElement(input);
|
||||
|
||||
EXPECT_TRUE(result.Active);
|
||||
EXPECT_EQ(result.Parent.Token, "W");
|
||||
EXPECT_EQ(result.Value, 0x02);
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, FindMatchingElement_InvalidCommand) {
|
||||
std::string input = "[INVALID]";
|
||||
editor::ParsedElement result = editor::FindMatchingElement(input);
|
||||
|
||||
EXPECT_FALSE(result.Active);
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, ImportMessageData_InvalidFile) {
|
||||
auto result = editor::ImportMessageData("nonexistent_file.txt");
|
||||
EXPECT_TRUE(result.empty());
|
||||
}
|
||||
|
||||
TEST_F(MessageTest, BuildDictionaryEntries_CorrectSize) {
|
||||
auto result = editor::BuildDictionaryEntries(rom());
|
||||
EXPECT_EQ(result.size(), editor::kNumDictionaryEntries);
|
||||
EXPECT_FALSE(result.empty());
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace yaze
|
||||
|
||||
Reference in New Issue
Block a user