Skip to content

Commit ddc5f3d

Browse files
committed
Merge branch 'standard-normal-form' into refref
2 parents 8a75835 + d52f8c5 commit ddc5f3d

File tree

9 files changed

+83
-34
lines changed

9 files changed

+83
-34
lines changed

src/Beman/Optional26/optional.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// src/Beman/Optional26/optional.cpp -*-C++-*-
1+
// src/Beman/Optional26/optional.cpp -*-C++-*-
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
#include <Beman/Optional26/optional.hpp>

src/Beman/Optional26/tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ target_sources(
2121
optional_ref_monadic.t.cpp
2222
optional_refref.t.cpp
2323
optional_refref_monadic.t.cpp
24-
test_types.cpp)
24+
test_types.cpp
25+
test_utilities.cpp)
2526

2627
target_link_libraries(
2728
beman_optional26_test

src/Beman/Optional26/tests/optional.t.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
#include <gtest/gtest.h>
1515

16-
TEST(OptionalTest, TestGTest) { ASSERT_EQ(1, 1); }
17-
1816
TEST(OptionalTest, Constructors) {
1917
beman::optional26::optional<int> i1;
2018
beman::optional26::optional<int> i2{beman::optional26::nullopt};

src/Beman/Optional26/tests/optional_constexpr.t.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
#include <Beman/Optional26/optional.hpp>
55
#include <Beman/Optional26/tests/test_types.hpp>
6+
#include <Beman/Optional26/tests/test_utilities.hpp>
67

78
#include <functional>
89
#include <ranges>
910
#include <tuple>
1011

1112
#include <gtest/gtest.h>
1213

13-
TEST(OptionalConstexprTest, TestGTest) { ASSERT_EQ(1, 1); }
14-
1514

1615
TEST(OptionalConstexprTest, Constructors) {
1716
constexpr beman::optional26::optional<int> i1;
@@ -220,7 +219,7 @@ consteval bool testConstexprInPlace() {
220219
return retval;
221220
}
222221

223-
auto consteval constify(auto expr) { return (expr); }
222+
using beman::optional26::tests::constify;
224223

225224
TEST(OptionalConstexprTest, InPlace) {
226225
EXPECT_TRUE(constify(testConstexprInPlace()));
@@ -268,11 +267,6 @@ TEST(OptionalConstexprTest, Nullopt) {
268267
EXPECT_TRUE(!std::is_default_constructible<beman::optional26::nullopt_t>::value);
269268
}
270269

271-
struct move_detector {
272-
move_detector() = default;
273-
move_detector(move_detector&& rhs) { rhs.been_moved = true; }
274-
bool been_moved = false;
275-
};
276270

277271
TEST(OptionalConstexprTest, Observers) {
278272
constexpr beman::optional26::optional<int> o1 = 42;
@@ -292,19 +286,6 @@ TEST(OptionalConstexprTest, Observers) {
292286

293287
}
294288

295-
namespace {
296-
class Point
297-
{
298-
int x_;
299-
int y_;
300-
public:
301-
constexpr Point() : x_(0), y_(0) {}
302-
constexpr Point(int x, int y) : x_(x), y_(y) {}
303-
auto operator<=>(const Point&) const = default;
304-
bool operator==(const Point&) const = default;
305-
};
306-
307-
}
308289
TEST(OptionalConstexprTest, RelationalOps) {
309290
constexpr beman::optional26::optional<int> o1{4};
310291
constexpr beman::optional26::optional<int> o2{42};
@@ -389,6 +370,8 @@ TEST(OptionalConstexprTest, RelationalOps) {
389370
}
390371
}
391372

373+
using beman::optional26::tests::Point;
374+
392375
constexpr Point p4{2, 3};
393376
constexpr Point p5{3, 4};
394377

@@ -796,6 +779,8 @@ consteval bool testComparisons() {
796779
}
797780
}
798781

782+
using beman::optional26::tests::Point;
783+
799784
constexpr Point p4{2, 3};
800785
constexpr Point p5{3, 4};
801786

src/Beman/Optional26/tests/optional_ref.t.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
#include <gtest/gtest.h>
88

9-
TEST(OptionalRefTest, TestGTest) { ASSERT_EQ(1, 1); }
10-
11-
129
TEST(OptionalRefTest, Constructors) {
1310
beman::optional26::optional<int&> i1;
1411
beman::optional26::optional<int&> i2{beman::optional26::nullopt};
@@ -405,12 +402,6 @@ TEST(OptionalRefTest, Nullopt) {
405402
EXPECT_TRUE(!std::is_default_constructible<beman::optional26::nullopt_t>::value);
406403
}
407404

408-
struct move_detector {
409-
move_detector() = default;
410-
move_detector(move_detector&& rhs) { rhs.been_moved = true; }
411-
bool been_moved = false;
412-
};
413-
414405
TEST(OptionalRefTest, Observers) {
415406
int var = 42;
416407
beman::optional26::optional<int&> o1 = var;
@@ -623,3 +614,38 @@ TEST(OptionalRefTest, AssignFromOptional) {
623614
// optional_base_const_ref = [](){return beman::optional26::optional<derived>(derived(3, 4));}();
624615
// TODO: Add to "fail-to-compile" tests when they exist
625616
}
617+
618+
TEST(OptionalRefTest, ConstructFromOptional) {
619+
int var = 42;
620+
beman::optional26::optional<int&> o1 = beman::optional26::nullopt;
621+
beman::optional26::optional<int&> o2{var};
622+
623+
624+
using beman::optional26::tests::base;
625+
using beman::optional26::tests::derived;
626+
627+
base b{1};
628+
derived d(1, 2);
629+
beman::optional26::optional<base&> empty_base;
630+
beman::optional26::optional<base&> engaged_base{b};
631+
632+
beman::optional26::optional<derived&> empty_derived_ref;
633+
beman::optional26::optional<derived&> engaged_derived_ref{d};
634+
635+
beman::optional26::optional<base&> optional_base_ref{empty_derived_ref};
636+
EXPECT_FALSE(optional_base_ref.has_value());
637+
638+
beman::optional26::optional<base&> optional_base_ref2{engaged_derived_ref};
639+
EXPECT_TRUE(optional_base_ref2.has_value());
640+
641+
beman::optional26::optional<derived> empty_derived;
642+
beman::optional26::optional<derived> engaged_derived{d};
643+
644+
static_assert(std::is_constructible_v<const base&, derived>);
645+
646+
beman::optional26::optional<const base&> optional_base_const_ref{empty_derived};
647+
EXPECT_FALSE(optional_base_const_ref.has_value());
648+
649+
beman::optional26::optional<const base&> optional_base_const_ref2{engaged_derived};
650+
EXPECT_TRUE(optional_base_const_ref2.has_value());
651+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// src/Beman/Optional26/test/test_types.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
14
#include <Beman/Optional26/tests/test_types.hpp>

src/Beman/Optional26/tests/test_types.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ struct derived : public base {
4949
auto operator<=>(const derived&) const = default;
5050
};
5151

52+
struct move_detector {
53+
move_detector() = default;
54+
move_detector(move_detector&& rhs) { rhs.been_moved = true; }
55+
bool been_moved = false;
56+
};
57+
58+
class Point {
59+
int x_;
60+
int y_;
61+
62+
public:
63+
constexpr Point() : x_(0), y_(0) {}
64+
constexpr Point(int x, int y) : x_(x), y_(y) {}
65+
auto operator<=>(const Point&) const = default;
66+
bool operator==(const Point&) const = default;
67+
};
68+
5269
} // namespace beman::optional26::tests
5370

5471
#endif // BEMAN_OPTIONAL26_TESTS_TEST_TYPES_HPP
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// src/Beman/Optional26/test/test_utilities.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <Beman/Optional26/tests/test_utilities.hpp>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// src/Beman/Optional26/tests/test_utilities.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef BEMAN_OPTIONAL26_TESTS_TEST_UTILITIES_HPP
5+
#define BEMAN_OPTIONAL26_TESTS_TEST_UTILITIES_HPP
6+
7+
namespace beman::optional26::tests {
8+
/***
9+
* Evaluate and return an expression in a consteval context for testing
10+
* constexpr correctness.
11+
*/
12+
auto consteval constify(auto expr) { return (expr); }
13+
} // namespace beman::optional26::tests
14+
15+
#endif

0 commit comments

Comments
 (0)