You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.0 KiB
41 lines
1.0 KiB
#include <catch2/catch_all.hpp>
|
|
|
|
#include <monoformat_utf8.hpp>
|
|
|
|
TEST_CASE("TestUTF8.SimpleIterator") {
|
|
int i = 0;
|
|
for (std::uint32_t cp : monoformat::UTF8Iterator(std::string_view{"abc"})) {
|
|
if (i == 0) {
|
|
CHECK(cp == 'a');
|
|
} else if (i == 1) {
|
|
CHECK(cp == 'b');
|
|
} else if (i == 2) {
|
|
CHECK(cp == 'c');
|
|
}
|
|
++i;
|
|
}
|
|
CHECK(i == 3);
|
|
i = 0;
|
|
for (std::uint32_t cp : monoformat::UTF8Iterator(std::string_view{"\xe2\x98\x83"})) {
|
|
if (i == 0) {
|
|
CHECK(cp == 0x2603);
|
|
}
|
|
++i;
|
|
}
|
|
CHECK(i == 1);
|
|
}
|
|
|
|
TEST_CASE("TestUTF8.Invalid") {
|
|
int i = 0;
|
|
for (std::uint32_t cp : monoformat::UTF8Iterator(std::string_view{"\x80\xe2\x98\x83\xe2\x98"})) {
|
|
if (i == 0) {
|
|
CHECK(cp == ~std::uint32_t{0});
|
|
} else if (i == 1) {
|
|
CHECK(cp == 0x2603);
|
|
} else if (i == 2) {
|
|
CHECK(cp == ~std::uint32_t{0});
|
|
}
|
|
++i;
|
|
}
|
|
CHECK(i == 3);
|
|
}
|
|
|