|
8 | 8 | #include "opentelemetry/nostd/string_view.h" |
9 | 9 |
|
10 | 10 | using namespace opentelemetry; |
11 | | - |
| 11 | +// |
12 | 12 | // struct SplitStringTestData |
13 | 13 | //{ |
14 | 14 | // opentelemetry::nostd::string_view input; |
@@ -37,25 +37,50 @@ using namespace opentelemetry; |
37 | 37 | // "00f067aa0ba902b7", "01"}, |
38 | 38 | // 4}, |
39 | 39 | // }; |
40 | | -// |
41 | | -// |
42 | | -// TEST(StringTest, SplitStringTest) |
43 | | -//{ |
44 | | -// for (auto &test_param : split_string_test_cases) { |
45 | | -// std::vector<opentelemetry::nostd::string_view> fields{}; |
46 | | -// fields.reserve(test_param.expected_number_strings); |
47 | | -// size_t got_splits_num = opentelemetry::trace::propagation::detail::SplitString( |
48 | | -// test_param.input, test_param.separator, fields.data(), test_param.max_count); |
49 | | -// |
50 | | -// // Assert on the output |
51 | | -// EXPECT_EQ(got_splits_num, test_param.expected_number_strings); |
52 | | -// for (size_t i = 0; i < got_splits_num; i++) |
53 | | -// { |
54 | | -// // Checks for resulting strings in-order |
55 | | -// EXPECT_EQ(fields[i], test_param.splits[i]); |
56 | | -// } |
57 | | -// } |
58 | | -// } |
| 40 | + |
| 41 | +TEST(StringTest, SplitStringTest) |
| 42 | +{ |
| 43 | + struct |
| 44 | + { |
| 45 | + opentelemetry::nostd::string_view input; |
| 46 | + char separator; |
| 47 | + size_t max_count; |
| 48 | + std::vector<opentelemetry::nostd::string_view> splits; |
| 49 | + size_t expected_number_strings; |
| 50 | + } test_cases[] = { |
| 51 | + {"foo,bar,baz", ',', 4, std::vector<opentelemetry::nostd::string_view>{"foo", "bar", "baz"}, |
| 52 | + 3}, |
| 53 | +// {"foo,bar,baz,foobar", ',', 4, |
| 54 | +// std::vector<opentelemetry::nostd::string_view>{"foo", "bar", "baz", "foobar"}, 4}, |
| 55 | +// {"foo,bar,baz,foobar", '.', 4, |
| 56 | +// std::vector<opentelemetry::nostd::string_view>{"foo,bar,baz,foobar"}, 1}, |
| 57 | +// {"foo,bar,baz,", ',', 4, |
| 58 | +// std::vector<opentelemetry::nostd::string_view>{"foo", "bar", "baz", ""}, 4}, |
| 59 | +// {"foo,bar,baz,", ',', 2, std::vector<opentelemetry::nostd::string_view>{"foo", "bar"}, 2}, |
| 60 | +// {"foo ,bar, baz ", ',', 4, |
| 61 | +// std::vector<opentelemetry::nostd::string_view>{"foo ", "bar", " baz "}, 3}, |
| 62 | +// {"foo ,bar, baz ", ',', 4, |
| 63 | +// std::vector<opentelemetry::nostd::string_view>{"foo ", "bar", " baz "}, 3}, |
| 64 | +// {"00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01", '-', 4, |
| 65 | +// std::vector<opentelemetry::nostd::string_view>{"00", "0af7651916cd43dd8448eb211c80319c", |
| 66 | +// "00f067aa0ba902b7", "01"},4} |
| 67 | + }; |
| 68 | + for (auto &test_param : test_cases) |
| 69 | + { |
| 70 | + std::vector<opentelemetry::nostd::string_view> fields{}; |
| 71 | + fields.reserve(test_param.expected_number_strings); |
| 72 | + size_t got_splits_num = opentelemetry::trace::propagation::detail::SplitString( |
| 73 | + test_param.input, test_param.separator, fields.data(), test_param.max_count); |
| 74 | + |
| 75 | + // Assert on the output |
| 76 | + EXPECT_EQ(got_splits_num, test_param.expected_number_strings); |
| 77 | + for (size_t i = 0; i < got_splits_num; i++) |
| 78 | + { |
| 79 | + // Checks for resulting strings in-order |
| 80 | + EXPECT_EQ(fields[i], test_param.splits[i]); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
59 | 84 |
|
60 | 85 | TEST(StringTest, SimpleTest) |
61 | 86 | { |
|
0 commit comments