]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright The OpenTelemetry Authors |
2 | // SPDX-License-Identifier: Apache-2.0 | |
3 | ||
4 | #include <gtest/gtest.h> | |
5 | #include <opentelemetry/common/string_util.h> | |
6 | ||
7 | #include <string> | |
8 | #include <utility> | |
9 | #include <vector> | |
10 | ||
11 | // ------------------------- StringUtil class tests --------------------------------- | |
12 | ||
13 | using opentelemetry::common::StringUtil; | |
14 | ||
15 | TEST(StringUtilTest, TrimStringWithIndex) | |
16 | { | |
17 | struct | |
18 | { | |
19 | const char *input; | |
20 | const char *expected; | |
21 | } testcases[] = {{"k1=v1", "k1=v1"}, {"k1=v1,k2=v2, k3=v3", "k1=v1,k2=v2, k3=v3"}, | |
22 | {" k1=v1", "k1=v1"}, {"k1=v1 ", "k1=v1"}, | |
23 | {" k1=v1 ", "k1=v1"}, {" ", ""}}; | |
24 | for (auto &testcase : testcases) | |
25 | { | |
26 | EXPECT_EQ(StringUtil::Trim(testcase.input, 0, strlen(testcase.input) - 1), testcase.expected); | |
27 | } | |
28 | } | |
29 | ||
30 | TEST(StringUtilTest, TrimString) | |
31 | { | |
32 | struct | |
33 | { | |
34 | const char *input; | |
35 | const char *expected; | |
36 | } testcases[] = {{"k1=v1", "k1=v1"}, | |
37 | {"k1=v1,k2=v2, k3=v3", "k1=v1,k2=v2, k3=v3"}, | |
38 | {" k1=v1", "k1=v1"}, | |
39 | {"k1=v1 ", "k1=v1"}, | |
40 | {" k1=v1 ", "k1=v1"}, | |
41 | {" ", ""}, | |
42 | {"", ""}}; | |
43 | for (auto &testcase : testcases) | |
44 | { | |
45 | EXPECT_EQ(StringUtil::Trim(testcase.input), testcase.expected); | |
46 | } | |
47 | } |