mirror of
https://github.com/audacity/linuxdeploy.git
synced 2026-04-16 21:51:43 -05:00
Add data getter
This commit is contained in:
@@ -146,6 +146,10 @@ namespace linuxdeploy {
|
||||
return d->path;
|
||||
}
|
||||
|
||||
DesktopFile::sections_t DesktopFileReader::data() const {
|
||||
return d->sections;
|
||||
}
|
||||
|
||||
DesktopFile::section_t DesktopFileReader::operator[](const std::string& name) const {
|
||||
auto it = d->sections.find(name);
|
||||
|
||||
|
||||
@@ -56,6 +56,10 @@ namespace linuxdeploy {
|
||||
// get a specific section from the parsed data
|
||||
// throws std::range_error if section does not exist
|
||||
DesktopFile::section_t operator[](const std::string& name) const;
|
||||
|
||||
// get copy of internal data storage
|
||||
// can be handed to a DesktopFileWriter instance, or to manually hack on the data
|
||||
DesktopFile::sections_t data() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,3 +166,24 @@ TEST_F(DesktopFileReaderFixture, testParseFileWithLeadingAndTrailingWhitespaceIn
|
||||
EXPECT_EQ(section["Name"].value(), "name");
|
||||
EXPECT_EQ(section["Exec"].value(), "exec");
|
||||
}
|
||||
|
||||
TEST_F(DesktopFileReaderFixture, testDataGetter) {
|
||||
std::stringstream ss;
|
||||
ss << "[Desktop File]" << std::endl
|
||||
<< "Name= name" << std::endl
|
||||
<< "Exec =exec" << std::endl;
|
||||
|
||||
DesktopFileReader reader(ss);
|
||||
|
||||
auto section = reader["Desktop File"];
|
||||
EXPECT_FALSE(section.empty());
|
||||
|
||||
auto data = reader.data();
|
||||
|
||||
auto expected = DesktopFile::section_t({
|
||||
{"Name", DesktopFileEntry("Name", "name")},
|
||||
{"Exec", DesktopFileEntry("Exec", "exec")},
|
||||
});
|
||||
|
||||
EXPECT_EQ(data["Desktop File"], expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user