xref: /llvm-project/libcxx/test/std/strings/basic.string/string.nonmembers/string.io/get_line.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 "min_allocator.h"
21 
22 int main()
23 {
24     {
25         std::istringstream in(" abc\n  def\n   ghij");
26         std::string s("initial text");
27         getline(in, s);
28         assert(in.good());
29         assert(s == " abc");
30         getline(in, s);
31         assert(in.good());
32         assert(s == "  def");
33         getline(in, s);
34         assert(in.eof());
35         assert(s == "   ghij");
36     }
37     {
38         std::wistringstream in(L" abc\n  def\n   ghij");
39         std::wstring s(L"initial text");
40         getline(in, s);
41         assert(in.good());
42         assert(s == L" abc");
43         getline(in, s);
44         assert(in.good());
45         assert(s == L"  def");
46         getline(in, s);
47         assert(in.eof());
48         assert(s == L"   ghij");
49     }
50 #if TEST_STD_VER >= 11
51     {
52         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
53         std::istringstream in(" abc\n  def\n   ghij");
54         S s("initial text");
55         getline(in, s);
56         assert(in.good());
57         assert(s == " abc");
58         getline(in, s);
59         assert(in.good());
60         assert(s == "  def");
61         getline(in, s);
62         assert(in.eof());
63         assert(s == "   ghij");
64     }
65     {
66         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
67         std::wistringstream in(L" abc\n  def\n   ghij");
68         S s(L"initial text");
69         getline(in, s);
70         assert(in.good());
71         assert(s == L" abc");
72         getline(in, s);
73         assert(in.good());
74         assert(s == L"  def");
75         getline(in, s);
76         assert(in.eof());
77         assert(s == L"   ghij");
78     }
79 #endif
80 }
81