MCPcopy Create free account
hub / github.com/Snapchat/Valdi / TEST

Function TEST

valdi/test/runtime/UTF_tests.cpp:9–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace ValdiTest {
8
9TEST(UTF16ToUTF32Index, canResolveIndexesOnEqualLength) {
10 std::string_view str = "Hello World\n";
11
12 std::vector<uint32_t> utf32;
13 std::vector<char16_t> utf16;
14
15 for (auto c : str) {
16 utf32.emplace_back(static_cast<uint32_t>(c));
17 utf16.emplace_back(static_cast<char16_t>(c));
18 }
19
20 UTF16ToUTF32Index index(utf16.data(), utf16.size(), utf32.data(), utf32.size());
21
22 ASSERT_EQ(static_cast<size_t>(0), index.getUTF32Index(0));
23 ASSERT_EQ(static_cast<size_t>(5), index.getUTF32Index(5));
24 ASSERT_EQ(static_cast<size_t>(11), index.getUTF32Index(11));
25 // Out of bounds should still work
26 ASSERT_EQ(static_cast<size_t>(42), index.getUTF32Index(42));
27}
28
29TEST(UTF16ToUTF32Index, canResolveIndexesOnDifferentLength) {
30 std::string_view str = "مقدمة إلى \U0001F385\U0001F385\u2066C++ \U0001F385 ASCII \U0001F385\U0001F385 MORE ASCII "

Callers

nothing calls this directly

Calls 5

utf8ToUtf16Function · 0.85
utf8ToUtf32Function · 0.85
getUTF32IndexMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected