| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <string> |
| 10 | |
| 11 | // template<class charT, class traits, class Allocator> |
| 12 | // basic_istream<charT,traits>& |
| 13 | // getline(basic_istream<charT,traits>&& is, |
| 14 | // basic_string<charT,traits,Allocator>& str); |
| 15 | |
| 16 | #include <string> |
| 17 | #include <sstream> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | #include "min_allocator.h" |
| 22 | |
| 23 | template <template <class> class Alloc> |
| 24 | void test() { |
| 25 | { |
| 26 | using S = std::basic_string<char, std::char_traits<char>, Alloc<char> >; |
| 27 | S s("initial text" ); |
| 28 | std::getline(std::istringstream(" abc\n def\n ghij" ), s); |
| 29 | assert(s == " abc" ); |
| 30 | } |
| 31 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 32 | { |
| 33 | using WS = std::basic_string<wchar_t, std::char_traits<wchar_t>, Alloc<wchar_t> >; |
| 34 | WS s(L"initial text" ); |
| 35 | std::getline(std::wistringstream(L" abc\n def\n ghij" ), s); |
| 36 | assert(s == L" abc" ); |
| 37 | } |
| 38 | #endif |
| 39 | } |
| 40 | |
| 41 | int main(int, char**) { |
| 42 | test<std::allocator>(); |
| 43 | test<min_allocator>(); |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |