Skip to content

Commit cdce763

Browse files
committed
Tests: WIP ROS constructor
1 parent 817c90e commit cdce763

File tree

10 files changed

+93
-18
lines changed

10 files changed

+93
-18
lines changed

libcxx/include/spanstream

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <__utility/move.h>
6767
#include <__utility/swap.h>
6868
#include <iostream>
69+
#include <print>
6970
#include <span>
7071
#include <streambuf>
7172
#include <version>
@@ -266,8 +267,14 @@ public:
266267
requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
267268
_LIBCPP_HIDE_FROM_ABI explicit basic_ispanstream(_ROSeq&& __s)
268269
: basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
270+
std::println(stderr, "ispanstream");
269271
std::span<const _CharT> __sp(std::forward<_ROSeq>(__s));
272+
std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
273+
std::println(stderr, "span data {} {}", __sp.empty(), __sp.size());
274+
std::println(stderr, "ispanstream 2");
270275
this->span(std::span<_CharT>(std::span<_CharT>(const_cast<_CharT*>(__sp.data()), __sp.size())));
276+
std::println(stderr, "span __sb_ {} {}", __sb_.span().empty(), __sb_.span().size());
277+
std::println(stderr, "ispanstream 3");
271278
}
272279

273280
basic_ispanstream& operator=(const basic_ispanstream&) = delete;

libcxx/test/std/input.output/span.streams/types.h renamed to libcxx/test/std/input.output/span.streams/helper_types.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,28 @@
1616

1717
#include "test_macros.h"
1818

19+
#include <print>
20+
1921
template <typename CharT, std::size_t N = 0>
2022
class ReadOnlySpan {
23+
public:
2124
explicit ReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
2225

23-
public:
2426
operator std::span<CharT>() = delete;
2527

26-
operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; }
28+
operator std::span<const CharT>() {
29+
std::println(stderr, "----> ROspan");
30+
return std::span<const CharT, N>{arr_};
31+
}
2732

28-
const CharT* begin() { return arr_; }
29-
const CharT* end() { return arr_ + N; }
33+
const CharT* begin() {
34+
std::println(stderr, "----> ROspan begin");
35+
return arr_;
36+
}
37+
const CharT* end() {
38+
std::println(stderr, "----> ROspan end");
39+
return arr_ + N;
40+
}
3041

3142
private:
3243
CharT* arr_;
@@ -68,9 +79,9 @@ static_assert(!std::convertible_to<const ReadOnlySpan<wchar_t>, std::span<const
6879

6980
template <typename CharT, std::size_t N = 0>
7081
class NonReadOnlySpan {
82+
public:
7183
explicit NonReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {}
7284

73-
public:
7485
operator std::span<CharT>() { return std::span<CharT, N>{arr_}; }
7586

7687
operator std::span<const CharT>() = delete;

libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/ros.pass.cpp

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,92 @@
1919
// template<class ROS> explicit basic_ispanstream(ROS&& s);
2020

2121
#include <cassert>
22+
#include <concepts>
2223
#include <spanstream>
2324

2425
#include "constexpr_char_traits.h"
2526
#include "nasty_string.h"
27+
#include "test_convertible.h"
2628
#include "test_macros.h"
2729

28-
#include "../../types.h"
30+
#include "../../helper_types.h"
2931

3032
#ifndef TEST_HAS_NO_NASTY_STRING
3133
void test_sfinae_with_nasty_char() {
3234
using SpStream = std::basic_ispanstream<nasty_char, nasty_char_traits>;
3335

34-
// TODO:
36+
// Non-const convertible
37+
static_assert(std::constructible_from<SpStream, ReadOnlySpan<nasty_char>>);
38+
static_assert(!test_convertible<SpStream, ReadOnlySpan<nasty_char>>());
39+
40+
// Const convertible
41+
static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<nasty_char>>);
42+
static_assert(!test_convertible<SpStream, const ReadOnlySpan<nasty_char>>());
43+
44+
// Non-const non-convertible
45+
static_assert(std::constructible_from<SpStream, ReadOnlySpan<nasty_char>>);
46+
static_assert(!test_convertible<SpStream, ReadOnlySpan<nasty_char>>());
47+
48+
// Const non-convertible
49+
static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<nasty_char>>);
50+
static_assert(!test_convertible<SpStream, const ReadOnlySpan<nasty_char>>());
3551
}
3652
#endif // TEST_HAS_NO_NASTY_STRING
3753

3854
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
3955
void test_sfinae() {
40-
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
56+
using SpStream =
57+
std::conditional_t<std::same_as<CharT, nasty_char>,
58+
std::basic_ispanstream<nasty_char, nasty_char_traits>,
59+
std::basic_ispanstream<CharT, TraitsT>>;
4160

42-
// TODO:
61+
// Non-const convertible
62+
static_assert(std::constructible_from<SpStream, ReadOnlySpan<CharT>>);
63+
static_assert(!test_convertible<SpStream, ReadOnlySpan<CharT>>());
64+
65+
// Const convertible
66+
static_assert(!std::constructible_from<SpStream, const ReadOnlySpan<CharT>>);
67+
static_assert(!test_convertible<SpStream, const ReadOnlySpan<CharT>>());
68+
69+
// Non-const non-convertible
70+
static_assert(std::constructible_from<SpStream, NonReadOnlySpan<CharT>>);
71+
static_assert(!test_convertible<SpStream, NonReadOnlySpan<CharT>>());
72+
73+
// Const non-convertible
74+
static_assert(!std::constructible_from<SpStream, const NonReadOnlySpan<CharT>>);
75+
static_assert(!test_convertible<SpStream, const NonReadOnlySpan<CharT>>());
4376
}
4477

4578
template <typename CharT, typename TraitsT = std::char_traits<CharT>>
4679
void test() {
4780
using SpStream = std::basic_ispanstream<CharT, TraitsT>;
4881

4982
// TODO:
83+
CharT arr[4];
84+
ReadOnlySpan<CharT, 4> ros{arr};
85+
86+
{
87+
SpStream spSt(ros);
88+
assert(spSt.span().data() == arr);
89+
assert(spSt.span().empty());
90+
assert(spSt.span().size() == 0);
91+
}
92+
93+
CharT arr1[6];
94+
ReadOnlySpan<CharT, 6> ros2{arr1};
95+
96+
{
97+
SpStream spSt(ros2);
98+
assert(spSt.span().data() == arr);
99+
assert(spSt.span().data() == arr1);
100+
assert(spSt.span().empty());
101+
assert(spSt.span().size() == 0);
102+
}
50103
}
51104

52105
int main(int, char**) {
53106
#ifndef TEST_HAS_NO_NASTY_STRING
107+
// test_sfinae<nasty_char, nasty_char_traits>();
54108
test_sfinae_with_nasty_char();
55109
#endif
56110
test_sfinae<char>();

libcxx/test/std/input.output/span.streams/ispanstream/ispanstream.cons/span.mode.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "test_convertible.h"
3131
#include "test_macros.h"
3232

33-
#include "../../macros.h"
34-
#include "../../types.h"
33+
#include "../../helper_macros.h"
34+
#include "../../helper_types.h"
3535

3636
#ifndef TEST_HAS_NO_NASTY_STRING
3737
void test_sfinae_with_nasty_char() {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# All non-trivial uses of iostreams require localization support
2+
if "no-localization" in config.available_features:
3+
config.unsupported = True

libcxx/test/std/input.output/span.streams/ospanstream/ospanstream.cons/span.mode.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "test_convertible.h"
3131
#include "test_macros.h"
3232

33-
#include "../../macros.h"
34-
#include "../../types.h"
33+
#include "../../helper_macros.h"
34+
#include "../../helper_types.h"
3535

3636
#ifndef TEST_HAS_NO_NASTY_STRING
3737
void test_sfinae_with_nasty_char() {

libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/mode.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "test_convertible.h"
2929
#include "test_macros.h"
3030

31-
#include "../../types.h"
31+
#include "../../helper_types.h"
3232

3333
#ifndef TEST_HAS_NO_NASTY_STRING
3434
void test_sfinae_with_nasty_char() {

libcxx/test/std/input.output/span.streams/spanbuf/spanbuf.cons/span.mode.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "test_convertible.h"
3131
#include "test_macros.h"
3232

33-
#include "../../macros.h"
34-
#include "../../types.h"
33+
#include "../../helper_macros.h"
34+
#include "../../helper_types.h"
3535

3636
#ifndef TEST_HAS_NO_NASTY_STRING
3737
void test_sfinae_with_nasty_char() {

libcxx/test/std/input.output/span.streams/spanstream/spanstream.cons/span.mode.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "test_convertible.h"
3131
#include "test_macros.h"
3232

33-
#include "../../macros.h"
34-
#include "../../types.h"
33+
#include "../../helper_macros.h"
34+
#include "../../helper_types.h"
3535

3636
#ifndef TEST_HAS_NO_NASTY_STRING
3737
void test_sfinae_with_nasty_char() {

0 commit comments

Comments
 (0)