| 1 | #include "duckdb/common/string_util.hpp" | 
|---|
| 2 |  | 
|---|
| 3 | #include "catch.hpp" | 
|---|
| 4 |  | 
|---|
| 5 | #include <vector> | 
|---|
| 6 | #include <string> | 
|---|
| 7 |  | 
|---|
| 8 | using namespace duckdb; | 
|---|
| 9 |  | 
|---|
| 10 | TEST_CASE( "Test join vector items", "[string_util]") { | 
|---|
| 11 | SECTION( "Three string items") { | 
|---|
| 12 | std::vector<std::string> str_items = { "abc", "def", "ghi"}; | 
|---|
| 13 | std::string result = StringUtil::Join(str_items, ","); | 
|---|
| 14 | REQUIRE(result == "abc,def,ghi"); | 
|---|
| 15 | } | 
|---|
| 16 |  | 
|---|
| 17 | SECTION( "One string item") { | 
|---|
| 18 | std::vector<std::string> str_items = { "abc"}; | 
|---|
| 19 | std::string result = StringUtil::Join(str_items, ","); | 
|---|
| 20 | REQUIRE(result == "abc"); | 
|---|
| 21 | } | 
|---|
| 22 |  | 
|---|
| 23 | SECTION( "No string items") { | 
|---|
| 24 | std::vector<std::string> str_items; | 
|---|
| 25 | std::string result = StringUtil::Join(str_items, ","); | 
|---|
| 26 | REQUIRE(result == ""); | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | SECTION( "Three int items") { | 
|---|
| 30 | std::vector<int> int_items = {1, 2, 3}; | 
|---|
| 31 | std::string result = | 
|---|
| 32 | StringUtil::Join(int_items, int_items.size(), ", ", [](const int &item) { return std::to_string(item); }); | 
|---|
| 33 | REQUIRE(result == "1, 2, 3"); | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | SECTION( "One int item") { | 
|---|
| 37 | std::vector<int> int_items = {1}; | 
|---|
| 38 | std::string result = | 
|---|
| 39 | StringUtil::Join(int_items, int_items.size(), ", ", [](const int &item) { return std::to_string(item); }); | 
|---|
| 40 | REQUIRE(result == "1"); | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 | SECTION( "No int items") { | 
|---|
| 44 | std::vector<int> int_items; | 
|---|
| 45 | std::string result = | 
|---|
| 46 | StringUtil::Join(int_items, int_items.size(), ", ", [](const int &item) { return std::to_string(item); }); | 
|---|
| 47 | REQUIRE(result == ""); | 
|---|
| 48 | } | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|