Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / input.streams / istream.unformatted / ignore.pass.cpp
blobe313ddc5b97c19ea4549e4a3c7a88295554c56d2
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 //===----------------------------------------------------------------------===//
9 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
11 // <istream>
13 // basic_istream<charT,traits>&
14 // ignore(streamsize n = 1, int_type delim = traits::eof());
16 #include <istream>
17 #include <cassert>
19 #include "test_macros.h"
21 template <class CharT>
22 struct testbuf
23 : public std::basic_streambuf<CharT>
25 typedef std::basic_string<CharT> string_type;
26 typedef std::basic_streambuf<CharT> base;
27 private:
28 string_type str_;
29 public:
31 testbuf() {}
32 testbuf(const string_type& str)
33 : str_(str)
35 base::setg(const_cast<CharT*>(str_.data()),
36 const_cast<CharT*>(str_.data()),
37 const_cast<CharT*>(str_.data()) + str_.size());
40 CharT* eback() const {return base::eback();}
41 CharT* gptr() const {return base::gptr();}
42 CharT* egptr() const {return base::egptr();}
45 int main(int, char**)
48 testbuf<char> sb(" 1\n2345\n6");
49 std::istream is(&sb);
50 is.ignore();
51 assert(!is.eof());
52 assert(!is.fail());
53 assert(is.gcount() == 1);
54 is.ignore(5, '\n');
55 assert(!is.eof());
56 assert(!is.fail());
57 assert(is.gcount() == 2);
58 is.ignore(15);
59 assert( is.eof());
60 assert(!is.fail());
61 assert(is.gcount() == 6);
63 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
65 testbuf<wchar_t> sb(L" 1\n2345\n6");
66 std::wistream is(&sb);
67 is.ignore();
68 assert(!is.eof());
69 assert(!is.fail());
70 assert(is.gcount() == 1);
71 is.ignore(5, '\n');
72 assert(!is.eof());
73 assert(!is.fail());
74 assert(is.gcount() == 2);
75 is.ignore(15);
76 assert( is.eof());
77 assert(!is.fail());
78 assert(is.gcount() == 6);
80 #endif
81 #ifndef TEST_HAS_NO_EXCEPTIONS
83 testbuf<char> sb(" ");
84 std::basic_istream<char> is(&sb);
85 is.exceptions(std::ios_base::eofbit);
86 bool threw = false;
87 try {
88 is.ignore(5);
89 } catch (std::ios_base::failure&) {
90 threw = true;
92 assert(threw);
93 assert(!is.bad());
94 assert( is.eof());
95 assert(!is.fail());
97 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
99 testbuf<wchar_t> sb(L" ");
100 std::basic_istream<wchar_t> is(&sb);
101 is.exceptions(std::ios_base::eofbit);
102 bool threw = false;
103 try {
104 is.ignore(5);
105 } catch (std::ios_base::failure&) {
106 threw = true;
108 assert(threw);
109 assert(!is.bad());
110 assert( is.eof());
111 assert(!is.fail());
113 #endif
114 #endif // TEST_HAS_NO_EXCEPTIONS
116 return 0;