/* 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 .
*/
#include "catch2/catch_test_macros.hpp"
#include "duckhandy/infix_iterator.hpp"
#include
#include
#include
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 empty{};
copy(empty.begin(), empty.end(), infix_ostream_iterator(oss, "lalala"));
CHECK(oss.str() == "");
}
{
ostringstream oss;
vector data{"apple", "pear", "cherry", "mango"};
copy(data.begin(), data.end(), infix_ostream_iterator(oss, "lalala"));
CHECK(oss.str() == "applelalalapearlalalacherrylalalamango");
}
{
ostringstream oss;
vector data{1, 2, 3, 4, 5, 6, 7};
copy(data.begin(), data.end(), infix_ostream_iterator(oss, ", "));
CHECK(oss.str() == "1, 2, 3, 4, 5, 6, 7");
}
{
ostringstream oss;
vector data{"just one value"};
copy(data.begin(), data.end(), infix_ostream_iterator(oss, ", "));
CHECK(oss.str() == "just one value");
}
}