| 317 | } |
| 318 | |
| 319 | TEST(SkipUTF8BOM, Basics) { |
| 320 | auto CheckOk = [](const std::string& s, size_t expected_offset) -> void { |
| 321 | const uint8_t* data = reinterpret_cast<const uint8_t*>(s.data()); |
| 322 | const uint8_t* res; |
| 323 | ASSERT_OK_AND_ASSIGN(res, SkipUTF8BOM(data, static_cast<int64_t>(s.size()))); |
| 324 | ASSERT_NE(res, nullptr); |
| 325 | ASSERT_EQ(res - data, expected_offset); |
| 326 | }; |
| 327 | |
| 328 | auto CheckTruncated = [](const std::string& s) -> void { |
| 329 | const uint8_t* data = reinterpret_cast<const uint8_t*>(s.data()); |
| 330 | ASSERT_RAISES(Invalid, SkipUTF8BOM(data, static_cast<int64_t>(s.size()))); |
| 331 | }; |
| 332 | |
| 333 | CheckOk("", 0); |
| 334 | CheckOk("a", 0); |
| 335 | CheckOk("ab", 0); |
| 336 | CheckOk("abc", 0); |
| 337 | CheckOk("abcd", 0); |
| 338 | CheckOk("\xc3\xa9", 0); |
| 339 | CheckOk("\xee", 0); |
| 340 | CheckOk("\xef\xbc", 0); |
| 341 | CheckOk("\xef\xbb\xbe", 0); |
| 342 | CheckOk("\xef\xbb\xbf", 3); |
| 343 | CheckOk("\xef\xbb\xbfx", 3); |
| 344 | |
| 345 | CheckTruncated("\xef"); |
| 346 | CheckTruncated("\xef\xbb"); |
| 347 | } |
| 348 | |
| 349 | // Currently a known issue with Valgrind and wide string AVX2 instructions |
| 350 | // https://sourceware.org/bugzilla/show_bug.cgi?id=22954 |
nothing calls this directly
no test coverage detected