Skip to content

Commit 2fb74bf

Browse files
committed
Improve support for locale strings
Doesn't properly validate the locale strings yet, but should accept all valid ones.
1 parent d6a4627 commit 2fb74bf

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

tests/test_desktopfilereader.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -391,27 +391,33 @@ TEST_F(DesktopFileReaderTest, testReadBrokenSectionMissingOpeningBracket) {
391391

392392
// FIXME: introduce proper localization support
393393
TEST_F(DesktopFileReaderTest, testReadLocalizedEntriesWithoutProperLocalizationSupport) {
394-
std::stringstream ss;
395-
ss << "[Desktop File]" << std::endl
396-
<< "Name=name" << std::endl
397-
<< "Name[de]=name" << std::endl
398-
<< "Exec=exec" << std::endl;
394+
// lang_COUNTRY.ENCODING@MODIFIER
395+
// https://standards.freedesktop.org/desktop-entry-spec/latest/ar01s05.html
396+
for (std::string locale : {"de", "de_DE", "ca@valencia", "de_DE.UTF-8"}) {
397+
std::stringstream ss;
398+
ss << "[Desktop Entry]" << std::endl
399+
<< "Name=name" << std::endl
400+
<< "Name[" << locale << "]=name" << std::endl
401+
<< "Exec=exec" << std::endl;
399402

400-
DesktopFileReader reader(ss);
403+
DesktopFileReader reader;
401404

402-
auto section = reader["Desktop File"];
403-
EXPECT_FALSE(section.empty());
405+
EXPECT_NO_THROW(reader = DesktopFileReader(ss)) << "tested locale string: " << locale;
404406

405-
auto data = reader.data();
407+
auto section = reader["Desktop Entry"];
408+
EXPECT_FALSE(section.empty());
406409

407-
auto expected = DesktopFile::section_t({
408-
{"Name", DesktopFileEntry("Name", "name")},
409-
// FIXME: revise after introduction of localization support
410-
{"Name[de]", DesktopFileEntry("Name[de]", "name")},
411-
{"Exec", DesktopFileEntry("Exec", "exec")},
412-
});
410+
auto data = reader.data();
413411

414-
EXPECT_EQ(data["Desktop File"], expected);
412+
auto expected = DesktopFile::section_t({
413+
{"Name", DesktopFileEntry("Name", "name")},
414+
// FIXME: revise after introduction of localization support
415+
{"Name[" + locale + "]", DesktopFileEntry("Name[" + locale + "]", "name")},
416+
{"Exec", DesktopFileEntry("Exec", "exec")},
417+
});
418+
419+
EXPECT_EQ(data["Desktop Entry"], expected) << "tested locale string: " << locale;
420+
}
415421
}
416422

417423
TEST_F(DesktopFileReaderTest, testBrokenLocalizedKeys) {

0 commit comments

Comments
 (0)