Skip to content

Commit

Permalink
added more convert functions and extended value tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zussel committed May 10, 2024
1 parent f1469bf commit 7acc54f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/matador/utils/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ void convert(utils::blob &dest, const utils::blob &data);

void convert(std::string &dest, const date &source);

template < typename SourceType >
void convert(date &/*dest*/, SourceType &/*source*/)

Check warning on line 130 in include/matador/utils/convert.hpp

View check run for this annotation

Codecov / codecov/patch

include/matador/utils/convert.hpp#L130

Added line #L130 was not covered by tests
{
throw std::logic_error("couldn't convert value into date");

Check warning on line 132 in include/matador/utils/convert.hpp

View check run for this annotation

Codecov / codecov/patch

include/matador/utils/convert.hpp#L132

Added line #L132 was not covered by tests
}

template < typename DestType >
void convert(DestType &/*dest*/, const time &/*data*/)

Check warning on line 136 in include/matador/utils/convert.hpp

View check run for this annotation

Codecov / codecov/patch

include/matador/utils/convert.hpp#L136

Added line #L136 was not covered by tests
{
Expand All @@ -134,6 +140,12 @@ void convert(DestType &/*dest*/, const time &/*data*/)

void convert(std::string &dest, const time &source);

template < typename SourceType >
void convert(time &/*dest*/, SourceType &/*source*/)

Check warning on line 144 in include/matador/utils/convert.hpp

View check run for this annotation

Codecov / codecov/patch

include/matador/utils/convert.hpp#L144

Added line #L144 was not covered by tests
{
throw std::logic_error("couldn't convert value into time");

Check warning on line 146 in include/matador/utils/convert.hpp

View check run for this annotation

Codecov / codecov/patch

include/matador/utils/convert.hpp#L146

Added line #L146 was not covered by tests
}

template < typename DestType >
void convert(DestType &/*dest*/, const date &/*data*/)

Check warning on line 150 in include/matador/utils/convert.hpp

View check run for this annotation

Codecov / codecov/patch

include/matador/utils/convert.hpp#L150

Added line #L150 was not covered by tests
{
Expand Down
18 changes: 18 additions & 0 deletions test/catch2/sql/ValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "matador/sql/types.hpp"
#include "matador/sql/value.hpp"

#include "matador/utils/date.hpp"
#include "matador/utils/time.hpp"
#include "matador/utils/types.hpp"

using namespace matador;
Expand Down Expand Up @@ -69,4 +71,20 @@ TEST_CASE("Test value class", "[value]") {
REQUIRE(v.is_blob());
REQUIRE(v.data_type() == data_type::type_blob);
REQUIRE(v.size() == 4);

const auto today = date{};
v = today;

REQUIRE(v.is_date());
REQUIRE(v.data_type() == data_type::type_date);
REQUIRE(v.size() == 0);
REQUIRE(v.as<date>() == today);

const auto now = matador::time{};
v = now;

REQUIRE(v.is_time());
REQUIRE(v.data_type() == data_type::type_time);
REQUIRE(v.size() == 0);
REQUIRE(v.as<matador::time>() == now);
}

0 comments on commit 7acc54f

Please sign in to comment.