|
11 | 11 |
|
12 | 12 | using namespace datadog::tracing; |
13 | 13 |
|
14 | | -TEST_CASE("parse_int") { |
| 14 | +#define PARSE_UTIL_TEST(x) TEST_CASE(x, "[parse_util]") |
| 15 | + |
| 16 | +PARSE_UTIL_TEST("parse_int") { |
15 | 17 | struct TestCase { |
16 | 18 | int line; |
17 | 19 | std::string name; |
@@ -74,7 +76,7 @@ TEST_CASE("parse_int") { |
74 | 76 |
|
75 | 77 | // This test case is similar to the one above, except that negative numbers are |
76 | 78 | // not supported, and the underflow and overflow values are different. |
77 | | -TEST_CASE("parse_uint64") { |
| 79 | +PARSE_UTIL_TEST("parse_uint64") { |
78 | 80 | struct TestCase { |
79 | 81 | int line; |
80 | 82 | std::string name; |
@@ -133,3 +135,101 @@ TEST_CASE("parse_uint64") { |
133 | 135 | REQUIRE(result.error().code == expected); |
134 | 136 | } |
135 | 137 | } |
| 138 | + |
| 139 | +PARSE_UTIL_TEST("parse_tags") { |
| 140 | + struct TestCase { |
| 141 | + int line; |
| 142 | + StringView name; |
| 143 | + StringView input; |
| 144 | + std::unordered_map<std::string, std::string> expected; |
| 145 | + }; |
| 146 | + |
| 147 | + auto test_case = GENERATE(values<TestCase>({ |
| 148 | + {__LINE__, |
| 149 | + "space separated tags", |
| 150 | + "env:test aKey:aVal bKey:bVal cKey:", |
| 151 | + { |
| 152 | + {"env", "test"}, |
| 153 | + {"aKey", "aVal"}, |
| 154 | + {"bKey", "bVal"}, |
| 155 | + {"cKey", ""}, |
| 156 | + }}, |
| 157 | + {__LINE__, |
| 158 | + "comma separated tags", |
| 159 | + "env:test aKey:aVal bKey:bVal cKey:", |
| 160 | + { |
| 161 | + {"env", "test"}, |
| 162 | + {"aKey", "aVal"}, |
| 163 | + {"bKey", "bVal"}, |
| 164 | + {"cKey", ""}, |
| 165 | + }}, |
| 166 | + {__LINE__, |
| 167 | + "mixed separator but comma first", |
| 168 | + "env:test,aKey:aVal bKey:bVal cKey:", |
| 169 | + { |
| 170 | + {"env", "test"}, |
| 171 | + {"aKey", "aVal bKey:bVal cKey:"}, |
| 172 | + }}, |
| 173 | + {__LINE__, |
| 174 | + "mixed separator but space first", |
| 175 | + "env:test bKey :bVal dKey: dVal cKey:", |
| 176 | + { |
| 177 | + {"env", "test"}, |
| 178 | + {"bKey", ""}, |
| 179 | + {"dKey", ""}, |
| 180 | + {"dVal", ""}, |
| 181 | + {"cKey", ""}, |
| 182 | + }}, |
| 183 | + {__LINE__, |
| 184 | + "mixed separator but space first", |
| 185 | + "env:keyWithA:Semicolon bKey:bVal cKey", |
| 186 | + { |
| 187 | + {"env", "keyWithA:Semicolon"}, |
| 188 | + {"bKey", "bVal"}, |
| 189 | + {"cKey", ""}, |
| 190 | + }}, |
| 191 | + // {__LINE__, |
| 192 | + // "mixed separator edge case", |
| 193 | + // "env:keyWith: , , Lots:Of:Semicolons ", |
| 194 | + // { |
| 195 | + // {"env", "keyWith:"}, |
| 196 | + // {"Lots", "Of:Semicolons"}, |
| 197 | + // }}, |
| 198 | + {__LINE__, |
| 199 | + "comma separated but some tags without value", |
| 200 | + "a:b,c,d", |
| 201 | + { |
| 202 | + {"a", "b"}, |
| 203 | + {"c", ""}, |
| 204 | + {"d", ""}, |
| 205 | + }}, |
| 206 | + {__LINE__, |
| 207 | + "one separator without value", |
| 208 | + "a,1", |
| 209 | + { |
| 210 | + {"a", ""}, |
| 211 | + {"1", ""}, |
| 212 | + }}, |
| 213 | + {__LINE__, |
| 214 | + "no separator", |
| 215 | + "a:b:c:d", |
| 216 | + { |
| 217 | + {"a", "b:c:d"}, |
| 218 | + }}, |
| 219 | + {__LINE__, |
| 220 | + "input is trimed", |
| 221 | + "key1:val1, key2 : val2 ", |
| 222 | + { |
| 223 | + {"key1", "val1"}, |
| 224 | + {"key2", "val2"}, |
| 225 | + }}, |
| 226 | + })); |
| 227 | + |
| 228 | + CAPTURE(test_case.line); |
| 229 | + CAPTURE(test_case.name); |
| 230 | + CAPTURE(test_case.input); |
| 231 | + |
| 232 | + const auto tags = parse_tags(test_case.input); |
| 233 | + REQUIRE(tags); |
| 234 | + CHECK(*tags == test_case.expected); |
| 235 | +} |
0 commit comments