added expected and fmt for cleaner code/interfaces
This commit is contained in:
1 parent
7f8a185678
commit
4d2e9305dc
9 files changed
+88
-47
No files matched your search
@@ -1,3 +1,5 @@
|
||||
*.user*
|
||||
cpputils/
|
||||
date/
|
||||
expected/
|
||||
fmt/
|
||||
@@ -40,7 +40,7 @@ char *toString(const espchrono::seconds32 &val)
|
||||
}
|
||||
|
||||
template<>
|
||||
char *toString(const std::optional<espchrono::seconds32> &val)
|
||||
char *toString(const tl::expected<espchrono::seconds32, std::string> &val)
|
||||
{
|
||||
return val ? ::QTest::toString(*val) : ::QTest::toString("(invalid)");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ Q_DECLARE_METATYPE(espchrono::utc_clock::time_point)
|
||||
Q_DECLARE_METATYPE(espchrono::local_clock::time_point)
|
||||
Q_DECLARE_METATYPE(espchrono::DateTime)
|
||||
Q_DECLARE_METATYPE(espchrono::LocalDateTime)
|
||||
Q_DECLARE_METATYPE(std::optional<espchrono::seconds32>)
|
||||
using X = tl::expected<espchrono::seconds32, std::string>;
|
||||
Q_DECLARE_METATYPE(X)
|
||||
|
||||
extern const espchrono::time_zone testTimeZone;
|
||||
|
||||
@@ -64,5 +65,5 @@ template<>
|
||||
char *toString(const espchrono::seconds32 &val);
|
||||
|
||||
template<>
|
||||
char *toString(const std::optional<espchrono::seconds32> &val);
|
||||
char *toString(const tl::expected<espchrono::seconds32, std::string> &val);
|
||||
} // namespace QTest
|
||||
+15
-11
@@ -227,23 +227,27 @@ private slots:
|
||||
|
||||
void test_parseDaypoint_data()
|
||||
{
|
||||
QTest::addColumn<std::string>("input");
|
||||
QTest::addColumn<std::optional<espchrono::seconds32>>("expected");
|
||||
using result_t = tl::expected<espchrono::seconds32, std::string>;
|
||||
|
||||
QTest::addRow("bullshit") << "bullshit"s << std::optional<espchrono::seconds32>{};
|
||||
QTest::addRow("missing_minute") << "00:"s << std::optional<espchrono::seconds32>{};
|
||||
QTest::addRow("zero") << "00:00"s << std::optional<espchrono::seconds32>{0s};
|
||||
QTest::addRow("zero3") << "00:00:00"s << std::optional<espchrono::seconds32>{0s};
|
||||
QTest::addRow("random") << "12:34:56"s << std::optional<espchrono::seconds32>{12h+34min+56s};
|
||||
QTest::addRow("random2") << "12:34"s << std::optional<espchrono::seconds32>{12h+34min};
|
||||
// QTest::addRow("negative") << "-12:34:56"s << std::optional<espchrono::seconds32>{-12h-34min-56s};
|
||||
// QTest::addRow("negative_leading_zero") << "-00:34:56"s << std::optional<espchrono::seconds32>{-34min-56s};
|
||||
QTest::addColumn<std::string>("input");
|
||||
QTest::addColumn<result_t>("expected");
|
||||
|
||||
QTest::addRow("bullshit") << "bullshit"s << result_t{tl::make_unexpected("invalid daypoint (bullshit)")};
|
||||
QTest::addRow("missing_minute") << "00:"s << result_t{tl::make_unexpected("invalid daypoint (00:)")};
|
||||
QTest::addRow("zero") << "00:00"s << result_t{0s};
|
||||
QTest::addRow("zero3") << "00:00:00"s << result_t{0s};
|
||||
QTest::addRow("random") << "12:34:56"s << result_t{12h+34min+56s};
|
||||
QTest::addRow("random2") << "12:34"s << result_t{12h+34min};
|
||||
// QTest::addRow("negative") << "-12:34:56"s << result_t{-12h-34min-56s};
|
||||
// QTest::addRow("negative_leading_zero") << "-00:34:56"s << result_t{-34min-56s};
|
||||
}
|
||||
|
||||
void test_parseDaypoint()
|
||||
{
|
||||
using result_t = tl::expected<espchrono::seconds32, std::string>;
|
||||
|
||||
QFETCH(std::string, input);
|
||||
QFETCH(std::optional<espchrono::seconds32>, expected);
|
||||
QFETCH(result_t, expected);
|
||||
|
||||
FIXEDCOMPARE(espchrono::parseDaypoint(input), expected);
|
||||
}
|
||||
|
||||
@@ -53,4 +53,39 @@ equals(CLONE_DATE, 1) {
|
||||
|
||||
include($$DATE_DIR/date.pri)
|
||||
|
||||
equals(CLONE_EXPECTED, 1) {
|
||||
EXPECTED_DIR = $$PWD/expected
|
||||
|
||||
message("Checking out expected...")
|
||||
exists($$EXPECTED_DIR/.git): {
|
||||
system("git -C $$EXPECTED_DIR pull")
|
||||
} else {
|
||||
system("git clone https://github.com/0xFEEDC0DE64/expected.git $$EXPECTED_DIR")
|
||||
}
|
||||
} else: exists($$PWD/../../expected/include) {
|
||||
EXPECTED_DIR = $$PWD/../../expected
|
||||
} else {
|
||||
error("expected not found, please run git submodule update --init")
|
||||
}
|
||||
|
||||
include($$EXPECTED_DIR/expected.pri)
|
||||
|
||||
equals(CLONE_FMT, 1) {
|
||||
FMT_DIR = $$PWD/fmt
|
||||
|
||||
message("Checking out fmt...")
|
||||
exists($$FMT_DIR/.git): {
|
||||
system("git -C $$FMT_DIR pull")
|
||||
} else {
|
||||
system("git clone https://github.com/0xFEEDC0DE64/fmt.git $$FMT_DIR")
|
||||
}
|
||||
} else: exists($$PWD/../../fmt/include) {
|
||||
FMT_DIR = $$PWD/../../fmt
|
||||
} else {
|
||||
error("fmt not found, please run git submodule update --init")
|
||||
}
|
||||
|
||||
include($$FMT_DIR/fmt.pri)
|
||||
include($$FMT_DIR/fmt_src.pri)
|
||||
|
||||
QMAKE_CXXFLAGS += -Wno-missing-field-initializers
|
||||
Reference in new issue
Block a user