Skip to content

Commit

Permalink
Fix tests for msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
vt4a2h committed Oct 28, 2024
1 parent 241d3b8 commit 68561bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
5 changes: 1 addition & 4 deletions src/include/fl/expected/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ class Expected
return std::get<Error_>(std::forward<Self>(self).m_data);
}

template <class AnotherValue, class AnotherError>
requires (std::equality_comparable_with<typename Expected::Data,
typename Expected<AnotherError, AnotherValue>::Data>)
constexpr friend bool operator ==(const Expected &lhs, const Expected<AnotherError, AnotherValue> &rhs)
constexpr friend bool operator ==(const Expected &lhs, const Expected &rhs)
{
return lhs.m_data == rhs.m_data;
}
Expand Down
14 changes: 7 additions & 7 deletions test/test_expected_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ TEST_CASE("Expected create")

SECTION("[Constexpr] From unexpected")
{
static constexpr std::string string;
static constexpr auto unexpected = fl::Unexpected(string);
static constexpr fl::Expected<int, std::string> expectedBox(unexpected);
static constexpr std::string_view string_view{"42"};
static constexpr auto unexpected = fl::Unexpected(string_view);
static constexpr fl::Expected<int, std::string_view> expectedBox(unexpected);

STATIC_REQUIRE(expectedBox.hasError());
}

SECTION("[Constexpr] From unexpected with correct value")
{
static constexpr std::string string{"42"};
static constexpr auto unexpected = fl::Unexpected(string);
static constexpr fl::Expected<int, std::string> expectedBox(unexpected);
static constexpr std::string_view string_view{"42"};
static constexpr auto unexpected = fl::Unexpected(string_view);
static constexpr fl::Expected<int, std::string_view> expectedBox(unexpected);

STATIC_REQUIRE(expectedBox.error() == string);
STATIC_REQUIRE(expectedBox.error() == string_view);
}

SECTION("Copy ctor")
Expand Down
26 changes: 19 additions & 7 deletions test/test_expected_unexpected_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include <fl/expected/expected.hpp>

#include <string>
#include <optional>
#include <ranges>
#include <algorithm>

constexpr fl::Unexpected<int> moveCtorConstexpr(int data)
{
Expand All @@ -22,6 +25,15 @@ constexpr fl::Unexpected<int> moveCtorConstexpr(int data)
return unexpectedMoved;
}

template <class T>
struct SumIlVal
{
constexpr SumIlVal(std::initializer_list<T> il, T val)
: sum (std::ranges::fold_left(il, val, std::plus<int>{}))
{}
T sum{};
};

TEST_CASE("Create unexpected")
{
SECTION("From value")
Expand All @@ -34,7 +46,7 @@ TEST_CASE("Create unexpected")

SECTION("[Constexpr] From value")
{
static constexpr std::string data{"42"};
static constexpr std::string_view data{"42"};
static constexpr auto unexpected = fl::Unexpected(data);

STATIC_REQUIRE(unexpected.error() == data);
Expand All @@ -58,10 +70,10 @@ TEST_CASE("Create unexpected")

SECTION("Move ctor")
{
auto unexpected = fl::Unexpected("42");
auto unexpectedMoved{std::move(unexpected)};
auto unexpected = fl::Unexpected<std::string_view>("42");
fl::Unexpected unexpectedMoved{std::move(unexpected)};

REQUIRE(fl::Unexpected("42") == unexpectedMoved);
REQUIRE(fl::Unexpected<std::string_view>("42") == unexpectedMoved);
}

SECTION("[Constexpr] Move ctor")
Expand All @@ -84,7 +96,7 @@ TEST_CASE("Create unexpected")

SECTION("[Constexpr] From value in-place")
{
static constexpr auto unexpected = fl::Unexpected<std::string>(std::in_place_t{}, "42");
static constexpr auto unexpected = fl::Unexpected<std::string_view>(std::in_place_t{}, "42");

STATIC_REQUIRE(unexpected.error() == "42");
}
Expand All @@ -98,8 +110,8 @@ TEST_CASE("Create unexpected")

SECTION("[Constexpr] From value in-place with initializer list")
{
static constexpr auto unexpected = fl::Unexpected<std::string>(std::in_place_t{}, {'4', '2'}, std::allocator<char>{});
static constexpr auto unexpected = fl::Unexpected<SumIlVal<int>>(std::in_place_t{}, {40}, 2);

REQUIRE(unexpected.error() == std::string{"42"});
STATIC_REQUIRE(unexpected.error().sum == 42);
}
}

0 comments on commit 68561bf

Please sign in to comment.