Skip to content

Commit 15db35a

Browse files
committed
Tests: WIP span.pass and span.span.pass
1 parent 7950812 commit 15db35a

File tree

4 files changed

+107
-43
lines changed

4 files changed

+107
-43
lines changed

libcxx/include/spanstream

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@
6666
#include <__utility/move.h>
6767
#include <__utility/swap.h>
6868
#include <iostream>
69-
// #include <print>
7069
#include <span>
7170
#include <streambuf>
7271
#include <version>
7372

73+
// #include <print>
74+
7475
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
7576
# pragma GCC system_header
7677
#endif
@@ -98,11 +99,11 @@ public:
9899
_LIBCPP_HIDE_FROM_ABI basic_spanbuf() : basic_spanbuf(ios_base::in | ios_base::out) {}
99100

100101
_LIBCPP_HIDE_FROM_ABI explicit basic_spanbuf(ios_base::openmode __which)
101-
: basic_spanbuf(std::span<_CharT>(), __which) {}
102+
: basic_streambuf<_CharT, _Traits>{}, __mode_{__which} {}
102103

103104
_LIBCPP_HIDE_FROM_ABI explicit basic_spanbuf(std::span<_CharT> __s,
104105
ios_base::openmode __which = ios_base::in | ios_base::out)
105-
: basic_streambuf<_CharT, _Traits>{}, __mode_{__which}, __buf_{__s} {
106+
: basic_streambuf<_CharT, _Traits>{}, __mode_{__which} {
106107
this->span(__s);
107108
}
108109

@@ -267,14 +268,8 @@ public:
267268
requires(!convertible_to<_ROSeq, std::span<_CharT>>) && convertible_to<_ROSeq, std::span<const _CharT>>
268269
_LIBCPP_HIDE_FROM_ABI explicit basic_ispanstream(_ROSeq&& __s)
269270
: basic_istream<_CharT, _Traits>(std::addressof(__sb_)) {
270-
// std::println(stderr, "ispanstream");
271271
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");
275272
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");
278273
}
279274

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

libcxx/test/std/input.output/span.streams/helper_types.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "test_macros.h"
1818

19-
// #include <print>
19+
// ROS types
2020

2121
template <typename CharT, std::size_t N = 0>
2222
class ReadOnlySpan {
@@ -25,19 +25,10 @@ class ReadOnlySpan {
2525

2626
operator std::span<CharT>() = delete;
2727

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

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-
}
30+
const CharT* begin() { return arr_; }
31+
const CharT* end() { return arr_ + N; }
4132

4233
private:
4334
CharT* arr_;
@@ -46,6 +37,8 @@ class ReadOnlySpan {
4637
template <typename CharT, std::size_t N>
4738
inline constexpr bool std::ranges::enable_borrowed_range<ReadOnlySpan<CharT, N>> = true;
4839

40+
// Constraints: Constructors [ispanstream.cons]
41+
4942
static_assert(std::ranges::borrowed_range<ReadOnlySpan<char>>);
5043

5144
static_assert(!std::constructible_from<std::span<char>, ReadOnlySpan<char>>);
@@ -96,6 +89,8 @@ class NonReadOnlySpan {
9689
template <typename CharT, std::size_t N>
9790
inline constexpr bool std::ranges::enable_borrowed_range<NonReadOnlySpan<CharT, N>> = true;
9891

92+
// Constraints: Constructors [ispanstream.cons]
93+
9994
static_assert(std::ranges::borrowed_range<NonReadOnlySpan<char>>);
10095

10196
static_assert(std::constructible_from<std::span<char>, NonReadOnlySpan<char>>);
@@ -126,7 +121,7 @@ static_assert(!std::constructible_from<std::span<const wchar_t>, const NonReadOn
126121
static_assert(!std::convertible_to<const NonReadOnlySpan<wchar_t>, std::span<const wchar_t>>);
127122
#endif
128123

129-
struct SomeObject {};
124+
// Mode types
130125

131126
struct NonMode {};
132127

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,17 @@ void test() {
3131
using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
3232

3333
CharT arr[4];
34-
std::span<CharT> sp{arr};
35-
36-
// TODO:
3734

38-
// Mode: default
35+
std::span<CharT> sp{arr};
36+
assert(sp.data() == arr);
37+
assert(!sp.empty());
38+
assert(sp.size() == 4);
39+
3940
{
40-
SpBuf rhsSpBuf{sp};
41-
SpBuf spBuf(std::span<CharT>{});
42-
spBuf.swap(rhsSpBuf);
43-
// assert(spBuf.span().data() == arr);
44-
// assert(!spBuf.span().empty());
45-
// assert(spBuf.span().size() == 4);
46-
}
41+
SpBuf spBuf(sp);
42+
assert(spBuf.span().data() == arr);
43+
assert(!spBuf.span().empty());
44+
assert(spBuf.span().size() == 4);
4745
}
4846

4947
int main(int, char**) {

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

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,94 @@ void test() {
3232
using SpBuf = std::basic_spanbuf<CharT, TraitsT>;
3333

3434
CharT arr[4];
35-
std::span<CharT> sp{arr};
3635

37-
// TODO:
36+
// Mode: default (`in` | `out`)
37+
{
38+
SpBuf spBuf;
39+
assert(spBuf.span().data() == nullptr);
40+
assert(spBuf.span().empty());
41+
assert(spBuf.span().size() == 0);
42+
43+
spBuf.span(arr);
44+
assert(spBuf.span().data() == arr);
45+
// Mode `out` counts read characters
46+
assert(spBuf.span().empty());
47+
assert(spBuf.span().size() == 0);
48+
}
49+
{
50+
SpBuf spBuf;
51+
assert(spBuf.span().data() == nullptr);
52+
assert(spBuf.span().empty());
53+
assert(spBuf.span().size() == 0);
54+
55+
std::span<CharT> sp{arr};
56+
assert(sp.data() == arr);
57+
assert(!sp.empty());
58+
assert(sp.size() == 4);
59+
60+
spBuf.span(sp);
61+
assert(spBuf.span().data() == arr);
62+
// Mode `out` counts read characters
63+
assert(spBuf.span().empty());
64+
assert(spBuf.span().size() == 0);
65+
}
66+
// Mode: `in`
67+
{
68+
SpBuf spBuf{std::ios_base::in};
69+
assert(spBuf.span().data() == nullptr);
70+
assert(spBuf.span().empty());
71+
assert(spBuf.span().size() == 0);
72+
73+
spBuf.span(arr);
74+
assert(spBuf.span().data() == arr);
75+
assert(!spBuf.span().empty());
76+
assert(spBuf.span().size() == 4);
77+
}
78+
{
79+
SpBuf spBuf{std::ios_base::in};
80+
assert(spBuf.span().data() == nullptr);
81+
assert(spBuf.span().empty());
82+
assert(spBuf.span().size() == 0);
83+
84+
std::span<CharT> sp{arr};
85+
assert(sp.data() == arr);
86+
assert(!sp.empty());
87+
assert(sp.size() == 4);
3888

39-
// Mode: default
89+
spBuf.span(sp);
90+
assert(spBuf.span().data() == arr);
91+
assert(!spBuf.span().empty());
92+
assert(spBuf.span().size() == 4);
93+
}
94+
// Mode: `out`
4095
{
41-
SpBuf rhsSpBuf{sp};
42-
SpBuf spBuf(std::span<CharT>{});
43-
spBuf.swap(rhsSpBuf);
44-
// assert(spBuf.span().data() == arr);
45-
// assert(!spBuf.span().empty());
46-
// assert(spBuf.span().size() == 4);
96+
SpBuf spBuf{std::ios_base::out};
97+
assert(spBuf.span().data() == nullptr);
98+
assert(spBuf.span().empty());
99+
assert(spBuf.span().size() == 0);
100+
101+
spBuf.span(arr);
102+
assert(spBuf.span().data() == arr);
103+
// Mode `out` counts read characters
104+
assert(spBuf.span().empty());
105+
assert(spBuf.span().size() == 0);
106+
}
107+
{
108+
SpBuf spBuf{std::ios_base::out};
109+
assert(spBuf.span().data() == nullptr);
110+
assert(spBuf.span().empty());
111+
assert(spBuf.span().size() == 0);
112+
113+
std::span<CharT> sp{arr};
114+
assert(sp.data() == arr);
115+
assert(!sp.empty());
116+
assert(sp.size() == 4);
117+
118+
spBuf.span(sp);
119+
assert(spBuf.span().data() == arr);
120+
// Mode `out` counts read characters
121+
assert(spBuf.span().empty());
122+
assert(spBuf.span().size() == 0);
47123
}
48124
}
49125

0 commit comments

Comments
 (0)