Implement ostream_joiner

This commit is contained in:
Glen Fernandes
2019-12-14 07:56:15 -05:00
parent a6b31015c6
commit 2dc89e1eee
8 changed files with 411 additions and 3 deletions

View File

@ -11,3 +11,5 @@ import testing ;
run ios_state_unit_test.cpp ;
run ios_state_test.cpp ;
run quoted_manip_test.cpp ;
run ostream_joiner_test.cpp ;
run make_ostream_joiner_test.cpp ;

View File

@ -0,0 +1,21 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/io/ostream_joiner.hpp>
#include <sstream>
int main()
{
std::ostringstream o;
boost::io::ostream_joiner<char> j = boost::io::make_ostream_joiner(o, ',');
*j++ = 1;
*j++ = '2';
*j++ = "3";
BOOST_TEST_EQ(o.str(), "1,2,3");
return boost::report_errors();
}

View File

@ -0,0 +1,116 @@
/*
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/io/ostream_joiner.hpp>
#include <sstream>
void test_char_type()
{
BOOST_TEST_TRAIT_SAME(char,
boost::io::ostream_joiner<const char*>::char_type);
}
void test_traits_type()
{
BOOST_TEST_TRAIT_SAME(std::char_traits<char>,
boost::io::ostream_joiner<const char*>::traits_type);
}
void test_ostream_type()
{
BOOST_TEST_TRAIT_SAME(std::ostream,
boost::io::ostream_joiner<const char*>::ostream_type);
}
void test_iterator_category()
{
BOOST_TEST_TRAIT_SAME(std::output_iterator_tag,
boost::io::ostream_joiner<const char*>::iterator_category);
}
void test_value_type()
{
BOOST_TEST_TRAIT_SAME(void,
boost::io::ostream_joiner<const char*>::value_type);
}
void test_difference_type()
{
BOOST_TEST_TRAIT_SAME(void,
boost::io::ostream_joiner<const char*>::difference_type);
}
void test_pointer()
{
BOOST_TEST_TRAIT_SAME(void,
boost::io::ostream_joiner<const char*>::pointer);
}
void test_reference()
{
BOOST_TEST_TRAIT_SAME(void,
boost::io::ostream_joiner<const char*>::reference);
}
void test_construct()
{
std::ostringstream o;
boost::io::ostream_joiner<const char*> j(o, ",");
BOOST_TEST(o.str().empty());
}
void test_assign()
{
std::ostringstream o;
boost::io::ostream_joiner<const char*> j(o, ",");
j = 1;
BOOST_TEST_EQ(o.str(), "1");
j = '2';
BOOST_TEST_EQ(o.str(), "1,2");
j = "3";
BOOST_TEST_EQ(o.str(), "1,2,3");
}
void test_increment()
{
std::ostringstream o;
boost::io::ostream_joiner<const char*> j(o, ",");
BOOST_TEST_EQ(&++j, &j);
}
void test_post_increment()
{
std::ostringstream o;
boost::io::ostream_joiner<const char*> j(o, ",");
BOOST_TEST_EQ(&j++, &j);
}
void test_value()
{
std::ostringstream o;
boost::io::ostream_joiner<const char*> j(o, ",");
BOOST_TEST_EQ(&*j, &j);
}
int main()
{
test_char_type();
test_traits_type();
test_ostream_type();
test_iterator_category();
test_value_type();
test_difference_type();
test_pointer();
test_reference();
test_construct();
test_assign();
test_increment();
test_post_increment();
test_value();
return boost::report_errors();
}