mirror of
https://github.com/boostorg/io.git
synced 2025-07-30 12:27:13 +02:00
Update and release the quoted manipulators
This commit is contained in:
@ -10,6 +10,6 @@ import testing ;
|
||||
|
||||
run ios_state_unit_test.cpp ;
|
||||
run ios_state_test.cpp ;
|
||||
run quoted_manip_test.cpp ;
|
||||
run quoted_test.cpp ;
|
||||
run ostream_joiner_test.cpp ;
|
||||
run make_ostream_joiner_test.cpp ;
|
||||
|
@ -1,133 +0,0 @@
|
||||
// libs/io/test/quote_manip_test.cpp ----------------------------------------------- //
|
||||
|
||||
// Copyright Beman Dawes 2010
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
// Library home page: http://www.boost.org/libs/io
|
||||
|
||||
// ---------------------------------------------------------------------------------- //
|
||||
|
||||
#include <boost/io/detail/quoted_manip.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using boost::io::quoted;
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::wstringstream wss;
|
||||
|
||||
string r; // test results
|
||||
|
||||
const string s0("foo");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s0);
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo\"");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s0);
|
||||
ss >> quoted(r);
|
||||
BOOST_TEST(r == "foo");
|
||||
}
|
||||
|
||||
const string s0s("foo bar");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s0s);
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s0s);
|
||||
ss >> quoted(r);
|
||||
BOOST_TEST(r == "foo bar");
|
||||
}
|
||||
|
||||
const string s1("foo\\bar, \" *");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s1);
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo\\\\bar,");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted("foo\\bar, \" *");
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo\\\\bar,");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s1);
|
||||
ss >> quoted(r);
|
||||
BOOST_TEST(r == s1);
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s1.c_str());
|
||||
ss >> quoted(r);
|
||||
BOOST_TEST(r == s1);
|
||||
}
|
||||
|
||||
string s2("'Jack & Jill'");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s2, '&', '\'');
|
||||
ss >> quoted(r, '&', '\'');
|
||||
BOOST_TEST(r == s2);
|
||||
}
|
||||
|
||||
wstring ws1(L"foo$bar, \" *");
|
||||
wstring wr; // test results
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << quoted(ws1, L'$');
|
||||
wss >> quoted(wr, L'$');
|
||||
BOOST_TEST(wr == ws1);
|
||||
}
|
||||
|
||||
const string s3("const string");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << quoted(s3);
|
||||
ss >> quoted(r);
|
||||
BOOST_TEST(r == s3);
|
||||
}
|
||||
{
|
||||
// missing end delimiter test
|
||||
std::stringstream ss;
|
||||
ss << "\"abc"; // load ss with faulty quoting
|
||||
ss >> quoted(r); // this loops if istream error/eof not detected
|
||||
BOOST_TEST(r == "abc");
|
||||
}
|
||||
{
|
||||
// no initial delmiter test
|
||||
std::stringstream ss;
|
||||
ss << "abc";
|
||||
ss >> quoted(r);
|
||||
BOOST_TEST(r == "abc");
|
||||
}
|
||||
{
|
||||
// no initial delmiter, space in ss
|
||||
std::stringstream ss;
|
||||
ss << "abc def";
|
||||
ss >> quoted(r);
|
||||
BOOST_TEST(r == "abc");
|
||||
}
|
||||
|
||||
// these should fail to compile because the arguments are const:
|
||||
// ss >> quoted(s1);
|
||||
// ss >> quoted("foo");
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
110
test/quoted_test.cpp
Normal file
110
test/quoted_test.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright 2010 Beman Dawes
|
||||
|
||||
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/io/quoted.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::string s0("foo");
|
||||
std::string r;
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s0);
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo\"");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s0);
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == "foo");
|
||||
}
|
||||
const std::string s0s("foo bar");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s0s);
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s0s);
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == "foo bar");
|
||||
}
|
||||
const std::string s1("foo\\bar, \" *");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s1);
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo\\\\bar,");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted("foo\\bar, \" *");
|
||||
ss >> r;
|
||||
BOOST_TEST(r == "\"foo\\\\bar,");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s1);
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == s1);
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s1.c_str());
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == s1);
|
||||
}
|
||||
std::string s2("'Jack & Jill'");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s2, '&', '\'');
|
||||
ss >> boost::io::quoted(r, '&', '\'');
|
||||
BOOST_TEST(r == s2);
|
||||
}
|
||||
const std::wstring ws1(L"foo$bar, \" *");
|
||||
std::wstring wr;
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << boost::io::quoted(ws1, L'$');
|
||||
wss >> boost::io::quoted(wr, L'$');
|
||||
BOOST_TEST(wr == ws1);
|
||||
}
|
||||
const std::string s3("const string");
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << boost::io::quoted(s3);
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == s3);
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "\"abc";
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == "abc");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "abc";
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == "abc");
|
||||
}
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "abc def";
|
||||
ss >> boost::io::quoted(r);
|
||||
BOOST_TEST(r == "abc");
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user