Tests: add test to parse string to get quantity

This commit is contained in:
wmayer
2023-02-28 15:11:32 +01:00
committed by wwmayer
parent 315a1158a9
commit 9b3b4e835e

View File

@@ -6,6 +6,7 @@
#include <Base/UnitsApi.h>
#include <Base/UnitsSchemaImperial1.h>
// NOLINTBEGIN
TEST(Unit, TestString)
{
auto toString = [](const Base::Unit& unit) {
@@ -190,6 +191,14 @@ TEST(BaseQuantity, TestValid)
EXPECT_EQ(q2.isValid(), false);
}
TEST(BaseQuantity, TestParse)
{
Base::Quantity q1 = Base::Quantity::parse(QString::fromLatin1("1,234 kg"));
EXPECT_EQ(q1, Base::Quantity(1.2340, Base::Unit::Mass));
EXPECT_THROW(boost::ignore_unused(Base::Quantity::parse(QString::fromLatin1("1,234,500.12 kg"))), Base::ParserError);
}
TEST(BaseQuantity, TestDim)
{
Base::Quantity q1{0, Base::Unit::Area};
@@ -388,3 +397,4 @@ TEST_F(Quantity, TestSafeUserString)
EXPECT_EQ(result.toStdString(), "1 mm");
}
// NOLINTEND