Fix some errors in FileParser

This commit is contained in:
Kai Blaschke
2022-03-24 20:13:27 +01:00
parent 1c436c3277
commit dfe08a14bb
4 changed files with 7 additions and 5 deletions

View File

@ -168,7 +168,7 @@ void FileParser::ParseLine(const std::string& line)
std::string value(line.begin() + varNameDelimiterPos + 1, line.end());
// Only add first occurrence to mimic Milkdrop behaviour
if (!varName.empty() && !value.empty() && m_presetValues.find(varName) == m_presetValues.end())
if (!varName.empty() && m_presetValues.find(varName) == m_presetValues.end())
{
m_presetValues.emplace(std::move(varName), std::move(value));
}

View File

@ -17,7 +17,7 @@ class FileParser
public:
using ValueMap = std::map<std::string, std::string>; //!< A map with key/value pairs, each representing one line in the preset file.
static constexpr std::streamsize maxFileSize = 0x100000; //!< Maximum size of a preset file. Used for sanity checks.
static constexpr size_t maxFileSize = 0x100000; //!< Maximum size of a preset file. Used for sanity checks.
/**
* @brief Reads the preset file into an internal map to prepare for parsing.

View File

@ -61,8 +61,9 @@ TEST(FileParser, EmptyValue)
const auto& values = parser.PresetValues();
// Lines with empty values should be ignored
EXPECT_TRUE(values.find("empty_value") == values.end());
// Lines with empty values should be stored as such
ASSERT_FALSE(values.find("empty_value") == values.end());
EXPECT_EQ(values.at("empty_value"), "");
}
TEST(FileParser, EmptyKey)

View File

@ -1,7 +1,8 @@
// Very simple multi-line equation
per_frame_1=r=1.0;
per_frame_2=g=1.0;
per_frame_3=b=1.0;
per_frame_3=
per_frame_4=b=1.0;
// A gap in numbering should terminate parsing
per_frame_gap_1=r=1.0;