Skip to content

Commit da4329e

Browse files
committed
Add dangling iterator test for sorter_facade
1 parent 2f0c857 commit da4329e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ add_executable(main-tests
106106
rebind_iterator_category.cpp
107107
sorter_facade.cpp
108108
sorter_facade_constexpr.cpp
109+
sorter_facade_dangling_return.cpp
109110
sorter_facade_defaults.cpp
110111
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:sorter_facade_fptr.cpp>
111112
sorter_facade_range.cpp
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2024 Morwenn
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
#include <concepts>
6+
#include <functional>
7+
#include <ranges>
8+
#include <vector>
9+
#include <catch2/catch_test_macros.hpp>
10+
#include <cpp-sort/sorters/heap_sorter.h>
11+
12+
TEST_CASE( "sorter_facade returning dangling for rvalue ranges",
13+
"[sorter_facade][comparison][projection]" )
14+
{
15+
SECTION( "range" )
16+
{
17+
auto it = cppsort::heap_sort(std::vector<int>{3, 2, 1});
18+
STATIC_CHECK( std::same_as<decltype(it), std::ranges::dangling> );
19+
}
20+
21+
SECTION( "range and comparison" )
22+
{
23+
auto it = cppsort::heap_sort(std::vector<int>{3, 2, 1}, std::greater{});
24+
STATIC_CHECK( std::same_as<decltype(it), std::ranges::dangling> );
25+
}
26+
27+
SECTION( "range and projection" )
28+
{
29+
auto it = cppsort::heap_sort(std::vector<int>{3, 2, 1}, std::negate{});
30+
STATIC_CHECK( std::same_as<decltype(it), std::ranges::dangling> );
31+
}
32+
33+
SECTION( "range, comparison and projection" )
34+
{
35+
auto it = cppsort::heap_sort(std::vector<int>{3, 2, 1}, std::greater{}, std::negate{});
36+
STATIC_CHECK( std::same_as<decltype(it), std::ranges::dangling> );
37+
}
38+
}

0 commit comments

Comments
 (0)