|
| 1 | +#include <list> |
| 2 | +#include <vector> |
| 3 | + |
| 4 | +#include "gtest/gtest.h" |
| 5 | +#include "join.hpp" |
| 6 | + |
| 7 | +using my_algorithm::join; |
| 8 | + |
| 9 | +TEST(JoinTest, HandlesEmptyRange) { |
| 10 | + const std::vector<std::string> empty_vec; |
| 11 | + EXPECT_EQ(join(empty_vec, ","), ""); |
| 12 | +} |
| 13 | + |
| 14 | +TEST(JoinTest, HandlesSingleString) { |
| 15 | + const std::list<std::string> single = {"hello"}; |
| 16 | + EXPECT_EQ(join(single, " "), "hello"); |
| 17 | +} |
| 18 | + |
| 19 | +TEST(JoinTest, JoinsMultipleStrings) { |
| 20 | + const std::vector<std::string> strings = {"a", "b", "c"}; |
| 21 | + EXPECT_EQ(join(strings, ","), "a,b,c"); |
| 22 | +} |
| 23 | + |
| 24 | +TEST(JoinTest, WorksWithStringView) { |
| 25 | + const std::vector<std::string_view> sv = {"x", "y", "z"}; |
| 26 | + EXPECT_EQ(join(sv, "->"), "x->y->z"); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(JoinTest, HandlesMultiCharDelimiter) { |
| 30 | + const std::vector<std::string> strings = {"1", "2", "3"}; |
| 31 | + EXPECT_EQ(join(strings, "###"), "1###2###3"); |
| 32 | +} |
| 33 | + |
| 34 | +TEST(JoinTest, WorksWithNonOwningTypes) { |
| 35 | + const char* cstrings[] = {"quick", "brown", "fox"}; |
| 36 | + EXPECT_EQ(join(cstrings, "..."), "quick...brown...fox"); |
| 37 | +} |
0 commit comments