Skip to content

Commit e7cfb9a

Browse files
committed
Move the test cases within test scope
1 parent ffab2ee commit e7cfb9a

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

api/test/trace/propagation/detail/string_test.cc

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "opentelemetry/nostd/string_view.h"
99

1010
using namespace opentelemetry;
11-
11+
//
1212
// struct SplitStringTestData
1313
//{
1414
// opentelemetry::nostd::string_view input;
@@ -37,25 +37,50 @@ using namespace opentelemetry;
3737
// "00f067aa0ba902b7", "01"},
3838
// 4},
3939
// };
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+
}
5984

6085
TEST(StringTest, SimpleTest)
6186
{

0 commit comments

Comments
 (0)