Skip to content

Commit 68605d4

Browse files
committed
Tests: updated inherited.stream.ops.pass.cpp
1 parent 08e016b commit 68605d4

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

libcxx/include/spanstream

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public:
418418

419419
// [spanstream.swap], swap
420420

421-
void swap(basic_spanstream& __rhs) {
421+
_LIBCPP_HIDE_FROM_ABI void swap(basic_spanstream& __rhs) {
422422
basic_iostream<_CharT, _Traits>::swap(__rhs);
423423
__sb_.swap(__rhs.__sb_);
424424
}

libcxx/test/std/input.output/span.streams/spanstream/inherited.stream.ops.pass.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ template <typename CharT, typename TraitsT = std::char_traits<CharT>>
3838
void test() {
3939
using SpStream = std::basic_spanstream<CharT, TraitsT>;
4040

41+
constexpr auto arrSize{30UZ};
42+
4143
constexpr std::basic_string_view<CharT, TraitsT> sv{SV("zmt 94 hkt 82 pir 43vr")};
42-
CharT arr[sv.size() + 1];
44+
assert(sv.size() < arrSize);
45+
46+
CharT arr[arrSize]{};
4347
initialize_array(arr, sv);
48+
4449
std::span<CharT> sp{arr};
4550

4651
// Mode: default (`in` | `out`)
4752
{
4853
SpStream spSt(sp);
54+
assert(spSt.span().size() == 0);
55+
56+
// Read from stream
4957
std::basic_string<CharT, TraitsT> str1;
5058
spSt >> str1;
5159
int i1;
@@ -66,7 +74,12 @@ void test() {
6674
assert(str3 == CS("pir"));
6775
assert(i3 == 43);
6876

69-
spSt << CS("year 2024");
77+
// Write to stream
78+
constexpr std::basic_string_view<CharT, TraitsT> sv1{SV("year 2024")};
79+
spSt << sv1;
80+
assert(spSt.span().size() == sv1.size());
81+
82+
// Read from stream
7083
spSt.seekg(0);
7184
std::basic_string<CharT, TraitsT> str4;
7285
spSt >> str4;
@@ -75,6 +88,18 @@ void test() {
7588

7689
assert(str4 == CS("year"));
7790
assert(i4 == 2024);
91+
92+
// Write to stream
93+
spSt << CS("94");
94+
spSt << 84;
95+
std::cout << spSt.span().size() << std::endl;
96+
assert(spSt.span().size() == sv1.size() + 4);
97+
98+
// Write to stream with overflow
99+
constexpr std::basic_string_view<CharT, TraitsT> sv2{
100+
SV("This string should overflow! This string should overflow!")};
101+
spSt << sv2;
102+
assert(spSt.span().size() == arrSize);
78103
}
79104
// Mode: `in`
80105
{

0 commit comments

Comments
 (0)