Skip to content

Commit

Permalink
test(*): more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
c0nstexpr committed Apr 23, 2024
1 parent 713f189 commit 94cb4e4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.24)
#
project(
stdsharp
VERSION 0.9.0
VERSION 0.9.1
LANGUAGES CXX)

include(cmake/Utils.cmake)
Expand Down
2 changes: 1 addition & 1 deletion include/stdsharp/synchronizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace stdsharp

private:
template<typename Lock, typename... Args, typename T, typename Self>
// requires std::constructible_from<Lock, lock_type&, Args...>
requires std::constructible_from<Lock, lock_type&, Args...>
constexpr auto write_impl(this Self&& self, T&& value, Args&&... args)
{
using cast_t = forward_cast_t<Self, T>;
Expand Down
80 changes: 39 additions & 41 deletions tests/src/default_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ STDSHARP_TEST_NAMESPACES;
using namespace default_operator;

template<typename T>
void arithmetic_test()
void arithmetic_test([[maybe_unused]] T v = {})
{
[[maybe_unused]] T v{};
STATIC_REQUIRE(requires { v += 1; });
STATIC_REQUIRE(requires { v -= 1; });
STATIC_REQUIRE(requires { v *= 1; });
STATIC_REQUIRE(requires { v /= 1; });
STATIC_REQUIRE(requires { v %= 1; });
STATIC_REQUIRE(requires { v &= 1; });
STATIC_REQUIRE(requires { v |= 1; });
STATIC_REQUIRE(requires { v ^= 1; });
STATIC_REQUIRE(requires { v <<= 1; });
STATIC_REQUIRE(requires { v >>= 1; });

STATIC_REQUIRE(requires { v + 1; });
STATIC_REQUIRE(requires { v - 1; });
Expand All @@ -23,10 +32,8 @@ void arithmetic_test()
}

template<typename T>
void commutative_arithmetic_test()
void commutative_arithmetic_test([[maybe_unused]] T v = {})
{
[[maybe_unused]] T v{};

STATIC_REQUIRE(requires { 1 + v; });
STATIC_REQUIRE(requires { 1 - v; });
STATIC_REQUIRE(requires { 1 * v; });
Expand All @@ -40,43 +47,34 @@ void commutative_arithmetic_test()
STATIC_REQUIRE(requires { +v; });
}

SCENARIO("incrementable", "[default operator]")
struct increase_t : increase
{
[[maybe_unused]] struct : increase
{
using increase::operator++;
using increase::operator--;
using increase::operator++;
using increase::operator--;

auto& operator++() { return *this; }
increase_t& operator++();

auto& operator--() { return *this; }
} v{};
increase_t& operator--();
};

STATIC_REQUIRE(requires { v++; });
STATIC_REQUIRE(requires { v--; });
SCENARIO("incrementable", "[default operator]")
{
STATIC_REQUIRE(requires(increase_t v) { v++; });
STATIC_REQUIRE(requires(increase_t v) { v--; });
}

struct arith : arithmetic
{
auto& operator+=(int /*unused*/) { return *this; }

auto& operator-=(int /*unused*/) { return *this; }

auto& operator*=(int /*unused*/) { return *this; }

auto& operator/=(int /*unused*/) { return *this; }

auto& operator%=(int /*unused*/) { return *this; }

auto& operator&=(int /*unused*/) { return *this; }

auto& operator|=(int /*unused*/) { return *this; }

auto& operator^=(int /*unused*/) { return *this; }

auto& operator<<=(int /*unused*/) { return *this; }

auto& operator>>=(int /*unused*/) { return *this; }
arith& operator+=(int);
arith& operator-=(int);
arith& operator*=(int);
arith& operator/=(int);
arith& operator%=(int);
arith& operator&=(int);
arith& operator|=(int);
arith& operator^=(int);
arith& operator<<=(int);
arith& operator>>=(int);
};

SCENARIO("arithmetic", "[default operator]") { arithmetic_test<arith>(); }
Expand Down Expand Up @@ -138,15 +136,15 @@ SCENARIO("arrow", "[default operator]")

// TODO: multidimensional subscript
#if __cpp_multidimensional_subscript >= 202110L
SCENARIO("subscript", "[default operator]")
struct subscript_t : subscript
{
[[maybe_unused]] struct : subscript
{
using subscript::operator[];
using subscript::operator[];

[[nodiscard]] auto operator[](const int /*unused*/) const { return *this; }
} v{};
subscript_t operator[](int) const;
};

STATIC_REQUIRE(requires { v[0, 1]; });
SCENARIO("subscript", "[default operator]")
{
STATIC_REQUIRE(requires(subscript_t v) { v[0, 1]; });
}
#endif
20 changes: 13 additions & 7 deletions tests/src/type_traits/type_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ SCENARIO("type sequence apply", "[type traits][type sequence]")

namespace
{
inline constexpr auto type_sequence_invoker = []<typename T>(const basic_type_constant<T>) {};
struct type_sequence_invoker
{
template<typename T>
constexpr void operator()(const basic_type_constant<T> /*unused*/)
{
}
};
}

TEMPLATE_TEST_CASE(
"Scenario: type sequence invoke",
"[type traits][type sequence]",
identity,
decltype(type_sequence_invoker)
type_sequence_invoker
)
{
STATIC_REQUIRE(invocable<test_seq::invoke_fn<>, TestType>);
Expand All @@ -49,9 +55,9 @@ TEMPLATE_TEST_CASE_SIG(
"Scenario: type sequence find",
"[type traits][type sequence]",
((typename T, auto Expect), T, Expect),
(int, 0) //,
// (float, 1),
// (void, test_seq::size())
(int, 0),
(float, 1),
(void, test_seq::size())
)
{
STATIC_REQUIRE(
Expand All @@ -73,7 +79,7 @@ TEMPLATE_TEST_CASE_SIG(
);
}

TEMPLATE_TEST_CASE_SIG(
TEMPLATE_TEST_CASE_SIG(
"Scenario: type sequence append",
"[type traits][type sequence]",
( //
Expand Down Expand Up @@ -102,7 +108,7 @@ TEMPLATE_TEST_CASE_SIG(
STATIC_REQUIRE(same_as<test_seq::append_front_t<T...>, FrontExpect>);
}

TEMPLATE_TEST_CASE_SIG(
TEMPLATE_TEST_CASE_SIG(
"Scenario: type sequence insert",
"[type traits][type sequence]",
((auto Index, typename Expect, typename... T), Index, Expect, T...),
Expand Down

0 comments on commit 94cb4e4

Please sign in to comment.