Skip to content

Commit 169652c

Browse files
committed
Improve variant tests. Now we can be more confident that when using the index + value constructor, index() and v[index] will return the correct values. Move those tests before other more complicated tests.
1 parent ee4c4b9 commit 169652c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

source/tv/test/variant.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ static_assert(bounded::constructible_from<thing_t, short>);
4040
static_assert(bounded::constructible_from<thing_t, long>);
4141
static_assert(bounded::constructible_from<thing_t, char>);
4242

43+
constexpr auto check_index_and_value(auto const index, auto const value) -> bool {
44+
auto const v = thing_t(index, value);
45+
BOUNDED_ASSERT(v.index() == index);
46+
auto const stored = v[index];
47+
static_assert(std::same_as<decltype(stored), decltype(value)>);
48+
BOUNDED_ASSERT(stored == value);
49+
return true;
50+
}
51+
52+
static_assert(check_index_and_value(0_bi, 7));
53+
static_assert(check_index_and_value(1_bi, short(7)));
54+
static_assert(check_index_and_value(2_bi, 7L));
55+
static_assert(check_index_and_value(3_bi, 'A'));
56+
static_assert(check_index_and_value(4_bi, 7));
57+
4358
static_assert(thing_t(0_bi, 0) == thing_t(0_bi, 0));
4459
static_assert(thing_t(0_bi, 0) != thing_t(0_bi, 1));
4560
static_assert(thing_t(0_bi, 0) != thing_t(1_bi, static_cast<short>(0)));
@@ -48,22 +63,9 @@ static_assert(thing_t(0_bi, 0) != thing_t(4_bi, 1));
4863

4964
static_assert(thing_t(1_bi, static_cast<short>(5)) == thing_t(static_cast<short>(5)));
5065

51-
static_assert(thing_t(0_bi, 0).index() == 0_bi);
52-
static_assert(thing_t(1_bi, static_cast<short>(0)).index() == 1_bi);
53-
static_assert(thing_t(2_bi, 0).index() == 2_bi);
54-
static_assert(thing_t(3_bi, '\0').index() == 3_bi);
55-
static_assert(thing_t(4_bi, 0).index() == 4_bi);
56-
5766
constexpr auto index = 1_bi;
5867
constexpr auto value = static_cast<short>(8);
5968

60-
constexpr auto thing = thing_t(index, value);
61-
using thingy = decltype(thing[index]);
62-
63-
static_assert(std::same_as<thingy, short const &>);
64-
65-
static_assert(thing[index] == value);
66-
6769
constexpr auto test_assignment_from_variant() {
6870
auto thing1 = thing_t(index, value);
6971
thing1 = thing_t(index, value);

0 commit comments

Comments
 (0)