diff options
-rw-r--r-- | include/fud_c_string.hpp | 25 | ||||
-rw-r--r-- | include/fud_format.hpp | 21 | ||||
-rw-r--r-- | include/fud_string.hpp | 56 | ||||
-rw-r--r-- | include/fud_string_view.hpp | 6 | ||||
-rw-r--r-- | include/fud_utf8.hpp | 4 | ||||
-rw-r--r-- | source/fud_assert.cpp | 4 | ||||
-rw-r--r-- | source/fud_string.cpp | 117 | ||||
-rw-r--r-- | test/test_common.hpp | 30 | ||||
-rw-r--r-- | test/test_directory.cpp | 2 | ||||
-rw-r--r-- | test/test_format.cpp | 196 | ||||
-rw-r--r-- | test/test_string.cpp | 3 | ||||
-rw-r--r-- | test/test_utf8.cpp | 123 |
12 files changed, 310 insertions, 277 deletions
diff --git a/include/fud_c_string.hpp b/include/fud_c_string.hpp index 44e0dc8..d55ba30 100644 --- a/include/fud_c_string.hpp +++ b/include/fud_c_string.hpp @@ -50,6 +50,31 @@ constexpr ssize_t cStringLength(const char* str) return cStringLength(str, maxLength); } +constexpr ssize_t cStringLength(const char8_t* str, size_t maxLength) +{ + if (str == nullptr || maxLength > (SSIZE_MAX - 1)) { + return -1; + } + + ssize_t size = 0; + + while (str[size] != 0 && static_cast<size_t>(size) < maxLength) { + size++; + } + + if (str[size] != 0 && static_cast<size_t>(size) == maxLength) { + return static_cast<ssize_t>(maxLength) + 1; + } + + return size; +} + +constexpr ssize_t cStringLength(const char8_t* str) +{ + constexpr auto maxLength = SSIZE_MAX - 1; + return cStringLength(str, maxLength); +} + } // namespace fud #endif diff --git a/include/fud_format.hpp b/include/fud_format.hpp index c06643d..4d38c26 100644 --- a/include/fud_format.hpp +++ b/include/fud_format.hpp @@ -24,7 +24,7 @@ #include "fud_option.hpp" #include "fud_result.hpp" #include "fud_status.hpp" -#include "fud_string.hpp" +#include "fud_string.hpp" // IWYU pragma: keep #include "fud_string_convert.hpp" #include "fud_string_view.hpp" #include "fud_utf8.hpp" @@ -42,18 +42,18 @@ constexpr size_t maxIntCharCount = bitsPerOctal * sizeof(uint64_t) + 4; struct FormatString { template <size_t N> - consteval FormatString(const char (&input)[N]) : m_size{N - 1}, m_data{input} + consteval FormatString(const utf8 (&input)[N]) : m_size{N - 1}, m_data{input} { static_assert(N > 0); } StringView view() { - return StringView{m_size, reinterpret_cast<const utf8*>(m_data)}; + return StringView{m_size, m_data}; } size_t m_size; - const char* m_data; + const utf8* m_data; }; struct FormatAlign { @@ -1127,7 +1127,7 @@ void fillScientificBuffer(IntCharArray& buffer, Significand significand, uint8_t } } - forEach(Span<uint8_t>{buffer.data(), bufferLength}, [&](uint8_t digit) { + forEach(Span<utf8>{buffer.data(), bufferLength}, [&](uint8_t digit) { return static_cast<uint8_t>(digit + '0'); }); @@ -1485,17 +1485,6 @@ FormatResult format(Sink& sink, FormatCharMode formatMode, const FormatSpec& for return result; } -namespace fudTest { -inline void test() -{ - StringView prefix{0, ""}; - String sink{}; - - static_cast<void>(format(sink, FormatCharMode::Unchecked, "HELL YEAH")); - static_cast<void>(format(sink, FormatCharMode::Unchecked, "HELL YEAH", 1, true, "ye")); -} -} // namespace fudTest - } // namespace fud #endif diff --git a/include/fud_string.hpp b/include/fud_string.hpp index cdc6b91..226bb89 100644 --- a/include/fud_string.hpp +++ b/include/fud_string.hpp @@ -60,6 +60,7 @@ class String { * \returns FudStatus::AllocFailure if the allocator fails. */ static StringResult makeFromCString(const char* cString); + static StringResult makeFromCString(const char8_t* cString); /** \brief Create a string from a C String, specifying the allocator. * @@ -73,6 +74,7 @@ class String { * \returns FudStatus::AllocFailure if the allocator fails. */ static StringResult makeFromCString(const char* cString, Allocator* allocator); + static StringResult makeFromCString(const char8_t* cString, Allocator* allocator); /** \brief Create a string from concatenating multiple C Strings. * @@ -151,24 +153,15 @@ class String { String output{}; output.m_allocator = reinterpret_cast<uintptr_t>(allocator); utf8* data{nullptr}; - size_t capacity = totalLength + 1; - bool isLarge = capacity > SsoBufSize; + size_t outputCapacity = totalLength + 1; + bool isLarge = outputCapacity > SsoBufSize; if (isLarge) { - output.m_repr.large.capacity = capacity; - output.m_repr.large.length = totalLength; - auto dataResult = output.allocator()->allocate(output.m_repr.large.capacity); - if (dataResult.isError()) { - return StringResult::error(dataResult.getError()); + auto status = output.makeLarge(outputCapacity, totalLength, data); + if (status != FudStatus::Success) { + return StringResult::error(status); } - output.m_repr.large.data = static_cast<utf8*>(dataResult.getOkay()); - data = output.m_repr.large.data; - output.setLarge(); } else { - capacity = SsoBufSize; - static_assert(SsoBufSize < std::numeric_limits<int8_t>::max()); - output.m_repr.small.length = static_cast<uint8_t>(totalLength) & smallStringLengthMask; - data = output.m_repr.small.buffer.data(); - output.setSmall(); + output.makeSmall(outputCapacity, totalLength, data); } fudAssert(data != nullptr); @@ -176,7 +169,11 @@ class String { size_t cumulativeLength = 0; for (size_t idx = 0; idx < strPointers.size(); ++idx) { const auto* cString = strPointers[idx]; - auto copyStatus = copyMem(data + cumulativeLength, capacity - cumulativeLength, cString, lengths[idx]); + auto copyStatus = copyMem( + data + cumulativeLength, + outputCapacity - cumulativeLength, + cString, + lengths[idx]); fudAssert(copyStatus == FudStatus::Success); cumulativeLength += lengths[idx]; } @@ -368,28 +365,13 @@ class String { m_allocator &= allocatorMask; } - void addToLength(size_t augend) - { - if (isLarge()) { - fudAssert(m_repr.large.length + augend < maxStringLength); - m_repr.large.length += augend; - } else { - fudAssert(m_repr.small.length + augend < maxSmallStringLength); - m_repr.small.length = static_cast<decltype(m_repr.small.length)>((m_repr.small.length + augend)) & - smallStringLengthMask; - } - } + void addToLength(size_t augend); - void setLength(size_t newLength) - { - if (isLarge()) { - fudAssert(newLength < maxStringLength); - m_repr.large.length = newLength; - } else { - fudAssert(newLength < maxSmallStringLength); - m_repr.small.length = static_cast<uint8_t>(newLength) & smallStringLengthMask; - } - } + void setLength(size_t newLength); + + FudStatus makeLarge(size_t cap, size_t len, utf8*& outputData); + + void makeSmall(size_t& cap, size_t len, utf8*& outputData); }; } // namespace fud diff --git a/include/fud_string_view.hpp b/include/fud_string_view.hpp index 972630a..6403c27 100644 --- a/include/fud_string_view.hpp +++ b/include/fud_string_view.hpp @@ -30,6 +30,12 @@ namespace fud { class String; struct StringView { + template <size_t N> + consteval StringView(const utf8 (&input)[N]) : m_length{N - 1}, m_data{input} + { + static_assert(N > 0); + } + constexpr StringView() noexcept = default; constexpr StringView(const StringView& rhs) noexcept = default; diff --git a/include/fud_utf8.hpp b/include/fud_utf8.hpp index 3d53feb..414352f 100644 --- a/include/fud_utf8.hpp +++ b/include/fud_utf8.hpp @@ -29,7 +29,7 @@ namespace fud { -using utf8 = unsigned char; +using utf8 = char8_t; class String; struct StringView; @@ -385,7 +385,7 @@ struct FudUtf8 { } } - [[nodiscard]] constexpr const uint8_t* data() const noexcept + [[nodiscard]] constexpr const utf8* data() const noexcept { if (!valid()) { return nullptr; diff --git a/source/fud_assert.cpp b/source/fud_assert.cpp index e16f65e..7838e22 100644 --- a/source/fud_assert.cpp +++ b/source/fud_assert.cpp @@ -18,7 +18,7 @@ #include "fud_assert.hpp" #include "fud_format.hpp" -#include "fud_string.hpp" // DrainResult +#include "fud_drain.hpp" #include "fud_string_view.hpp" #include <cstdio> @@ -64,7 +64,7 @@ void assertFailMessage(const char* assertion, const std::source_location sourceL static_cast<void>(format( sink, FormatCharMode::Unchecked, - "{}:{}:{}: {}\n", + u8"{}:{}:{}: {}\n", fileName, functionName, sourceLocation.line(), diff --git a/source/fud_string.cpp b/source/fud_string.cpp index edb25da..058c813 100644 --- a/source/fud_string.cpp +++ b/source/fud_string.cpp @@ -23,11 +23,20 @@ namespace fud { +StringResult String::makeFromCString(const char8_t* cString) { + return makeFromCString(reinterpret_cast<const char*>(cString)); +} + StringResult String::makeFromCString(const char* cString) { return makeFromCString(cString, &globalFudAllocator); } +StringResult String::makeFromCString(const char8_t* cString, Allocator* allocator) +{ + return makeFromCString(reinterpret_cast<const char*>(cString), allocator); +} + StringResult String::makeFromCString(const char* cString, Allocator* allocator) { if (allocator == nullptr) { @@ -59,7 +68,7 @@ StringResult String::makeFromCString(const char* cString, Allocator* allocator) if (isLarge) { output.m_repr.large.capacity = capacity; output.m_repr.large.length = length; - auto dataResult = output.allocator()->allocate(output.m_repr.large.capacity); + auto dataResult = output.allocator()->allocate(capacity); if (dataResult.isError()) { return StringResult::error(dataResult.getError()); } @@ -69,7 +78,7 @@ StringResult String::makeFromCString(const char* cString, Allocator* allocator) } else { capacity = SsoBufSize; static_assert(SsoBufSize < std::numeric_limits<int8_t>::max()); - output.m_repr.small.length = static_cast<uint8_t>(length) & smallStringLengthMask; + output.m_repr.small.length = length & smallStringLengthMask; data = output.m_repr.small.buffer.data(); output.setSmall(); } @@ -136,24 +145,19 @@ StringResult String::from(StringView view, Allocator* allocator) String output{}; output.m_allocator = reinterpret_cast<uintptr_t>(allocator); - size_t capacity = view.length() + 1U; - bool isLarge = capacity > SsoBufSize; + size_t outputCapacity = view.length() + 1U; + bool isLarge = outputCapacity > SsoBufSize; utf8* data{nullptr}; if (isLarge) { - output.m_repr.large.capacity = capacity; - output.m_repr.large.length = view.length(); - output.m_repr.large.data = static_cast<utf8*>(M_TakeOrReturn(StringResult, output.allocator()->allocate(capacity))); - data = output.m_repr.large.data; - output.setLarge(); + auto status = output.makeLarge(outputCapacity, view.length(), data); + if (status != FudStatus::Success) { + return StringResult::error(status); + } } else { - capacity = SsoBufSize; - static_assert(SsoBufSize < std::numeric_limits<int8_t>::max()); - output.m_repr.small.length = static_cast<uint8_t>(view.length()) & smallStringLengthMask; - data = output.m_repr.small.buffer.data(); - output.setSmall(); + output.makeSmall(outputCapacity, view.length(), data); } fudAssert(data != nullptr); - auto copyStatus = copyMem(data, capacity, view.m_data, view.length()); + auto copyStatus = copyMem(data, outputCapacity, view.m_data, view.length()); fudAssert(copyStatus == FudStatus::Success); auto terminateStatus = output.nullTerminate(); @@ -630,21 +634,12 @@ StringResult String::catenate(const char* rhs) const size_t outputCapacity = outputLength + 1; utf8* outputData{nullptr}; if (outputCapacity > SsoBufSize) { - output.m_repr.large.capacity = outputCapacity; - output.m_repr.large.length = outputLength; - auto dataResult = output.allocator()->allocate(output.m_repr.large.capacity); - if (dataResult.isError()) { - return StringResult::error(dataResult.getError()); + auto status = output.makeLarge(outputCapacity, outputLength, outputData); + if (status != FudStatus::Success) { + return StringResult::error(status); } - output.m_repr.large.data = static_cast<utf8*>(dataResult.getOkay()); - output.setLarge(); - outputData = output.m_repr.large.data; } else { - outputCapacity = SsoBufSize; - static_assert(SsoBufSize < std::numeric_limits<int8_t>::max()); - output.setSmall(); - output.m_repr.small.length = static_cast<uint8_t>(outputLength) & smallStringLengthMask; - outputData = output.m_repr.small.buffer.data(); + output.makeSmall(outputCapacity, outputLength, outputData); } fudAssert(outputData != nullptr); @@ -674,24 +669,15 @@ StringResult String::catenate(const String& rhs) const String output{}; output.m_allocator = m_allocator; size_t outputLength = length() + rhs.length(); - size_t outputCapacity = outputLength + 1; + size_t outputCapacity = outputLength + 1; utf8* outputData{nullptr}; if (outputCapacity > SsoBufSize) { - output.m_repr.large.capacity = outputCapacity; - output.m_repr.large.length = outputLength; - auto dataResult = output.allocator()->allocate(output.m_repr.large.capacity); - if (dataResult.isError()) { - return StringResult::error(dataResult.getError()); + auto status = output.makeLarge(outputCapacity, outputLength, outputData); + if (status != FudStatus::Success) { + return StringResult::error(status); } - output.m_repr.large.data = static_cast<utf8*>(dataResult.getOkay()); - output.setLarge(); - outputData = output.m_repr.large.data; } else { - outputCapacity = SsoBufSize; - static_assert(SsoBufSize < std::numeric_limits<int8_t>::max()); - output.setSmall(); - output.m_repr.small.length = static_cast<uint8_t>(outputLength) & smallStringLengthMask; - outputData = output.m_repr.small.buffer.data(); + output.makeSmall(outputCapacity, outputLength, outputData); } auto status = copyMem(outputData, outputCapacity, data(), length()); @@ -750,4 +736,51 @@ const utf8* String::end() const return data() + size(); } +void String::addToLength(size_t augend) +{ + if (isLarge()) { + fudAssert(m_repr.large.length + augend < maxStringLength); + m_repr.large.length += augend; + } else { + fudAssert(m_repr.small.length + augend < maxSmallStringLength); + m_repr.small.length = static_cast<decltype(m_repr.small.length)>((m_repr.small.length + augend)) & + smallStringLengthMask; + } +} + +void String::setLength(size_t newLength) +{ + if (isLarge()) { + fudAssert(newLength < maxStringLength); + m_repr.large.length = newLength; + } else { + fudAssert(newLength < maxSmallStringLength); + m_repr.small.length = static_cast<uint8_t>(newLength) & smallStringLengthMask; + } +} + +FudStatus String::makeLarge(size_t cap, size_t len, utf8*& outputData) +{ + m_repr.large.capacity = cap; + m_repr.large.length = len; + auto dataResult = allocator()->allocate(cap); + if (dataResult.isError()) { + return dataResult.getError(); + } + m_repr.large.data = static_cast<utf8*>(dataResult.getOkay()); + outputData = m_repr.large.data; + setLarge(); + return FudStatus::Success; +} + +void String::makeSmall(size_t& cap, size_t len, utf8*& outputData) +{ + fudAssert(len < SsoBufSize); + cap = SsoBufSize; + static_assert(SsoBufSize < std::numeric_limits<int8_t>::max()); + m_repr.small.length = len & smallStringLengthMask; + outputData = m_repr.small.buffer.data(); + setSmall(); +} + } // namespace fud diff --git a/test/test_common.hpp b/test/test_common.hpp index 3d7ecba..fd16364 100644 --- a/test/test_common.hpp +++ b/test/test_common.hpp @@ -30,31 +30,31 @@ int unlink_cb(const char* fpath, const struct stat* sb_unused, int typeflag, str namespace fud { // NOLINTBEGIN(cppcoreguidelines-macro-usage) -#define MULTI_BYTE_LITERAL "test今日素敵はですねƩ®😀z" +#define MULTI_BYTE_LITERAL u8"test今日素敵はですねƩ®😀z" static_assert(sizeof(MULTI_BYTE_LITERAL) == 38); // NOLINT(readability-magic-numbers) -#define TWO_BYTE "Ʃ" +#define TWO_BYTE u8"Ʃ" static_assert(sizeof(TWO_BYTE) == 2 + 1); -#define THREE_BYTE "今" +#define THREE_BYTE u8"今" static_assert(sizeof(THREE_BYTE) == 3 + 1); -#define FOUR_BYTE "😀" +#define FOUR_BYTE u8"😀" static_assert(sizeof(FOUR_BYTE) == 4 + 1); -#define CHQUOTE "why waste time learning, when ignorance is instantaneous?" +#define CHQUOTE u8"why waste time learning, when ignorance is instantaneous?" -#define LOWERCASE_CHARS "abcdefghijklmnopqrstuvwxyz" -#define UPPERCASE_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -#define DECIMAL_CHARS "0123456789" -#define HEX_LOWER "abcdef" -#define HEX_UPPER "ABCDEF" +#define LOWERCASE_CHARS u8"abcdefghijklmnopqrstuvwxyz" +#define UPPERCASE_CHARS u8"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define DECIMAL_CHARS u8"0123456789" +#define HEX_LOWER u8"abcdef" +#define HEX_UPPER u8"ABCDEF" #define HEX_CHARS HEX_LOWER HEX_UPPER DECIMAL_CHARS #define ALPHA_CHARS LOWERCASE_CHARS UPPERCASE_CHARS #define ALPHA_NUMERIC_CHARS ALPHA_CHARS DECIMAL_CHARS -#define PUNCTUATION_CHARS "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" +#define PUNCTUATION_CHARS u8"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" #define GRAPHICAL_CHARS ALPHA_NUMERIC_CHARS PUNCTUATION_CHARS -#define BLANK_CHARS " \t" -#define SPACE_CHARS BLANK_CHARS "\v\r\n" -#define PRINTABLE_CHARS " " LOWERCASE_CHARS UPPERCASE_CHARS DECIMAL_CHARS PUNCTUATION_CHARS -#define CHARACTER_SET LOWERCASE_CHARS " " UPPERCASE_CHARS +#define BLANK_CHARS u8" \t" +#define SPACE_CHARS BLANK_CHARS u8"\v\r\n" +#define PRINTABLE_CHARS u8" " LOWERCASE_CHARS UPPERCASE_CHARS DECIMAL_CHARS PUNCTUATION_CHARS +#define CHARACTER_SET LOWERCASE_CHARS u8" " UPPERCASE_CHARS // NOLINTEND(cppcoreguidelines-macro-usage) constexpr size_t charSetSize = sizeof(CHARACTER_SET) - 1; diff --git a/test/test_directory.cpp b/test/test_directory.cpp index 58efc13..ba1c0e1 100644 --- a/test/test_directory.cpp +++ b/test/test_directory.cpp @@ -59,7 +59,7 @@ TEST(FudDirectory, Basic) ASSERT_TRUE(fileResult.isOkay()); CBinaryFile file{std::move(fileResult).takeOkay()}; ASSERT_EQ(file.open(), FudStatus::Success); - Array<utf8, 5> data{"test"}; + Array<utf8, 5> data{u8"test"}; WriteResult expected{data.size(), FudStatus::Success}; auto writeResult = file.write(data); ASSERT_EQ(writeResult.bytesWritten, expected.bytesWritten); diff --git a/test/test_format.cpp b/test/test_format.cpp index 4dec6b1..b9d373c 100644 --- a/test/test_format.cpp +++ b/test/test_format.cpp @@ -27,20 +27,20 @@ TEST(FormatTest, BasePositionalTest) { size_t length = 0; - auto formatSpecResult = FormatSpec::parse(StringView{" {1:}"}, length); + auto formatSpecResult = FormatSpec::parse(StringView{u8" {1:}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.takeError(), FudStatus::ArgumentInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{1}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); auto formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(formatSpec.position, 1); EXPECT_EQ(length, 3); - formatSpecResult = FormatSpec::parse(StringView{""}, length); + formatSpecResult = FormatSpec::parse(StringView{u8""}, length); ASSERT_EQ(formatSpecResult.takeErrorOr(FudStatus::NotImplemented), FudStatus::ArgumentInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{1:}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 4); @@ -60,7 +60,7 @@ TEST(FormatTest, AlignTest) { size_t length = 0; - auto formatSpecResult = FormatSpec::parse(StringView{"{1:<}"}, length); + auto formatSpecResult = FormatSpec::parse(StringView{u8"{1:<}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); auto formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(formatSpec.position, 1); @@ -74,14 +74,14 @@ TEST(FormatTest, AlignTest) EXPECT_FALSE(formatSpec.hasLocale); EXPECT_EQ(formatSpec.formatType, FormatType::Unspecified); - formatSpecResult = FormatSpec::parse(StringView{"{1:<<}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:<<}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(formatSpec.position, 1); EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); EXPECT_EQ(formatSpec.fill.fill, '<'); - formatSpecResult = FormatSpec::parse(StringView{"{:<<}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:<<}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 5); @@ -89,7 +89,7 @@ TEST(FormatTest, AlignTest) EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); EXPECT_EQ(formatSpec.fill.fill, '<'); - formatSpecResult = FormatSpec::parse(StringView{"{1:_<}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:_<}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 6); @@ -102,7 +102,7 @@ TEST(FormatTest, SpecialTest) { size_t length = 0; - auto formatSpecResult = FormatSpec::parse(StringView{"{1:_< }"}, length); + auto formatSpecResult = FormatSpec::parse(StringView{u8"{1:_< }"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); auto formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 7); @@ -113,7 +113,7 @@ TEST(FormatTest, SpecialTest) EXPECT_FALSE(formatSpec.alternateForm); EXPECT_FALSE(formatSpec.leadingZero); - formatSpecResult = FormatSpec::parse(StringView{"{1:+}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:+}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); EXPECT_EQ(length, 5); formatSpec = formatSpecResult.takeOkay(); @@ -122,7 +122,7 @@ TEST(FormatTest, SpecialTest) EXPECT_FALSE(formatSpec.alternateForm); EXPECT_FALSE(formatSpec.leadingZero); - formatSpecResult = FormatSpec::parse(StringView{"{1:-}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:-}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 5); @@ -131,7 +131,7 @@ TEST(FormatTest, SpecialTest) EXPECT_FALSE(formatSpec.alternateForm); EXPECT_FALSE(formatSpec.leadingZero); - formatSpecResult = FormatSpec::parse(StringView{"{1:_<#}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:_<#}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 7); @@ -142,7 +142,7 @@ TEST(FormatTest, SpecialTest) EXPECT_TRUE(formatSpec.alternateForm); EXPECT_FALSE(formatSpec.leadingZero); - formatSpecResult = FormatSpec::parse(StringView{"{1:_<0}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:_<0}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 7); @@ -153,7 +153,7 @@ TEST(FormatTest, SpecialTest) EXPECT_FALSE(formatSpec.alternateForm); EXPECT_TRUE(formatSpec.leadingZero); - formatSpecResult = FormatSpec::parse(StringView{"{1: #}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1: #}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 6); @@ -164,15 +164,15 @@ TEST(FormatTest, SpecialTest) EXPECT_TRUE(formatSpec.alternateForm); EXPECT_FALSE(formatSpec.leadingZero); - formatSpecResult = FormatSpec::parse(StringView{"{1:# }"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:# }"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{1:##}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:##}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{1: 0}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1: 0}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 6); @@ -183,19 +183,19 @@ TEST(FormatTest, SpecialTest) EXPECT_FALSE(formatSpec.alternateForm); EXPECT_TRUE(formatSpec.leadingZero); - formatSpecResult = FormatSpec::parse(StringView{"{1:0 }"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:0 }"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{1:0#}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:0#}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{1:#00}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:#00}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{1: #0}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1: #0}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 7); @@ -211,7 +211,7 @@ TEST(FormatTest, WidthTest) { size_t length = 0; - auto formatSpecResult = FormatSpec::parse(StringView{"{1:1}"}, length); + auto formatSpecResult = FormatSpec::parse(StringView{u8"{1:1}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); auto formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 5); @@ -219,7 +219,7 @@ TEST(FormatTest, WidthTest) EXPECT_FALSE(formatSpec.takesWidth); EXPECT_EQ(formatSpec.width, 1); - formatSpecResult = FormatSpec::parse(StringView{"{1:543}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:543}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 7); @@ -227,7 +227,7 @@ TEST(FormatTest, WidthTest) EXPECT_FALSE(formatSpec.takesWidth); EXPECT_EQ(formatSpec.width, 543); - formatSpecResult = FormatSpec::parse(StringView{"{:543}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:543}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 6); @@ -236,16 +236,16 @@ TEST(FormatTest, WidthTest) EXPECT_EQ(formatSpec.width, 543); // leading zero - formatSpecResult = FormatSpec::parse(StringView{"{1:00}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:00}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); // #x100000000 4294967296 - formatSpecResult = FormatSpec::parse(StringView{"{1:4294967296}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:4294967296}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); - formatSpecResult = FormatSpec::parse(StringView{"{1:{1}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:{1}}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 7); @@ -254,15 +254,15 @@ TEST(FormatTest, WidthTest) EXPECT_EQ(formatSpec.width, 1); // #x10000 65536 - formatSpecResult = FormatSpec::parse(StringView{"{1:{65536}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:{65536}}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); - formatSpecResult = FormatSpec::parse(StringView{"{:{1}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:{1}}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{:{}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:{}}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 5); @@ -275,7 +275,7 @@ TEST(FormatTest, PrecisionTest) { size_t length = 0; - auto formatSpecResult = FormatSpec::parse(StringView{"{1:.1}"}, length); + auto formatSpecResult = FormatSpec::parse(StringView{u8"{1:.1}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); auto formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 6); @@ -283,7 +283,7 @@ TEST(FormatTest, PrecisionTest) EXPECT_FALSE(formatSpec.takesPrecision); EXPECT_EQ(formatSpec.precision, 1); - formatSpecResult = FormatSpec::parse(StringView{"{1:.543}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:.543}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 8); @@ -291,7 +291,7 @@ TEST(FormatTest, PrecisionTest) EXPECT_FALSE(formatSpec.takesPrecision); EXPECT_EQ(formatSpec.precision, 543); - formatSpecResult = FormatSpec::parse(StringView{"{:.543}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:.543}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 7); @@ -300,16 +300,16 @@ TEST(FormatTest, PrecisionTest) EXPECT_EQ(formatSpec.precision, 543); // leading zero - formatSpecResult = FormatSpec::parse(StringView{"{1:00}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:00}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); // #x100000000 4294967296 - formatSpecResult = FormatSpec::parse(StringView{"{1:.4294967296}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:.4294967296}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); - formatSpecResult = FormatSpec::parse(StringView{"{1:.{1}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:.{1}}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 8); @@ -318,15 +318,15 @@ TEST(FormatTest, PrecisionTest) EXPECT_EQ(formatSpec.precision, 1); // #x10000 65536 - formatSpecResult = FormatSpec::parse(StringView{"{1:.{65536}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{1:.{65536}}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); - formatSpecResult = FormatSpec::parse(StringView{"{:.{1}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:.{1}}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); - formatSpecResult = FormatSpec::parse(StringView{"{:.{}}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:.{}}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 6); @@ -339,14 +339,14 @@ TEST(FormatTest, LocaleTest) { size_t length = 0; - auto formatSpecResult = FormatSpec::parse(StringView{"{1:L}"}, length); + auto formatSpecResult = FormatSpec::parse(StringView{u8"{1:L}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); auto formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 5); EXPECT_EQ(formatSpec.position, 1); EXPECT_TRUE(formatSpec.hasLocale); - formatSpecResult = FormatSpec::parse(StringView{"{:L}"}, length); + formatSpecResult = FormatSpec::parse(StringView{u8"{:L}"}, length); ASSERT_TRUE(formatSpecResult.isOkay()); formatSpec = formatSpecResult.takeOkay(); EXPECT_EQ(length, 4); @@ -358,23 +358,23 @@ TEST(FormatTest, FormatTest) { auto lengthArray{Array<size_t, 17>::constFill(0U)}; const Array<FormatSpecResult, 17> formatTypeResults{ - FormatSpec::parse(StringView{"{:s}"}, lengthArray[0x00]), - FormatSpec::parse(StringView{"{:?}"}, lengthArray[0x01]), - FormatSpec::parse(StringView{"{:b}"}, lengthArray[0x02]), - FormatSpec::parse(StringView{"{:B}"}, lengthArray[0x03]), - FormatSpec::parse(StringView{"{:c}"}, lengthArray[0x04]), - FormatSpec::parse(StringView{"{:d}"}, lengthArray[0x05]), - FormatSpec::parse(StringView{"{:o}"}, lengthArray[0x06]), - FormatSpec::parse(StringView{"{:x}"}, lengthArray[0x07]), - FormatSpec::parse(StringView{"{:X}"}, lengthArray[0x08]), - FormatSpec::parse(StringView{"{:a}"}, lengthArray[0x09]), - FormatSpec::parse(StringView{"{:A}"}, lengthArray[0x0A]), - FormatSpec::parse(StringView{"{:e}"}, lengthArray[0x0B]), - FormatSpec::parse(StringView{"{:E}"}, lengthArray[0x0C]), - FormatSpec::parse(StringView{"{:f}"}, lengthArray[0x0D]), - FormatSpec::parse(StringView{"{:F}"}, lengthArray[0x0E]), - FormatSpec::parse(StringView{"{:g}"}, lengthArray[0x0F]), - FormatSpec::parse(StringView{"{:G}"}, lengthArray[0x10])}; + FormatSpec::parse(StringView{u8"{:s}"}, lengthArray[0x00]), + FormatSpec::parse(StringView{u8"{:?}"}, lengthArray[0x01]), + FormatSpec::parse(StringView{u8"{:b}"}, lengthArray[0x02]), + FormatSpec::parse(StringView{u8"{:B}"}, lengthArray[0x03]), + FormatSpec::parse(StringView{u8"{:c}"}, lengthArray[0x04]), + FormatSpec::parse(StringView{u8"{:d}"}, lengthArray[0x05]), + FormatSpec::parse(StringView{u8"{:o}"}, lengthArray[0x06]), + FormatSpec::parse(StringView{u8"{:x}"}, lengthArray[0x07]), + FormatSpec::parse(StringView{u8"{:X}"}, lengthArray[0x08]), + FormatSpec::parse(StringView{u8"{:a}"}, lengthArray[0x09]), + FormatSpec::parse(StringView{u8"{:A}"}, lengthArray[0x0A]), + FormatSpec::parse(StringView{u8"{:e}"}, lengthArray[0x0B]), + FormatSpec::parse(StringView{u8"{:E}"}, lengthArray[0x0C]), + FormatSpec::parse(StringView{u8"{:f}"}, lengthArray[0x0D]), + FormatSpec::parse(StringView{u8"{:F}"}, lengthArray[0x0E]), + FormatSpec::parse(StringView{u8"{:g}"}, lengthArray[0x0F]), + FormatSpec::parse(StringView{u8"{:G}"}, lengthArray[0x10])}; const Array<FormatType, 17> formatTypes{ FormatType::String, FormatType::Escaped, @@ -406,7 +406,7 @@ TEST(FormatTest, FormatTest) size_t length = 0; - auto formatSpecResult = FormatSpec::parse(StringView{"{:N}"}, length); + auto formatSpecResult = FormatSpec::parse(StringView{u8"{:N}"}, length); ASSERT_TRUE(formatSpecResult.isError()); EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); } @@ -415,13 +415,13 @@ TEST(FormatTest, NoArgFormatTest) { String sink{}; auto expected = std::format("Test"); - auto formatResult = format(sink, FormatCharMode::Unchecked, "Test"); + auto formatResult = format(sink, FormatCharMode::Unchecked, u8"Test"); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format(""); - formatResult = format(sink, FormatCharMode::Unchecked, ""); + formatResult = format(sink, FormatCharMode::Unchecked, u8""); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); } @@ -429,66 +429,66 @@ TEST(FormatTest, NoArgFormatTest) TEST(FormatTest, OneNumberFormatTest) { String sink{}; - auto formatResult = format(sink, FormatCharMode::Unchecked, "Test {:}", 42U); + auto formatResult = format(sink, FormatCharMode::Unchecked, u8"Test {:}", 42U); EXPECT_TRUE(formatResult.isOkay()); ASSERT_EQ(sink.clear(), FudStatus::Success); auto expected = std::format("{:6}", 42U); - formatResult = format(sink, FormatCharMode::Unchecked, "{:6}", 42U); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:6}", 42U); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:*<6}", std::numeric_limits<uint64_t>::max()); - formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", std::numeric_limits<uint64_t>::max()); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:*<6}", std::numeric_limits<uint64_t>::max()); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:*<6}", std::numeric_limits<int64_t>::min()); - formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", std::numeric_limits<int64_t>::min()); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:*<6}", std::numeric_limits<int64_t>::min()); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:}", std::numeric_limits<int8_t>::min()); - formatResult = format(sink, FormatCharMode::Unchecked, "{:}", std::numeric_limits<int8_t>::min()); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:}", std::numeric_limits<int8_t>::min()); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:#X}", std::numeric_limits<int8_t>::min()); - formatResult = format(sink, FormatCharMode::Unchecked, "{:#X}", std::numeric_limits<int8_t>::min()); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:#X}", std::numeric_limits<int8_t>::min()); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:*<6}", 42U); - formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", 42U); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:*<6}", 42U); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:*>6}", 42U); - formatResult = format(sink, FormatCharMode::Unchecked, "{:*>6}", 42U); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:*>6}", 42U); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:*^6}", 42U); - formatResult = format(sink, FormatCharMode::Unchecked, "{:*^6}", 42U); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:*^6}", 42U); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:*<6}", 'x'); - formatResult = format(sink, FormatCharMode::Unchecked, "{:*<6}", 'x'); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:*<6}", 'x'); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:6d}", 'x'); - formatResult = format(sink, FormatCharMode::Unchecked, "{:6d}", 'x'); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:6d}", 'x'); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); } @@ -499,7 +499,7 @@ TEST(FormatTest, OneBoolFormatTest) ASSERT_EQ(sink.clear(), FudStatus::Success); auto expected = std::format("{:6}", true); - auto formatResult = format(sink, FormatCharMode::Unchecked, "{:6}", true); + auto formatResult = format(sink, FormatCharMode::Unchecked, u8"{:6}", true); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); } @@ -511,13 +511,13 @@ TEST(FormatTest, OneFloatFormatUnspecifiedTest) ASSERT_EQ(sink.clear(), FudStatus::Success); auto expected = std::format("{:}", 42.0); - auto formatResult = format(sink, FormatCharMode::Unchecked, "{:}", 42.0); + auto formatResult = format(sink, FormatCharMode::Unchecked, u8"{:}", 42.0); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("{:1.0}", 42.0); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.0}", 42.0); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0}", 42.0); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.0}", 42.0); @@ -535,73 +535,73 @@ TEST(FormatTest, OneFloatFormatScientificTest) ASSERT_EQ(sink.clear(), FudStatus::Success); auto expected = std::format("{:e}", 42.0); - auto formatResult = format(sink, FormatCharMode::Unchecked, "{:e}", 42.0); + auto formatResult = format(sink, FormatCharMode::Unchecked, u8"{:e}", 42.0); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.2e}", 0.99); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.2e}", 0.99); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.2e}", 0.99); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.1e}", 0.99); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.1e}", 0.99); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.1e}", 0.99); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.0e}", 0.99); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.0e}", 0.99); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0e}", 0.99); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.0e}", -0.99); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.0e}", -0.99); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0e}", -0.99); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.0e}", 42.0); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.0e}", 42.0); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0e}", 42.0); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.0e}", 4.20e-5); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.0e}", 4.20e-5); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0e}", 4.20e-5); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("{:1.0e}", -4.20e-5); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "{:1.0e}", -4.20e-5); + formatResult = format(sink, FormatCharMode::Unchecked, u8"{:1.0e}", -4.20e-5); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("e {:e}", 3.14); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:e}", 3.14); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:e}", 3.14); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("E {:E}", 3.14); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "E {:E}", 3.14); + formatResult = format(sink, FormatCharMode::Unchecked, u8"E {:E}", 3.14); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("e {:.0e}", 3.14); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:.0e}", 3.14); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:.0e}", 3.14); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("e {:+#010.0e}", 3.14); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:+#010.0e}", 3.14); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:+#010.0e}", 3.14); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); @@ -610,31 +610,31 @@ TEST(FormatTest, OneFloatFormatScientificTest) expected = std::format("e {:.0e}", maxVal / 4); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:.0e}", maxVal / 4); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:.0e}", maxVal / 4); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("e {:.0e}", maxVal / 2); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:.0e}", maxVal / 2); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:.0e}", maxVal / 2); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("e {:.0e}", maxVal); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:.0e}", maxVal); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:.0e}", maxVal); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("e {:.0e}", std::numeric_limits<double>::min()); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:.0e}", std::numeric_limits<double>::min()); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:.0e}", std::numeric_limits<double>::min()); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("e {:.0e}", subNormMin); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "e {:.0e}", subNormMin); + formatResult = format(sink, FormatCharMode::Unchecked, u8"e {:.0e}", subNormMin); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); @@ -642,7 +642,7 @@ TEST(FormatTest, OneFloatFormatScientificTest) expected = std::format("E#+ {:+#060.50E}", val); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "E#+ {:+#060.50E}", val); + formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:+#060.50E}", val); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); // Which is: "E#+ +0003.0000000000000000000000000000000000E+00" @@ -651,19 +651,19 @@ TEST(FormatTest, OneFloatFormatScientificTest) /* expected = std::format("E#+ {:Z>+#060.30E}", val); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "E#+ {:Z>+#060.30E}", val); + formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z>+#060.30E}", val); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("E#+ {:Z<+#060.30E}", val); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "E#+ {:Z<+#060.30E}", val); + formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z<+#060.30E}", val); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); expected = std::format("E#+ {:Z^+#060.30E}", val); ASSERT_EQ(sink.clear(), FudStatus::Success); - formatResult = format(sink, FormatCharMode::Unchecked, "E#+ {:Z^+#060.30E}", val); + formatResult = format(sink, FormatCharMode::Unchecked, u8"E#+ {:Z^+#060.30E}", val); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); */ @@ -698,13 +698,13 @@ TEST(FormatTest, TwoArgFormatTest) { String sink{}; auto expected = std::format("Test {:} {:}", 1U, false); - auto formatResult = format(sink, FormatCharMode::Unchecked, "Test {:} {:}", 1U, false); + auto formatResult = format(sink, FormatCharMode::Unchecked, u8"Test {:} {:}", 1U, false); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); ASSERT_EQ(sink.clear(), FudStatus::Success); expected = std::format("Test {:} {:}", 1U, "Hello"); - formatResult = format(sink, FormatCharMode::Unchecked, "Test {:} {:}", 1U, "Hello"); + formatResult = format(sink, FormatCharMode::Unchecked, u8"Test {:} {:}", 1U, u8"Hello"); EXPECT_TRUE(formatResult.isOkay()); EXPECT_STREQ(sink.c_str(), expected.c_str()); } diff --git a/test/test_string.cpp b/test/test_string.cpp index 54e3802..9f5b24e 100644 --- a/test/test_string.cpp +++ b/test/test_string.cpp @@ -25,7 +25,8 @@ namespace fud { TEST(FudString, CStringLength) { - ASSERT_EQ(cStringLength(nullptr), -1); + const char* nullPointer = nullPointer; + ASSERT_EQ(cStringLength(nullPointer), -1); ASSERT_EQ(cStringLength(""), 0); ASSERT_EQ(cStringLength("a"), 1); ASSERT_EQ(cStringLength(MULTI_BYTE_LITERAL), sizeof(MULTI_BYTE_LITERAL) - 1); diff --git a/test/test_utf8.cpp b/test/test_utf8.cpp index 8c3cad2..591d1a3 100644 --- a/test/test_utf8.cpp +++ b/test/test_utf8.cpp @@ -203,9 +203,6 @@ TEST(Utf8Test, Utf8MultiByte) EXPECT_EQ(character.size(), multiByteCharacters[idx].size()); EXPECT_EQ(character, multiByteCharacters[idx]); EXPECT_TRUE(multiByteCharacters[idx].valid()); - if (character != multiByteCharacters[idx]) { - printf("idx = %zu, %.*s\n", idx, static_cast<int>(character.size()), character.data()); - } idx++; } characterOpt = utf8Iter.next(); @@ -265,14 +262,14 @@ struct SpanGenerator { TEST(Utf8Test, Utf8IsAlphanumeric) { constexpr size_t numAlphanumericChars = 26 * 2 + 10; - Array<char, numAlphanumericChars + 1> alphanumericCharLiteral{ALPHA_NUMERIC_CHARS}; - Array<char, numAlphanumericChars> alphanumericChars{}; + Array<utf8, numAlphanumericChars + 1> alphanumericCharLiteral{ALPHA_NUMERIC_CHARS}; + Array<utf8, numAlphanumericChars> alphanumericChars{}; copyMem<numAlphanumericChars>(alphanumericChars, alphanumericCharLiteral); ASSERT_TRUE(allOf(alphanumericChars.span(), static_cast<CharPredicate>(isAlphanumeric))); constexpr size_t numNonAlphanumericChars = validAsciiSize - numAlphanumericChars; - Vector<char> nonAlphanumericChars{}; + Vector<utf8> nonAlphanumericChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { if (!isAlphanumeric(idx)) { ASSERT_EQ(nonAlphanumericChars.pushBack(idx), FudStatus::Success); @@ -291,11 +288,11 @@ TEST(Utf8Test, Utf8IsAlphanumeric) []() { return Array<utf8, invalidAsciiSize>{}; }, [&]() { return iotaGenerator().map([](auto val) { return static_cast<utf8>(val); }); }); - SpanGenerator<char, alphanumericChars.size()> alphanumericGenerator{alphanumericChars.span()}; + SpanGenerator<utf8, alphanumericChars.size()> alphanumericGenerator{alphanumericChars.span()}; auto utf8AlphanumericGenerator = [&]() { return alphanumericGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8AlphanumericGenerator, static_cast<FudUtf8Predicate>(isAlphanumeric))); - SpanGenerator<char> nonAlphanumericGenerator{nonAlphanumericChars.span().takeOkay()}; + SpanGenerator<utf8> nonAlphanumericGenerator{nonAlphanumericChars.span().takeOkay()}; auto utf8NonAlphanumericGenerator = [&]() { return nonAlphanumericGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonAlphanumericGenerator, static_cast<FudUtf8Predicate>(isAlphanumeric))); } @@ -303,14 +300,14 @@ TEST(Utf8Test, Utf8IsAlphanumeric) TEST(Utf8Test, Utf8IsAlpha) { constexpr size_t numAlphaChars = sizeof(ALPHA_CHARS) - 1; - Array<char, numAlphaChars + 1> alphaCharLiteral{ALPHA_CHARS}; - Array<char, numAlphaChars> alphaChars{}; + Array<utf8, numAlphaChars + 1> alphaCharLiteral{ALPHA_CHARS}; + Array<utf8, numAlphaChars> alphaChars{}; copyMem<numAlphaChars>(alphaChars, alphaCharLiteral); ASSERT_TRUE(allOf(alphaChars.span(), static_cast<CharPredicate>(isAlpha))); constexpr size_t numNonAlphanumericChars = validAsciiSize - numAlphaChars; - Vector<char> nonAlphaChars{}; + Vector<utf8> nonAlphaChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { if (!isAlphanumeric(idx)) { ASSERT_EQ(nonAlphaChars.pushBack(idx), FudStatus::Success); @@ -323,11 +320,11 @@ TEST(Utf8Test, Utf8IsAlpha) ASSERT_FALSE(isAlpha(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, alphaChars.size()> alphaGenerator{alphaChars.span()}; + SpanGenerator<utf8, alphaChars.size()> alphaGenerator{alphaChars.span()}; auto utf8AlphaGenerator = [&]() { return alphaGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8AlphaGenerator, static_cast<FudUtf8Predicate>(isAlpha))); - SpanGenerator<char> nonAlphaGenerator{nonAlphaChars.span().takeOkay()}; + SpanGenerator<utf8> nonAlphaGenerator{nonAlphaChars.span().takeOkay()}; auto utf8NonAlphaGenerator = [&]() { return nonAlphaGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonAlphaGenerator, static_cast<FudUtf8Predicate>(isAlpha))); } @@ -335,14 +332,14 @@ TEST(Utf8Test, Utf8IsAlpha) TEST(Utf8Test, Utf8IsLower) { constexpr size_t numLowerChars = 26; - Array<char, numLowerChars + 1> lowerCharLiteral{LOWERCASE_CHARS}; - Array<char, numLowerChars> lowerChars{}; + Array<utf8, numLowerChars + 1> lowerCharLiteral{LOWERCASE_CHARS}; + Array<utf8, numLowerChars> lowerChars{}; copyMem<numLowerChars>(lowerChars, lowerCharLiteral); ASSERT_TRUE(allOf(lowerChars.span(), static_cast<CharPredicate>(isLowercase))); constexpr size_t numNonLowerChars = validAsciiSize - numLowerChars; - Vector<char> nonLowerChars{}; + Vector<utf8> nonLowerChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { if (!isLowercase(idx)) { ASSERT_EQ(nonLowerChars.pushBack(idx), FudStatus::Success); @@ -355,11 +352,11 @@ TEST(Utf8Test, Utf8IsLower) ASSERT_FALSE(isLowercase(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, lowerChars.size()> lowerGenerator{lowerChars.span()}; + SpanGenerator<utf8, lowerChars.size()> lowerGenerator{lowerChars.span()}; auto utf8LowerGenerator = [&]() { return lowerGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8LowerGenerator, static_cast<FudUtf8Predicate>(isLowercase))); - SpanGenerator<char> nonLowerGenerator{nonLowerChars.span().takeOkay()}; + SpanGenerator<utf8> nonLowerGenerator{nonLowerChars.span().takeOkay()}; auto utf8NonLowerGenerator = [&]() { return nonLowerGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonLowerGenerator, static_cast<FudUtf8Predicate>(isLowercase))); } @@ -367,15 +364,15 @@ TEST(Utf8Test, Utf8IsLower) TEST(Utf8Test, Utf8IsUpper) { constexpr size_t numUpperChars = 26; - Array<char, numUpperChars + 1> upperCharLiteral{UPPERCASE_CHARS}; - Array<char, numUpperChars> upperChars{}; + Array<utf8, numUpperChars + 1> upperCharLiteral{UPPERCASE_CHARS}; + Array<utf8, numUpperChars> upperChars{}; copyMem<numUpperChars>(upperChars, upperCharLiteral); ASSERT_TRUE(allOf(upperChars.span(), static_cast<CharPredicate>(isUppercase))); constexpr size_t numNonUpperChars = validAsciiSize - numUpperChars; - Vector<char> nonUpperChars{}; - for (char idx = 0; idx < INT8_MAX; ++idx) { + Vector<utf8> nonUpperChars{}; + for (utf8 idx = 0; idx < INT8_MAX; ++idx) { if (!isUppercase(idx)) { ASSERT_EQ(nonUpperChars.pushBack(idx), FudStatus::Success); } @@ -387,11 +384,11 @@ TEST(Utf8Test, Utf8IsUpper) ASSERT_FALSE(isUppercase(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, upperChars.size()> upperGenerator{upperChars.span()}; + SpanGenerator<utf8, upperChars.size()> upperGenerator{upperChars.span()}; auto utf8UpperGenerator = [&]() { return upperGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8UpperGenerator, static_cast<FudUtf8Predicate>(isUppercase))); - SpanGenerator<char> nonUpperGenerator{nonUpperChars.span().takeOkay()}; + SpanGenerator<utf8> nonUpperGenerator{nonUpperChars.span().takeOkay()}; auto utf8NonUpperGenerator = [&]() { return nonUpperGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonUpperGenerator, static_cast<FudUtf8Predicate>(isUppercase))); } @@ -399,14 +396,14 @@ TEST(Utf8Test, Utf8IsUpper) TEST(Utf8Test, Utf8IsDigit) { constexpr size_t numDigitChars = 10; - Array<char, numDigitChars + 1> digitCharLiteral{DECIMAL_CHARS}; - Array<char, numDigitChars> digitChars{}; + Array<utf8, numDigitChars + 1> digitCharLiteral{DECIMAL_CHARS}; + Array<utf8, numDigitChars> digitChars{}; copyMem<numDigitChars>(digitChars, digitCharLiteral); ASSERT_TRUE(allOf(digitChars.span(), static_cast<CharPredicate>(isDigit))); constexpr size_t numNonDigitChars = validAsciiSize - numDigitChars; - Vector<char> nonDigitChars{}; + Vector<utf8> nonDigitChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { if (!isDigit(idx)) { ASSERT_EQ(nonDigitChars.pushBack(idx), FudStatus::Success); @@ -419,11 +416,11 @@ TEST(Utf8Test, Utf8IsDigit) ASSERT_FALSE(isDigit(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, digitChars.size()> digitGenerator{digitChars.span()}; + SpanGenerator<utf8, digitChars.size()> digitGenerator{digitChars.span()}; auto utf8DigitGenerator = [&]() { return digitGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8DigitGenerator, static_cast<FudUtf8Predicate>(isDigit))); - SpanGenerator<char> nonDigitGenerator{nonDigitChars.span().takeOkay()}; + SpanGenerator<utf8> nonDigitGenerator{nonDigitChars.span().takeOkay()}; auto utf8NonDigitGenerator = [&]() { return nonDigitGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonDigitGenerator, static_cast<FudUtf8Predicate>(isDigit))); } @@ -431,14 +428,14 @@ TEST(Utf8Test, Utf8IsDigit) TEST(Utf8Test, Utf8IsHexDigit) { constexpr size_t numHexDigitChars = 6 * 2 + 10; - Array<char, numHexDigitChars + 1> hexDigitCharLiteral{"abcdefABCDEF0123456789"}; - Array<char, numHexDigitChars> hexDigitChars{}; + Array<utf8, numHexDigitChars + 1> hexDigitCharLiteral{u8"abcdefABCDEF0123456789"}; + Array<utf8, numHexDigitChars> hexDigitChars{}; copyMem<numHexDigitChars>(hexDigitChars, hexDigitCharLiteral); ASSERT_TRUE(allOf(hexDigitChars.span(), static_cast<CharPredicate>(isHexDigit))); constexpr size_t numNonHexDigitChars = validAsciiSize - numHexDigitChars; - Vector<char> nonHexDigitChars{}; + Vector<utf8> nonHexDigitChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { if (!isHexDigit(idx)) { ASSERT_EQ(nonHexDigitChars.pushBack(idx), FudStatus::Success); @@ -451,11 +448,11 @@ TEST(Utf8Test, Utf8IsHexDigit) ASSERT_FALSE(isHexDigit(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, hexDigitChars.size()> hexDigitGenerator{hexDigitChars.span()}; + SpanGenerator<utf8, hexDigitChars.size()> hexDigitGenerator{hexDigitChars.span()}; auto utf8HexDigitGenerator = [&]() { return hexDigitGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8HexDigitGenerator, static_cast<FudUtf8Predicate>(isHexDigit))); - SpanGenerator<char> nonHexDigitGenerator{nonHexDigitChars.span().takeOkay()}; + SpanGenerator<utf8> nonHexDigitGenerator{nonHexDigitChars.span().takeOkay()}; auto utf8NonHexDigitGenerator = [&]() { return nonHexDigitGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonHexDigitGenerator, static_cast<FudUtf8Predicate>(isHexDigit))); } @@ -463,14 +460,14 @@ TEST(Utf8Test, Utf8IsHexDigit) TEST(Utf8Test, Utf8IsControl) { Iota<char> controlArrayGenerator{0, 1, numControlChars}; - auto controlChars = generate([]() { return Array<char, numControlChars>{}; }, controlArrayGenerator); + auto controlChars = generate([]() { return Array<utf8, numControlChars>{}; }, controlArrayGenerator); constexpr const char deleteChar = 0x7F; controlChars.back() = deleteChar; ASSERT_TRUE(allOf(controlChars.span(), static_cast<CharPredicate>(isControl))); constexpr size_t numNonControlChars = INT8_MAX + 1 - numControlChars; - Vector<char> nonControlChars{}; + Vector<utf8> nonControlChars{}; ASSERT_EQ(nonControlChars.reserve(numNonControlChars), FudStatus::Success); for (auto idx = numControlChars - 1; idx < deleteChar; ++idx) { ASSERT_EQ(nonControlChars.pushBack(idx), FudStatus::Success); @@ -483,11 +480,11 @@ TEST(Utf8Test, Utf8IsControl) ASSERT_FALSE(isControl(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, controlChars.size()> controlGenerator{controlChars.span()}; + SpanGenerator<utf8, controlChars.size()> controlGenerator{controlChars.span()}; auto utf8ControlGenerator = [&]() { return controlGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8ControlGenerator, static_cast<FudUtf8Predicate>(isControl))); - SpanGenerator<char> nonControlGenerator{nonControlChars.span().takeOkay()}; + SpanGenerator<utf8> nonControlGenerator{nonControlChars.span().takeOkay()}; auto utf8NonControlGenerator = [&]() { return nonControlGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonControlGenerator, static_cast<FudUtf8Predicate>(isControl))); } @@ -495,14 +492,14 @@ TEST(Utf8Test, Utf8IsControl) TEST(Utf8Test, Utf8IsGraphical) { constexpr size_t numGraphicalChars = sizeof(GRAPHICAL_CHARS) - 1; - Array<char, numGraphicalChars + 1> graphicalCharLiteral{GRAPHICAL_CHARS}; - Array<char, numGraphicalChars> graphicalChars{}; + Array<utf8, numGraphicalChars + 1> graphicalCharLiteral{GRAPHICAL_CHARS}; + Array<utf8, numGraphicalChars> graphicalChars{}; copyMem<numGraphicalChars>(graphicalChars, graphicalCharLiteral); ASSERT_TRUE(allOf(graphicalChars.span(), static_cast<CharPredicate>(isGraphical))); constexpr size_t numNonGraphicalChars = validAsciiSize - numGraphicalChars; - Vector<char> nonGraphicalChars{}; + Vector<utf8> nonGraphicalChars{}; ASSERT_EQ(nonGraphicalChars.reserve(numNonGraphicalChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { if (!isGraphical(static_cast<char>(idx))) { @@ -518,11 +515,11 @@ TEST(Utf8Test, Utf8IsGraphical) ASSERT_FALSE(isGraphical(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, graphicalChars.size()> graphicalGenerator{graphicalChars.span()}; + SpanGenerator<utf8, graphicalChars.size()> graphicalGenerator{graphicalChars.span()}; auto utf8GraphicalGenerator = [&]() { return graphicalGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8GraphicalGenerator, static_cast<FudUtf8Predicate>(isGraphical))); - SpanGenerator<char> nonGraphicalGenerator{nonGraphicalChars.span().takeOkay()}; + SpanGenerator<utf8> nonGraphicalGenerator{nonGraphicalChars.span().takeOkay()}; auto utf8NonGraphicalGenerator = [&]() { return nonGraphicalGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonGraphicalGenerator, static_cast<FudUtf8Predicate>(isGraphical))); } @@ -530,14 +527,14 @@ TEST(Utf8Test, Utf8IsGraphical) TEST(Utf8Test, Utf8IsSpace) { constexpr size_t numSpaceChars = sizeof(SPACE_CHARS) - 1; - Array<char, numSpaceChars + 1> spaceCharLiteral{SPACE_CHARS}; - Array<char, numSpaceChars> spaceChars{}; + Array<utf8, numSpaceChars + 1> spaceCharLiteral{SPACE_CHARS}; + Array<utf8, numSpaceChars> spaceChars{}; copyMem<numSpaceChars>(spaceChars, spaceCharLiteral); ASSERT_TRUE(allOf(spaceChars.span(), static_cast<CharPredicate>(isSpace))); constexpr size_t numNonSpaceChars = validAsciiSize - numSpaceChars; - Vector<char> nonSpaceChars{}; + Vector<utf8> nonSpaceChars{}; ASSERT_EQ(nonSpaceChars.reserve(numNonSpaceChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { if (!isSpace(static_cast<char>(idx))) { @@ -553,11 +550,11 @@ TEST(Utf8Test, Utf8IsSpace) ASSERT_FALSE(isSpace(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, spaceChars.size()> spaceGenerator{spaceChars.span()}; + SpanGenerator<utf8, spaceChars.size()> spaceGenerator{spaceChars.span()}; auto utf8SpaceGenerator = [&]() { return spaceGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8SpaceGenerator, static_cast<FudUtf8Predicate>(isSpace))); - SpanGenerator<char> nonSpaceGenerator{nonSpaceChars.span().takeOkay()}; + SpanGenerator<utf8> nonSpaceGenerator{nonSpaceChars.span().takeOkay()}; auto utf8NonSpaceGenerator = [&]() { return nonSpaceGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonSpaceGenerator, static_cast<FudUtf8Predicate>(isSpace))); } @@ -565,14 +562,14 @@ TEST(Utf8Test, Utf8IsSpace) TEST(Utf8Test, Utf8IsBlank) { constexpr size_t numBlankChars = sizeof(BLANK_CHARS) - 1; - Array<char, numBlankChars + 1> blankCharLiteral{BLANK_CHARS}; - Array<char, numBlankChars> blankChars{}; + Array<utf8, numBlankChars + 1> blankCharLiteral{BLANK_CHARS}; + Array<utf8, numBlankChars> blankChars{}; copyMem<numBlankChars>(blankChars, blankCharLiteral); ASSERT_TRUE(allOf(blankChars.span(), static_cast<CharPredicate>(isBlank))); constexpr size_t numNonBlankChars = validAsciiSize - numBlankChars; - Vector<char> nonBlankChars{}; + Vector<utf8> nonBlankChars{}; ASSERT_EQ(nonBlankChars.reserve(numNonBlankChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { if (!isBlank(static_cast<char>(idx))) { @@ -588,11 +585,11 @@ TEST(Utf8Test, Utf8IsBlank) ASSERT_FALSE(isBlank(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, blankChars.size()> blankGenerator{blankChars.span()}; + SpanGenerator<utf8, blankChars.size()> blankGenerator{blankChars.span()}; auto utf8BlankGenerator = [&]() { return blankGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8BlankGenerator, static_cast<FudUtf8Predicate>(isBlank))); - SpanGenerator<char> nonBlankGenerator{nonBlankChars.span().takeOkay()}; + SpanGenerator<utf8> nonBlankGenerator{nonBlankChars.span().takeOkay()}; auto utf8NonBlankGenerator = [&]() { return nonBlankGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonBlankGenerator, static_cast<FudUtf8Predicate>(isBlank))); } @@ -600,14 +597,14 @@ TEST(Utf8Test, Utf8IsBlank) TEST(Utf8Test, Utf8IsPrintable) { constexpr size_t numPrintableChars = sizeof(PRINTABLE_CHARS) - 1; - Array<char, numPrintableChars + 1> printableCharLiteral{PRINTABLE_CHARS}; - Array<char, numPrintableChars> printableChars{}; + Array<utf8, numPrintableChars + 1> printableCharLiteral{PRINTABLE_CHARS}; + Array<utf8, numPrintableChars> printableChars{}; copyMem<numPrintableChars>(printableChars, printableCharLiteral); ASSERT_TRUE(allOf(printableChars.span(), static_cast<CharPredicate>(isPrintable))); constexpr size_t numNonPrintableChars = validAsciiSize - numPrintableChars; - Vector<char> nonPrintableChars{}; + Vector<utf8> nonPrintableChars{}; ASSERT_EQ(nonPrintableChars.reserve(numNonPrintableChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { if (!isPrintable(static_cast<char>(idx))) { @@ -623,11 +620,11 @@ TEST(Utf8Test, Utf8IsPrintable) ASSERT_FALSE(isPrintable(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, printableChars.size()> printableGenerator{printableChars.span()}; + SpanGenerator<utf8, printableChars.size()> printableGenerator{printableChars.span()}; auto utf8PrintableGenerator = [&]() { return printableGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8PrintableGenerator, static_cast<FudUtf8Predicate>(isPrintable))); - SpanGenerator<char> nonPrintableGenerator{nonPrintableChars.span().takeOkay()}; + SpanGenerator<utf8> nonPrintableGenerator{nonPrintableChars.span().takeOkay()}; auto utf8NonPrintableGenerator = [&]() { return nonPrintableGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonPrintableGenerator, static_cast<FudUtf8Predicate>(isPrintable))); } @@ -635,14 +632,14 @@ TEST(Utf8Test, Utf8IsPrintable) TEST(Utf8Test, Utf8IsPunctuation) { constexpr size_t numPunctuationChars = sizeof(PUNCTUATION_CHARS) - 1; - Array<char, numPunctuationChars + 1> punctuationCharLiteral{PUNCTUATION_CHARS}; - Array<char, numPunctuationChars> punctuationChars{}; + Array<utf8, numPunctuationChars + 1> punctuationCharLiteral{PUNCTUATION_CHARS}; + Array<utf8, numPunctuationChars> punctuationChars{}; copyMem<numPunctuationChars>(punctuationChars, punctuationCharLiteral); ASSERT_TRUE(allOf(punctuationChars.span(), static_cast<CharPredicate>(isPunctuation))); constexpr size_t numNonPunctuationChars = validAsciiSize - numPunctuationChars; - Vector<char> nonPunctuationChars{}; + Vector<utf8> nonPunctuationChars{}; ASSERT_EQ(nonPunctuationChars.reserve(numNonPunctuationChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { if (!isPunctuation(static_cast<char>(idx))) { @@ -658,11 +655,11 @@ TEST(Utf8Test, Utf8IsPunctuation) ASSERT_FALSE(isPunctuation(FudUtf8{Ascii{invalidAscii}})); - SpanGenerator<char, punctuationChars.size()> punctuationGenerator{punctuationChars.span()}; + SpanGenerator<utf8, punctuationChars.size()> punctuationGenerator{punctuationChars.span()}; auto utf8PunctuationGenerator = [&]() { return punctuationGenerator().map(toUtf8<uint16_t>); }; ASSERT_TRUE(allOf(utf8PunctuationGenerator, static_cast<FudUtf8Predicate>(isPunctuation))); - SpanGenerator<char> nonPunctuationGenerator{nonPunctuationChars.span().takeOkay()}; + SpanGenerator<utf8> nonPunctuationGenerator{nonPunctuationChars.span().takeOkay()}; auto utf8NonPunctuationGenerator = [&]() { return nonPunctuationGenerator().map(toUtf8<uint16_t>); }; ASSERT_FALSE(anyOf(utf8NonPunctuationGenerator, static_cast<FudUtf8Predicate>(isPunctuation))); } |