duckhandy/test/unit/infix_iterator.cpp
King_DuckZ 4d904ac689 Fix deprecation warning
Also put iterator into dhandy namespace. I don't
remember why I left it out, and it's probably a
sign I should have not done so.
2024-04-26 00:19:50 +02:00

58 lines
1.8 KiB
C++

/* Copyright 2016-2024 Michele Santullo
* This file is part of "duckhandy".
*
* "duckhandy" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "duckhandy" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "duckhandy". If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch_test_macros.hpp"
#include "duckhandy/infix_iterator.hpp"
#include <algorithm>
#include <sstream>
#include <vector>
TEST_CASE("infix_iterator tests", "[iterator][infix_iterator]") {
using std::vector;
using std::string;
using std::copy;
using std::ostringstream;
using dhandy::infix_ostream_iterator;
{
ostringstream oss;
vector<string> empty{};
copy(empty.begin(), empty.end(), infix_ostream_iterator<string>(oss, "lalala"));
CHECK(oss.str() == "");
}
{
ostringstream oss;
vector<string> data{"apple", "pear", "cherry", "mango"};
copy(data.begin(), data.end(), infix_ostream_iterator<string>(oss, "lalala"));
CHECK(oss.str() == "applelalalapearlalalacherrylalalamango");
}
{
ostringstream oss;
vector<int> data{1, 2, 3, 4, 5, 6, 7};
copy(data.begin(), data.end(), infix_ostream_iterator<int>(oss, ", "));
CHECK(oss.str() == "1, 2, 3, 4, 5, 6, 7");
}
{
ostringstream oss;
vector<string> data{"just one value"};
copy(data.begin(), data.end(), infix_ostream_iterator<string>(oss, ", "));
CHECK(oss.str() == "just one value");
}
}