Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56173 - in sandbox/explore: boost/explore libs/explore/test
From: jeff_at_[hidden]
Date: 2009-09-13 11:57:22


Author: jefffaust
Date: 2009-09-13 11:57:21 EDT (Sun, 13 Sep 2009)
New Revision: 56173
URL: http://svn.boost.org/trac/boost/changeset/56173

Log:
Reuse stream_normal_value for streaming pairs. Add more tests for item_width and quote_strings.
Text files modified:
   sandbox/explore/boost/explore/pair.hpp | 23 ++----
   sandbox/explore/libs/explore/test/quote_strings.cpp | 124 +++++++++++++++++++++++++++++++++++++++
   sandbox/explore/libs/explore/test/std_pair.cpp | 2
   3 files changed, 130 insertions(+), 19 deletions(-)

Modified: sandbox/explore/boost/explore/pair.hpp
==============================================================================
--- sandbox/explore/boost/explore/pair.hpp (original)
+++ sandbox/explore/boost/explore/pair.hpp 2009-09-13 11:57:21 EDT (Sun, 13 Sep 2009)
@@ -17,26 +17,19 @@
 namespace std
 {
     template<typename Elem, typename Tr, typename T1, typename T2>
- std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& ostr, const std::pair<T1, T2>& p)
+ basic_ostream<Elem, Tr>& operator<<(basic_ostream<Elem, Tr>& ostr, const pair<T1, T2>& p)
     {
         using namespace boost::explore;
 
- container_common_stream_state* common_state = get_stream_state<container_common_stream_state>(ostr);
         container_stream_state<Elem>* state = get_stream_state<container_stream_state<Elem> >(ostr);
-
- // set the level based on the current recursive depth
+ container_common_stream_state* common_state = get_stream_state<container_common_stream_state>(ostr);
         detail::increment_depth guard(common_state);
-
- basic_stringstream<Elem, Tr> sstream;
-
- { // redirect output to a string stream so we can correctly set width()
- detail::rdbuf_guard<Elem, Tr> guard(ostr);
- ostr.rdbuf(sstream.rdbuf());
- ostr << state->start() << p.first << state->separator() << p.second << state->end();
- }
-
- ostr.width(common_state->itemwidth());
- return ostr << sstream.str();
+ ostr << state->start();
+ stream_normal_value()(ostr, p.first, state, common_state);
+ ostr << state->separator();
+ stream_normal_value()(ostr, p.second, state, common_state);
+ ostr << state->end();
+ return ostr;
     }
 }
 

Modified: sandbox/explore/libs/explore/test/quote_strings.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/quote_strings.cpp (original)
+++ sandbox/explore/libs/explore/test/quote_strings.cpp 2009-09-13 11:57:21 EDT (Sun, 13 Sep 2009)
@@ -9,8 +9,9 @@
 
 #define BOOST_TEST_MODULE PrintLib
 #include <boost/test/unit_test.hpp>
-#include <boost/explore/map.hpp>
-#include <boost/explore/vector.hpp>
+#include <boost/explore.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/tuple/tuple_io.hpp>
 #include "boost_explore_test_tools.hpp"
 
 BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_map, C, test_types )
@@ -35,9 +36,18 @@
     BOOST_CHECK_EQUAL(output(str_out), "[1:\"first\", 2:\"second\"]");
     str_out << no_quote_strings << mis;
     BOOST_CHECK_EQUAL(output(str_out), "[1:\"first\", 2:\"second\"][1:first, 2:second]");
+
+ reset(str_out);
+
+ str_out << item_width(12) << mis;
+ BOOST_CHECK_EQUAL(output(str_out), "[ 1:first, 2:second]");
+
+ reset(str_out);
+ str_out << item_width(12) << quote_strings << mis;
+ BOOST_CHECK_EQUAL(output(str_out), "[ 1:\"first\", 2:\"second\"]");
 }
 
-BOOST_AUTO_TEST_CASE_TEMPLATE( strings_with_item_width, C, test_types )
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_vector, C, test_types )
 {
     using namespace boost::explore;
     typedef typename test_traits<C>::string_type string_type;
@@ -51,3 +61,111 @@
 
     BOOST_CHECK_EQUAL(output(str_out), "[ \"1234\", \"5678\"]");
 }
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_boost_array, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+ typename test_traits<C>::stream_type str_out;
+
+ boost::array<string_type, 2> as;
+ as[0] = str_to<C>("first");
+ as[1] = str_to<C>("second");
+
+ str_out << quote_strings << item_width(10) << as;
+ BOOST_CHECK_EQUAL(output(str_out), "[ \"first\", \"second\"]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_boost_range, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+ typename test_traits<C>::stream_type str_out;
+
+ std::vector<string_type> vs;
+
+ vs.push_back(str_to<C>("Hello"));
+ vs.push_back(str_to<C>("World"));
+
+ str_out << quote_strings << item_width(17) << make_iterator_range(vs);
+ BOOST_CHECK_EQUAL(output(str_out), "[ \"Hello\", \"World\"]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_tuple, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+ typename test_traits<C>::stream_type str_out;
+
+ boost::tuples::tuple<string_type, double> t(str_to<C>("Hello"), 3.14);
+ str_out << quote_strings << item_width(20) << t;
+ // I think things that already have a way to print should not change
+ //BOOST_CHECK_EQUAL(output(str_out), "[1, 3.14]");
+ BOOST_CHECK_EQUAL(output(str_out), "(Hello 3.14)");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_c_array, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+ typename test_traits<C>::stream_type str_out;
+
+ string_type arrs3[] = {str_to<C>("One"), str_to<C>("Two"), str_to<C>("Three")};
+ str_out << quote_strings << item_width(10) << arrs3;
+ BOOST_CHECK_EQUAL(output(str_out), "[ \"One\", \"Two\", \"Three\"]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_deque, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+
+ typename test_traits<C>::stream_type str_out;
+
+ std::deque<string_type> ds;
+ ds.push_back(str_to<C>("1234"));
+ ds.push_back(str_to<C>("5678"));
+ str_out << quote_strings << item_width(7) << ds;
+
+ BOOST_CHECK_EQUAL(output(str_out), "[ \"1234\", \"5678\"]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_list, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+
+ typename test_traits<C>::stream_type str_out;
+
+ std::list<string_type> ls;
+ ls.push_back(str_to<C>("1234"));
+ ls.push_back(str_to<C>("5678"));
+ str_out << quote_strings << item_width(7) << ls;
+
+ BOOST_CHECK_EQUAL(output(str_out), "[ \"1234\", \"5678\"]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_pair, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+ typename test_traits<C>::stream_type str_out;
+
+ std::pair<string_type, double> p(str_to<C>("Hello"), 3.14);
+ str_out << quote_strings << item_width(10) << p;
+ BOOST_CHECK_EQUAL(output(str_out), "[ \"Hello\", 3.14]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( strings_in_set, C, test_types )
+{
+ using namespace boost::explore;
+ typedef typename test_traits<C>::string_type string_type;
+ typename test_traits<C>::stream_type str_out;
+
+ std::set<string_type> ss;
+ ss.insert(str_to<C>("Hello"));
+ ss.insert(str_to<C>("World"));
+
+ str_out << quote_strings << item_width(10) << ss;
+ BOOST_CHECK_EQUAL(output(str_out), "[ \"Hello\", \"World\"]");
+}

Modified: sandbox/explore/libs/explore/test/std_pair.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_pair.cpp (original)
+++ sandbox/explore/libs/explore/test/std_pair.cpp 2009-09-13 11:57:21 EDT (Sun, 13 Sep 2009)
@@ -62,5 +62,5 @@
     pair<int,int> pi(3, 33);
 
     str_out << item_width(10) << pi;
- BOOST_CHECK_EQUAL(output(str_out), " [3, 33]");
+ BOOST_CHECK_EQUAL(output(str_out), "[ 3, 33]");
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk