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/detail/lightweight_test.hpp> 9 10 #include <sstream> 11 12 #include <boost/spirit/include/support_istream_iterator.hpp> 13 main()14int main() 15 { 16 std::stringstream ss("HELO\n"); 17 boost::spirit::istream_iterator it(ss); 18 19 // Check iterator concepts 20 boost::spirit::istream_iterator it2(it); // CopyConstructible 21 BOOST_TEST( it2 == it ); // EqualityComparable 22 BOOST_TEST( *it2 == 'H' ); 23 24 boost::spirit::istream_iterator end; // DefaultConstructible 25 BOOST_TEST( it != end ); 26 it = end; // CopyAssignable 27 BOOST_TEST( it == end ); 28 29 std::swap(it, it2); // Swappable 30 BOOST_TEST( it2 == end ); 31 BOOST_TEST( *it == 'H' ); 32 33 ++it; 34 BOOST_TEST( *it == 'E' ); 35 BOOST_TEST( *it++ == 'E' ); 36 37 // "Incrementing a copy of a does not change the value read from a" 38 boost::spirit::istream_iterator it3 = it; 39 BOOST_TEST( *it == 'L' ); 40 BOOST_TEST( *it3 == 'L' ); 41 ++it; 42 BOOST_TEST( *it == 'O' ); 43 BOOST_TEST( *it3 == 'L' ); 44 45 it3 = it; 46 // "a == b implies ++a == ++b" 47 BOOST_TEST( ++it3 == ++it ); 48 49 // Usage of const iterators 50 boost::spirit::istream_iterator const itc = it; 51 BOOST_TEST( itc == it ); 52 BOOST_TEST( *itc == *it ); 53 ++it; 54 BOOST_TEST( itc != it ); 55 56 // Skipping le/gt comparisons as unclear what they are for in forward iterators... 57 58 return boost::report_errors(); 59 } 60 // Destructible 61