Boost logo

Boost-Commit :

From: jared_at_[hidden]
Date: 2007-05-27 01:59:24


Author: jared
Date: 2007-05-27 01:59:23 EDT (Sun, 27 May 2007)
New Revision: 4303
URL: http://svn.boost.org/trac/boost/changeset/4303

Log:
Added custom format tester for print.

Added:
   sandbox/explore/libs/explore/test/basic_lg_format.hpp
   sandbox/explore/libs/explore/test/custom_format_simple.cpp
Text files modified:
   sandbox/explore/libs/explore/test/Jamfile.v2 | 2 +
   sandbox/explore/libs/explore/test/std_vector.cpp | 57 +++++++++++++++++++++------------------
   2 files changed, 33 insertions(+), 26 deletions(-)

Modified: sandbox/explore/libs/explore/test/Jamfile.v2
==============================================================================
--- sandbox/explore/libs/explore/test/Jamfile.v2 (original)
+++ sandbox/explore/libs/explore/test/Jamfile.v2 2007-05-27 01:59:23 EDT (Sun, 27 May 2007)
@@ -36,5 +36,7 @@
   
   # conflicts with stream operator already defined for iterator_range
   #[ run boost_range.cpp ]
+
+ [ run custom_format_simple.cpp ]
  ;
 }

Added: sandbox/explore/libs/explore/test/basic_lg_format.hpp
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/basic_lg_format.hpp 2007-05-27 01:59:23 EDT (Sun, 27 May 2007)
@@ -0,0 +1,32 @@
+// Boost.Print library
+
+// Copyright Jared McIntyre 2007. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/list.hpp>
+
+#include "../../../boost/explore/explore.hpp"
+
+struct basic_lg_range_format : explore::basic_range_format
+{
+ static char_ *opening() { return "<=";}
+ static char_ *closing() { return "=>";}
+ static char_ delimiter() { return '#';}
+};
+
+struct basic_lg_range_format_selector
+{
+ template< typename T>
+ struct range_format
+ {
+ typedef basic_lg_range_format type;
+ };
+};
+
+
+struct basic_lg_format : boost::mpl::list< basic_lg_range_format_selector> {};

Added: sandbox/explore/libs/explore/test/custom_format_simple.cpp
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/custom_format_simple.cpp 2007-05-27 01:59:23 EDT (Sun, 27 May 2007)
@@ -0,0 +1,87 @@
+// Boost.Print library
+
+// Copyright Jared McIntyre 2007. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#define BOOST_TEST_MODULE PrintLib
+#include <boost/test/unit_test.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <string>
+#include <sstream>
+#include <vector>
+#include "../../../boost/explore/explore.hpp"
+#include "../../../boost/explore/stream_container.hpp"
+#include "basic_lg_format.hpp"
+
+BOOST_AUTO_TEST_CASE( basic_vector_custom_format_print_test )
+{
+ std::stringstream str_out;
+
+ std::vector<int> vi;
+ explore::print(vi, str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<==>");
+
+ str_out.str("");
+
+ vi.push_back(1);
+ explore::print(vi, str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=1=>");
+
+ str_out.str("");
+
+ vi.push_back(2);
+ vi.push_back(3);
+ explore::print(vi, str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=1#2#3=>");
+
+ str_out.str("");
+
+ explore::print(vi.begin(), ++(++vi.begin()), str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=1#2=>");
+
+ str_out.str("");
+
+ explore::print(boost::make_iterator_range(vi.begin(), ++(++vi.begin())), str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=1#2=>");
+
+ str_out.str("");
+
+ explore::print(vi, str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=1#2#3=>");
+}
+
+BOOST_AUTO_TEST_CASE( basic_map_custom_format_print_test )
+{
+ std::stringstream str_out;
+
+ std::map<int,std::string> mis;
+ explore::print(mis, str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<==>");
+
+ str_out.str("");
+
+ mis.insert(std::make_pair(1, "first"));
+ explore::print(mis, str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=<=1#first=>=>");
+
+ str_out.str("");
+
+ mis.insert(std::make_pair(2, "second"));
+ mis.insert(std::make_pair(3, "third"));
+ explore::print(mis, str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=<=1#first=>#<=2#second=>#<=3#third=>=>");
+
+ str_out.str("");
+
+ explore::print(mis.begin(), ++(++mis.begin()), str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=<=1#first=>#<=2#second=>=>");
+
+ str_out.str("");
+
+ explore::print(boost::make_iterator_range(mis.begin(), ++(++mis.begin())), str_out, basic_lg_format(), explore::default_container_policy());
+ BOOST_CHECK_EQUAL(str_out.str(), "<=<=1#first=>#<=2#second=>=>");
+}

Modified: sandbox/explore/libs/explore/test/std_vector.cpp
==============================================================================
--- sandbox/explore/libs/explore/test/std_vector.cpp (original)
+++ sandbox/explore/libs/explore/test/std_vector.cpp 2007-05-27 01:59:23 EDT (Sun, 27 May 2007)
@@ -16,22 +16,22 @@
 #include "../../../boost/explore/explore.hpp"
 #include "../../../boost/explore/stream_container.hpp"
 
-BOOST_AUTO_TEST_CASE( basic_vector_print_test )
+BOOST_AUTO_TEST_CASE( vector_custom_format_print_test )
 {
     std::stringstream str_out;
-
+
     std::vector<int> vi;
     explore::print(vi, str_out);
     BOOST_CHECK_EQUAL(str_out.str(), "[]");
-
+
     str_out.str("");
-
+
     vi.push_back(1);
     explore::print(vi, str_out);
- BOOST_CHECK_EQUAL(str_out.str(), "[1]");
-
+ BOOST_CHECK_EQUAL(sŒtr_out.str(), "[1]");
+
     str_out.str("");
-
+
     vi.push_back(2);
     vi.push_back(3);
     explore::print(vi, str_out);
@@ -46,25 +46,30 @@
         
     explore::print(boost::make_iterator_range(vi.begin(), ++(++vi.begin())), str_out);
     BOOST_CHECK_EQUAL(str_out.str(), "[1, 2]");
+
+ str_out.str("");
+
+ explore::print(vi, str_out);
+ BOOST_CHECK_EQUAL(str_out.str(), "[1, 2, 3]");
 }
 
 BOOST_AUTO_TEST_CASE( basic_vector_stream_test )
 {
     using namespace boost;
     std::stringstream str_out;
-
+
     std::vector<int> vi;
     str_out << vi;
     BOOST_CHECK_EQUAL(str_out.str(), "[]");
-
+
     str_out.str("");
-
+
     vi.push_back(1);
     str_out << vi;
     BOOST_CHECK_EQUAL(str_out.str(), "[1]");
-
+
     str_out.str("");
-
+
     vi.push_back(2);
     vi.push_back(3);
     str_out << vi;
@@ -84,24 +89,24 @@
 BOOST_AUTO_TEST_CASE( vector_in_vector_print_test )
 {
     std::stringstream str_out;
-
+
     std::vector<int> vi;
     vi.push_back(1);
     vi.push_back(2);
     vi.push_back(3);
-
+
     std::vector<std::vector<int> > vvi;
     explore::print(vvi, str_out);
     BOOST_CHECK_EQUAL(str_out.str(), "[]");
-
+
     str_out.str("");
-
+
     vvi.push_back(vi);
     explore::print(vvi, str_out);
     BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3]]");
-
+
     str_out.str("");
-
+
     vvi.push_back(vi);
     vvi.push_back(vi);
     explore::print(vvi, str_out);
@@ -122,24 +127,24 @@
 {
     using namespace boost;
     std::stringstream str_out;
-
+
     std::vector<int> vi;
     vi.push_back(1);
     vi.push_back(2);
     vi.push_back(3);
-
+
     std::vector<std::vector<int> > vvi;
     str_out << vvi;
     BOOST_CHECK_EQUAL(str_out.str(), "[]");
-
+
     str_out.str("");
-
+
     vvi.push_back(vi);
     str_out << vvi;
     BOOST_CHECK_EQUAL(str_out.str(), "[[1, 2, 3]]");
-
+
     str_out.str("");
-
+
     vvi.push_back(vi);
     vvi.push_back(vi);
     str_out << vvi;
@@ -161,7 +166,7 @@
 BOOST_AUTO_TEST_CASE( vector_with_ugly_string_case_print_test )
 {
     std::stringstream str_out;
-
+
     std::vector<std::string> vs;
     vs.push_back("[1, 2, 3], [1, 2, 3], [1, 2, 3]");
     explore::print(vs, str_out);
@@ -172,7 +177,7 @@
 {
     using namespace boost;
     std::stringstream str_out;
-
+
     std::vector<std::string> vs;
     vs.push_back("[1, 2, 3], [1, 2, 3], [1, 2, 3]");
     str_out << vs;


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