istream_iterator_basic.cpp 1.6 KB

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