1// Copyright (c) 2016 Jeffrey E. Trull
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6// A series of simple tests for the istream_iterator
7
8#include <boost/spirit/include/support_istream_iterator.hpp>
9
10#include <boost/core/lightweight_test.hpp>
11#include <sstream>
12
13int main()
14{
15 std::stringstream ss("HELO\n");
16 boost::spirit::istream_iterator it(ss);
17
18 // Check iterator concepts
19 boost::spirit::istream_iterator it2(it); // CopyConstructible
20 BOOST_TEST( it2 == it ); // EqualityComparable
21 BOOST_TEST( *it2 == 'H' );
22
23 boost::spirit::istream_iterator end; // DefaultConstructible
24 BOOST_TEST( it != end );
25 it = end; // CopyAssignable
26 BOOST_TEST( it == end );
27
28 std::swap(a&: it, b&: it2); // Swappable
29 BOOST_TEST( it2 == end );
30 BOOST_TEST( *it == 'H' );
31
32 ++it;
33 BOOST_TEST( *it == 'E' );
34 BOOST_TEST( *it++ == 'E' );
35
36 // "Incrementing a copy of a does not change the value read from a"
37 boost::spirit::istream_iterator it3 = it;
38 BOOST_TEST( *it == 'L' );
39 BOOST_TEST( *it3 == 'L' );
40 ++it;
41 BOOST_TEST( *it == 'O' );
42 BOOST_TEST( *it3 == 'L' );
43
44 it3 = it;
45 // "a == b implies ++a == ++b"
46 BOOST_TEST( ++it3 == ++it );
47
48 // Usage of const iterators
49 boost::spirit::istream_iterator const itc = it;
50 BOOST_TEST( itc == it );
51 BOOST_TEST( *itc == *it );
52 ++it;
53 BOOST_TEST( itc != it );
54
55 // Skipping le/gt comparisons as unclear what they are for in forward iterators...
56
57 return boost::report_errors();
58}
59// Destructible
60

source code of boost/libs/spirit/test/support/istream_iterator_basic.cpp