mirror of
https://github.com/audacity/linuxdeploy.git
synced 2026-04-16 13:11:33 -05:00
Implement conversion to double
This commit is contained in:
@@ -87,6 +87,12 @@ long DesktopFileEntry::asLong() const {
|
||||
return lexical_cast<long>(value());
|
||||
}
|
||||
|
||||
double DesktopFileEntry::asDouble() const {
|
||||
d->assertValueNotEmpty();
|
||||
|
||||
return lexical_cast<double>(value());
|
||||
}
|
||||
|
||||
std::vector<std::string> DesktopFileEntry::parseStringList() const {
|
||||
const auto& value = this->value();
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ public:
|
||||
// throws boost::bad_lexical_cast in case of type errors
|
||||
long asLong() const;
|
||||
|
||||
// convert value to double
|
||||
// throws boost::bad_lexical_cast in case of type errors
|
||||
double asDouble() const;
|
||||
|
||||
// split CSV list value into vector
|
||||
// the separator used to split the string is a semicolon as per desktop file spec
|
||||
std::vector<std::string> parseStringList() const;
|
||||
|
||||
@@ -116,6 +116,17 @@ TEST_F(DesktopFileEntryFixture, testConversionToLong) {
|
||||
ASSERT_THROW(emptyEntry.asLong(), std::invalid_argument);
|
||||
}
|
||||
|
||||
TEST_F(DesktopFileEntryFixture, testConversionToDouble) {
|
||||
DesktopFileEntry doubleEntry(key, "1.234567");
|
||||
EXPECT_NEAR(doubleEntry.asDouble(), 1.234567, 0.00000001);
|
||||
|
||||
DesktopFileEntry brokenValueEntry(key, "abcd");
|
||||
ASSERT_THROW(brokenValueEntry.asDouble(), bad_lexical_cast);
|
||||
|
||||
DesktopFileEntry emptyEntry(key, "");
|
||||
ASSERT_THROW(emptyEntry.asDouble(), std::invalid_argument);
|
||||
}
|
||||
|
||||
TEST_F(DesktopFileEntryFixture, testConversionToString) {
|
||||
DesktopFileEntry entry(key, value);
|
||||
auto result = static_cast<std::string>(entry);
|
||||
|
||||
Reference in New Issue
Block a user