diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/test_format.cpp | 330 | ||||
-rw-r--r-- | test/test_string_convert.cpp | 186 | ||||
-rw-r--r-- | test/test_utf8.cpp | 219 |
4 files changed, 637 insertions, 99 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 515ae16..788e4ba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,6 +69,7 @@ fud_add_test(test_sqlite SOURCES test_sqlite.cpp) fud_add_test(test_string SOURCES test_string.cpp) fud_add_test(test_utf8 SOURCES test_utf8.cpp) fud_add_test(test_vector SOURCES test_vector.cpp) +fud_add_test(test_string_convert SOURCES test_string_convert.cpp) # fud_add_test(test_deserialize_number SOURCES test_deserialize_number.cpp) # fud_add_test(test_ext_algorithm SOURCES test_algorithm.cpp) diff --git a/test/test_format.cpp b/test/test_format.cpp index 319ed22..68c94cd 100644 --- a/test/test_format.cpp +++ b/test/test_format.cpp @@ -15,17 +15,339 @@ * limitations under the License. */ -// #include "fud_array.hpp" -// #include "fud_format.hpp" -// #include "fud_span.hpp" +#include "fud_string_view.hpp" +#include "fud_format.hpp" #include "gtest/gtest.h" namespace fud { -TEST(FormatTest, FormatSpecTest) +TEST(FormatTest, BasePositionalTest) { + size_t length = 0; + auto formatSpecResult = FormatSpec::make(StringView{" {1:}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.takeError(), FudStatus::ArgumentInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{1}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + auto formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(length, 3); + + formatSpecResult = FormatSpec::make(StringView{"{1:}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 4); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Default); + EXPECT_EQ(formatSpec.fill.fill, ' '); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Default); + EXPECT_FALSE(formatSpec.takesWidth); + EXPECT_FALSE(formatSpec.takesPrecision); + EXPECT_FALSE(formatSpec.alternateForm); + EXPECT_FALSE(formatSpec.leadingZero); + EXPECT_FALSE(formatSpec.hasLocale); + EXPECT_TRUE(std::holds_alternative<std::monostate>(formatSpec.formatType)); +} + +TEST(FormatTest, AlignTest) +{ + size_t length = 0; + + auto formatSpecResult = FormatSpec::make(StringView{"{1:<}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + auto formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(length, 5); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); + EXPECT_EQ(formatSpec.fill.fill, ' '); + EXPECT_FALSE(formatSpec.takesWidth); + EXPECT_FALSE(formatSpec.takesPrecision); + EXPECT_FALSE(formatSpec.alternateForm); + EXPECT_FALSE(formatSpec.leadingZero); + EXPECT_FALSE(formatSpec.hasLocale); + EXPECT_TRUE(std::holds_alternative<std::monostate>(formatSpec.formatType)); + + formatSpecResult = FormatSpec::make(StringView{"{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::make(StringView{"{:<<}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 5); + EXPECT_EQ(formatSpec.position, FormatSpec::positionUnspecified); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); + EXPECT_EQ(formatSpec.fill.fill, '<'); + + formatSpecResult = FormatSpec::make(StringView{"{1:_<}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 6); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); + EXPECT_EQ(formatSpec.fill.fill, '_'); +} + +TEST(FormatTest, SpecialTest) +{ + size_t length = 0; + + auto formatSpecResult = FormatSpec::make(StringView{"{1:_< }"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + auto formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 7); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); + EXPECT_EQ(formatSpec.fill.fill, '_'); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Space); + EXPECT_FALSE(formatSpec.alternateForm); + EXPECT_FALSE(formatSpec.leadingZero); + + formatSpecResult = FormatSpec::make(StringView{"{1:+}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + EXPECT_EQ(length, 5); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Plus); + EXPECT_FALSE(formatSpec.alternateForm); + EXPECT_FALSE(formatSpec.leadingZero); + + formatSpecResult = FormatSpec::make(StringView{"{1:-}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 5); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Minus); + EXPECT_FALSE(formatSpec.alternateForm); + EXPECT_FALSE(formatSpec.leadingZero); + + formatSpecResult = FormatSpec::make(StringView{"{1:_<#}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 7); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); + EXPECT_EQ(formatSpec.fill.fill, '_'); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Default); + EXPECT_TRUE(formatSpec.alternateForm); + EXPECT_FALSE(formatSpec.leadingZero); + + formatSpecResult = FormatSpec::make(StringView{"{1:_<0}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 7); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Left); + EXPECT_EQ(formatSpec.fill.fill, '_'); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Default); + EXPECT_FALSE(formatSpec.alternateForm); + EXPECT_TRUE(formatSpec.leadingZero); + + formatSpecResult = FormatSpec::make(StringView{"{1: #}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 6); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Default); + EXPECT_EQ(formatSpec.fill.fill, ' '); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Space); + EXPECT_TRUE(formatSpec.alternateForm); + EXPECT_FALSE(formatSpec.leadingZero); + + formatSpecResult = FormatSpec::make(StringView{"{1:# }"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{1:##}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{1: 0}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 6); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Default); + EXPECT_EQ(formatSpec.fill.fill, ' '); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Space); + EXPECT_FALSE(formatSpec.alternateForm); + EXPECT_TRUE(formatSpec.leadingZero); + + formatSpecResult = FormatSpec::make(StringView{"{1:0 }"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{1:0#}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{1:#00}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.takeError(), FudStatus::FormatInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{1: #0}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 7); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_EQ(formatSpec.fill.align(), FormatAlign::Value::Default); + EXPECT_EQ(formatSpec.fill.fill, ' '); + EXPECT_EQ(formatSpec.formatSign, FormatSign::Space); + EXPECT_TRUE(formatSpec.alternateForm); + EXPECT_TRUE(formatSpec.leadingZero); +} + +TEST(FormatTest, WidthTest) +{ + size_t length = 0; + + auto formatSpecResult = FormatSpec::make(StringView{"{1:1}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + auto formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 5); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_FALSE(formatSpec.takesWidth); + EXPECT_EQ(formatSpec.width, 1); + + formatSpecResult = FormatSpec::make(StringView{"{1:543}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 7); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_FALSE(formatSpec.takesWidth); + EXPECT_EQ(formatSpec.width, 543); + + formatSpecResult = FormatSpec::make(StringView{"{:543}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 6); + EXPECT_EQ(formatSpec.position, FormatSpec::positionUnspecified); + EXPECT_FALSE(formatSpec.takesWidth); + EXPECT_EQ(formatSpec.width, 543); + + // leading zero + formatSpecResult = FormatSpec::make(StringView{"{1:00}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); + + // #x100000000 4294967296 + formatSpecResult = FormatSpec::make(StringView{"{1:4294967296}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); + + formatSpecResult = FormatSpec::make(StringView{"{1:{1}}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 7); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_TRUE(formatSpec.takesWidth); + EXPECT_EQ(formatSpec.width, 1); + + // #x10000 65536 + formatSpecResult = FormatSpec::make(StringView{"{1:{65536}}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); + + formatSpecResult = FormatSpec::make(StringView{"{:{1}}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{:{}}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 5); + EXPECT_EQ(formatSpec.position, FormatSpec::positionUnspecified); + EXPECT_TRUE(formatSpec.takesWidth); + EXPECT_EQ(formatSpec.width, FormatSpec::widthUnspecified); +} + +TEST(FormatTest, PrecisionTest) +{ + size_t length = 0; + + auto formatSpecResult = FormatSpec::make(StringView{"{1:.1}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + auto formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 6); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_FALSE(formatSpec.takesPrecision); + EXPECT_EQ(formatSpec.precision, 1); + + formatSpecResult = FormatSpec::make(StringView{"{1:.543}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 8); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_FALSE(formatSpec.takesPrecision); + EXPECT_EQ(formatSpec.precision, 543); + + formatSpecResult = FormatSpec::make(StringView{"{:.543}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 7); + EXPECT_EQ(formatSpec.position, FormatSpec::positionUnspecified); + EXPECT_FALSE(formatSpec.takesPrecision); + EXPECT_EQ(formatSpec.precision, 543); + + // leading zero + formatSpecResult = FormatSpec::make(StringView{"{1:00}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); + + // #x100000000 4294967296 + formatSpecResult = FormatSpec::make(StringView{"{1:.4294967296}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); + + formatSpecResult = FormatSpec::make(StringView{"{1:.{1}}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 8); + EXPECT_EQ(formatSpec.position, 1); + EXPECT_TRUE(formatSpec.takesPrecision); + EXPECT_EQ(formatSpec.precision, 1); + + // #x10000 65536 + formatSpecResult = FormatSpec::make(StringView{"{1:.{65536}}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::RangeError); + + formatSpecResult = FormatSpec::make(StringView{"{:.{1}}"}, length); + ASSERT_TRUE(formatSpecResult.isError()); + EXPECT_EQ(formatSpecResult.getError(), FudStatus::FormatInvalid); + + formatSpecResult = FormatSpec::make(StringView{"{:.{}}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 6); + EXPECT_EQ(formatSpec.position, FormatSpec::positionUnspecified); + EXPECT_TRUE(formatSpec.takesPrecision); + EXPECT_EQ(formatSpec.precision, FormatSpec::widthUnspecified); +} + +TEST(FormatTest, LocaleTest) +{ + size_t length = 0; + + auto formatSpecResult = FormatSpec::make(StringView{"{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::make(StringView{"{:L}"}, length); + ASSERT_TRUE(formatSpecResult.isOkay()); + formatSpec = formatSpecResult.takeOkay(); + EXPECT_EQ(length, 4); + EXPECT_EQ(formatSpec.position, FormatSpec::positionUnspecified); + EXPECT_TRUE(formatSpec.hasLocale); } } // namespace fud diff --git a/test/test_string_convert.cpp b/test/test_string_convert.cpp new file mode 100644 index 0000000..38f5123 --- /dev/null +++ b/test/test_string_convert.cpp @@ -0,0 +1,186 @@ +/* + * libfud + * Copyright 2024 Dominick Allen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "fud_string_convert.hpp" + +#include "gtest/gtest.h" + +namespace fud { + +TEST(FudStringConvert, ConvertInt) +{ + auto intResult = fromString<int>(StringView{"0"}); + ASSERT_TRUE(intResult.isOkay()); + auto convertState = intResult.getOkay(); + ASSERT_EQ(convertState.value, 0); + ASSERT_EQ(convertState.nextIndex, 1); + + intResult = fromString<int>(StringView{"1"}); + ASSERT_TRUE(intResult.isOkay()); + convertState = intResult.getOkay(); + ASSERT_EQ(convertState.value, 1); + ASSERT_EQ(convertState.nextIndex, 1); + + intResult = fromString<int>(StringView{"-1"}); + ASSERT_TRUE(intResult.isOkay()); + convertState = intResult.getOkay(); + ASSERT_EQ(convertState.value, -1); + ASSERT_EQ(convertState.nextIndex, 2); + + intResult = fromString<int>(StringView{"+1"}); + ASSERT_TRUE(intResult.isOkay()); + convertState = intResult.getOkay(); + ASSERT_EQ(convertState.value, 1); + ASSERT_EQ(convertState.nextIndex, 2); + + intResult = fromString<int>(StringView{" +42"}); + ASSERT_TRUE(intResult.isOkay()); + convertState = intResult.getOkay(); + ASSERT_EQ(convertState.value, 42); + ASSERT_EQ(convertState.nextIndex, 4); + + intResult = fromString<int>(StringView{" +42Q"}); + ASSERT_TRUE(intResult.isOkay()); + convertState = intResult.getOkay(); + ASSERT_EQ(convertState.value, 42); + ASSERT_EQ(convertState.nextIndex, 4); +} + +TEST(FudStringConvert, ConvertUnsigned) +{ + auto unsignedResult = fromString<uint16_t>(StringView{"0"}); + ASSERT_TRUE(unsignedResult.isOkay()); + auto convertState = unsignedResult.getOkay(); + ASSERT_EQ(convertState.value, 0); + ASSERT_EQ(convertState.nextIndex, 1); + + unsignedResult = fromString<uint16_t>(StringView{"1"}); + ASSERT_TRUE(unsignedResult.isOkay()); + convertState = unsignedResult.getOkay(); + ASSERT_EQ(convertState.value, 1); + ASSERT_EQ(convertState.nextIndex, 1); + + unsignedResult = fromString<uint16_t>(StringView{"-1"}); + ASSERT_TRUE(unsignedResult.isError()); + ASSERT_EQ(unsignedResult.getError(), FudStatus::ArgumentInvalid); + + unsignedResult = fromString<uint16_t>(StringView{"0xFFFF"}); + ASSERT_TRUE(unsignedResult.isOkay()); + convertState = unsignedResult.getOkay(); + ASSERT_EQ(convertState.value, 0xFFFF); + ASSERT_EQ(convertState.nextIndex, 6); + + unsignedResult = fromString<uint16_t>(StringView{"0x10000"}); + ASSERT_TRUE(unsignedResult.isError()); + ASSERT_EQ(unsignedResult.getError(), FudStatus::RangeError); + + unsignedResult = fromString<uint16_t>(StringView{"+1"}); + ASSERT_TRUE(unsignedResult.isOkay()); + convertState = unsignedResult.getOkay(); + ASSERT_EQ(convertState.value, 1); + ASSERT_EQ(convertState.nextIndex, 2); + + unsignedResult = fromString<uint16_t>(StringView{" +42"}); + ASSERT_TRUE(unsignedResult.isOkay()); + convertState = unsignedResult.getOkay(); + ASSERT_EQ(convertState.value, 42); + ASSERT_EQ(convertState.nextIndex, 4); + + unsignedResult = fromString<uint16_t>(StringView{" +42Q"}); + ASSERT_TRUE(unsignedResult.isOkay()); + convertState = unsignedResult.getOkay(); + ASSERT_EQ(convertState.value, 42); + ASSERT_EQ(convertState.nextIndex, 4); +} + +TEST(FudStringConvert, ConvertFloat) +{ + auto floatResult = fromString<float>(StringView{"0"}); + ASSERT_TRUE(floatResult.isOkay()); + auto convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, 0.0); + ASSERT_EQ(convertState.nextIndex, 1); + + floatResult = fromString<float>(StringView{"1.0"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, 1.0); + ASSERT_EQ(convertState.nextIndex, 3); + + floatResult = fromString<float>(StringView{"1.5"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, 1.5); + ASSERT_EQ(convertState.nextIndex, 3); + + floatResult = fromString<float>(StringView{"1.5 next"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, 1.5); + ASSERT_EQ(convertState.nextIndex, 3); + + floatResult = fromString<float>(StringView{"-1.0"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, -1.0); + ASSERT_EQ(convertState.nextIndex, 4); + + floatResult = fromString<float>(StringView{"-1.5 next"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, -1.5); + ASSERT_EQ(convertState.nextIndex, 4); + + floatResult = fromString<float>(StringView{" -1.5 next"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, -1.5); + ASSERT_EQ(convertState.nextIndex, 5); + + floatResult = fromString<float>(StringView{" -1.5E+3 next"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, -1.5E+3); + ASSERT_EQ(convertState.nextIndex, sizeof(" -1.5E+3") - 1); + + floatResult = fromString<float>(StringView{" -15E+2 next"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, -1.5E+3); + ASSERT_EQ(convertState.nextIndex, sizeof(" -15E+2") - 1); + + floatResult = fromString<float>(StringView{" -1EA next"}); + ASSERT_TRUE(floatResult.isError()); + ASSERT_EQ(floatResult.getError(), FudStatus::ArgumentInvalid); + + floatResult = fromString<float>(StringView{" -1.5EA next"}); + ASSERT_TRUE(floatResult.isError()); + ASSERT_EQ(floatResult.getError(), FudStatus::ArgumentInvalid); + + floatResult = fromString<float>(StringView{" -1.5EQ next"}); + ASSERT_TRUE(floatResult.isError()); + ASSERT_EQ(floatResult.getError(), FudStatus::ArgumentInvalid); + + floatResult = fromString<float>(StringView{" -1.5E3Q next"}); + ASSERT_TRUE(floatResult.isOkay()); + convertState = floatResult.getOkay(); + ASSERT_EQ(convertState.value, -1.5E3); + ASSERT_EQ(convertState.nextIndex, sizeof(" -1.5E3") - 1); +} + +} // namespace fud diff --git a/test/test_utf8.cpp b/test/test_utf8.cpp index d1737f7..4b57b64 100644 --- a/test/test_utf8.cpp +++ b/test/test_utf8.cpp @@ -30,6 +30,35 @@ namespace fud { +using classify::CharPredicate; +using classify::FudUtf8Predicate; +using classify::isAscii; +using classify::isAscii; +using classify:: isAlphanumeric; +using classify:: isAlphanumeric; +using classify:: isAlpha; +using classify:: isAlpha; +using classify:: isLowercase; +using classify:: isLowercase; +using classify:: isUppercase; +using classify:: isUppercase; +using classify:: isDigit; +using classify:: isDigit; +using classify:: isHexDigit; +using classify:: isHexDigit; +using classify:: isControl; +using classify:: isControl; +using classify:: isGraphical; +using classify:: isGraphical; +using classify:: isSpace; +using classify:: isSpace; +using classify:: isBlank; +using classify:: isBlank; +using classify:: isPrintable; +using classify:: isPrintable; +using classify:: isPunctuation; +using classify:: isPunctuation; + constexpr size_t validAsciiSize = INT8_MAX + 1; constexpr size_t invalidAsciiSize = UINT8_MAX + 1 - validAsciiSize; @@ -194,24 +223,24 @@ TEST(Utf8Test, Utf8MultiByte) TEST(Utf8Test, Utf8IsAscii) { - ASSERT_FALSE(charIsAscii(invalidAscii)); + ASSERT_FALSE(isAscii(invalidAscii)); Iota<int16_t> charIota{0, 1, validAsciiSize}; - ASSERT_TRUE(allOf([&]() -> Option<char> { return charIota().map(toLetter<int16_t>); }, charIsAscii)); + ASSERT_TRUE(allOf([&]() -> Option<char> { return charIota().map(toLetter<int16_t>); }, static_cast<CharPredicate>(isAscii))); Iota<int16_t> invalidCharIota{validAsciiSize, 1, invalidAsciiSize}; - ASSERT_FALSE(anyOf([&]() -> Option<char> { return invalidCharIota().map(toLetter<int16_t>); }, charIsAscii)); + ASSERT_FALSE(anyOf([&]() -> Option<char> { return invalidCharIota().map(toLetter<int16_t>); }, static_cast<CharPredicate>(isAscii))); FudUtf8 unicode{FudUtf8::invalidAscii()}; - ASSERT_FALSE(utf8IsAscii(unicode)); + ASSERT_FALSE(isAscii(unicode)); charIota.set(0); - ASSERT_TRUE(allOf([&]() -> Option<FudUtf8> { return charIota().map(toUtf8<int16_t>); }, utf8IsAscii)); + ASSERT_TRUE(allOf([&]() -> Option<FudUtf8> { return charIota().map(toUtf8<int16_t>); }, static_cast<FudUtf8Predicate>(isAscii))); invalidCharIota.set(invalidAsciiSize); - ASSERT_FALSE(anyOf([&]() -> Option<FudUtf8> { return invalidCharIota().map(toUtf8<int16_t>); }, utf8IsAscii)); + ASSERT_FALSE(anyOf([&]() -> Option<FudUtf8> { return invalidCharIota().map(toUtf8<int16_t>); }, static_cast<FudUtf8Predicate>(isAscii))); } template <typename T, size_t Size = SIZE_MAX> @@ -241,22 +270,22 @@ TEST(Utf8Test, Utf8IsAlphanumeric) Array<char, numAlphanumericChars> alphanumericChars{}; copyMem<numAlphanumericChars>(alphanumericChars, alphanumericCharLiteral); - ASSERT_TRUE(allOf(alphanumericChars.span(), charIsAlphanumeric)); + ASSERT_TRUE(allOf(alphanumericChars.span(), static_cast<CharPredicate>(isAlphanumeric))); constexpr size_t numNonAlphanumericChars = validAsciiSize - numAlphanumericChars; Vector<char> nonAlphanumericChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { - if (!charIsAlphanumeric(idx)) { + if (!isAlphanumeric(idx)) { ASSERT_EQ(nonAlphanumericChars.pushBack(idx), FudStatus::Success); } } auto nonAlphanumericSpan{nonAlphanumericChars.span().takeOkay()}; - ASSERT_FALSE(anyOf(nonAlphanumericSpan, charIsAlphanumeric)); + ASSERT_FALSE(anyOf(nonAlphanumericSpan, static_cast<CharPredicate>(isAlphanumeric))); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsAlphanumeric)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isAlphanumeric))); - ASSERT_FALSE(utf8IsAlphanumeric(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isAlphanumeric(FudUtf8{Ascii{invalidAscii}})); auto iotaGenerator = invalidAsciiGenerator(); auto generator = generate( @@ -265,11 +294,11 @@ TEST(Utf8Test, Utf8IsAlphanumeric) SpanGenerator<char, alphanumericChars.size()> alphanumericGenerator{alphanumericChars.span()}; auto utf8AlphanumericGenerator = [&]() { return alphanumericGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8AlphanumericGenerator, utf8IsAlphanumeric)); + ASSERT_TRUE(allOf(utf8AlphanumericGenerator, static_cast<FudUtf8Predicate>(isAlphanumeric))); SpanGenerator<char> nonAlphanumericGenerator{nonAlphanumericChars.span().takeOkay()}; auto utf8NonAlphanumericGenerator = [&]() { return nonAlphanumericGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonAlphanumericGenerator, utf8IsAlphanumeric)); + ASSERT_FALSE(anyOf(utf8NonAlphanumericGenerator, static_cast<FudUtf8Predicate>(isAlphanumeric))); } TEST(Utf8Test, Utf8IsAlpha) @@ -279,29 +308,29 @@ TEST(Utf8Test, Utf8IsAlpha) Array<char, numAlphaChars> alphaChars{}; copyMem<numAlphaChars>(alphaChars, alphaCharLiteral); - ASSERT_TRUE(allOf(alphaChars.span(), charIsAlpha)); + ASSERT_TRUE(allOf(alphaChars.span(), static_cast<CharPredicate>(isAlpha))); constexpr size_t numNonAlphanumericChars = validAsciiSize - numAlphaChars; Vector<char> nonAlphaChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { - if (!charIsAlphanumeric(idx)) { + if (!isAlphanumeric(idx)) { ASSERT_EQ(nonAlphaChars.pushBack(idx), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonAlphaChars.span().takeOkay(), charIsAlpha)); + ASSERT_FALSE(anyOf(nonAlphaChars.span().takeOkay(), static_cast<CharPredicate>(isAlpha))); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsAlpha)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isAlpha))); - ASSERT_FALSE(utf8IsAlpha(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isAlpha(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, alphaChars.size()> alphaGenerator{alphaChars.span()}; auto utf8AlphaGenerator = [&]() { return alphaGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8AlphaGenerator, utf8IsAlpha)); + ASSERT_TRUE(allOf(utf8AlphaGenerator, static_cast<FudUtf8Predicate>(isAlpha))); SpanGenerator<char> nonAlphaGenerator{nonAlphaChars.span().takeOkay()}; auto utf8NonAlphaGenerator = [&]() { return nonAlphaGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonAlphaGenerator, utf8IsAlpha)); + ASSERT_FALSE(anyOf(utf8NonAlphaGenerator, static_cast<FudUtf8Predicate>(isAlpha))); } TEST(Utf8Test, Utf8IsLower) @@ -311,29 +340,29 @@ TEST(Utf8Test, Utf8IsLower) Array<char, numLowerChars> lowerChars{}; copyMem<numLowerChars>(lowerChars, lowerCharLiteral); - ASSERT_TRUE(allOf(lowerChars.span(), charIsLowercase)); + ASSERT_TRUE(allOf(lowerChars.span(), static_cast<CharPredicate>(isLowercase))); constexpr size_t numNonLowerChars = validAsciiSize - numLowerChars; Vector<char> nonLowerChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { - if (!charIsLowercase(idx)) { + if (!isLowercase(idx)) { ASSERT_EQ(nonLowerChars.pushBack(idx), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonLowerChars.span().takeOkay(), charIsLowercase)); + ASSERT_FALSE(anyOf(nonLowerChars.span().takeOkay(), static_cast<CharPredicate>(isLowercase))); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsLowercase)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isLowercase))); - ASSERT_FALSE(utf8IsLowercase(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isLowercase(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, lowerChars.size()> lowerGenerator{lowerChars.span()}; auto utf8LowerGenerator = [&]() { return lowerGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8LowerGenerator, utf8IsLowercase)); + ASSERT_TRUE(allOf(utf8LowerGenerator, static_cast<FudUtf8Predicate>(isLowercase))); SpanGenerator<char> nonLowerGenerator{nonLowerChars.span().takeOkay()}; auto utf8NonLowerGenerator = [&]() { return nonLowerGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonLowerGenerator, utf8IsLowercase)); + ASSERT_FALSE(anyOf(utf8NonLowerGenerator, static_cast<FudUtf8Predicate>(isLowercase))); } TEST(Utf8Test, Utf8IsUpper) @@ -343,29 +372,29 @@ TEST(Utf8Test, Utf8IsUpper) Array<char, numUpperChars> upperChars{}; copyMem<numUpperChars>(upperChars, upperCharLiteral); - ASSERT_TRUE(allOf(upperChars.span(), charIsUppercase)); + 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) { - if (!charIsUppercase(idx)) { + if (!isUppercase(idx)) { ASSERT_EQ(nonUpperChars.pushBack(idx), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonUpperChars.span().takeOkay(), charIsUppercase)); + ASSERT_FALSE(anyOf(nonUpperChars.span().takeOkay(), static_cast<CharPredicate>(isUppercase))); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsUppercase)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isUppercase))); - ASSERT_FALSE(utf8IsUppercase(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isUppercase(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, upperChars.size()> upperGenerator{upperChars.span()}; auto utf8UpperGenerator = [&]() { return upperGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8UpperGenerator, utf8IsUppercase)); + ASSERT_TRUE(allOf(utf8UpperGenerator, static_cast<FudUtf8Predicate>(isUppercase))); SpanGenerator<char> nonUpperGenerator{nonUpperChars.span().takeOkay()}; auto utf8NonUpperGenerator = [&]() { return nonUpperGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonUpperGenerator, utf8IsUppercase)); + ASSERT_FALSE(anyOf(utf8NonUpperGenerator, static_cast<FudUtf8Predicate>(isUppercase))); } TEST(Utf8Test, Utf8IsDigit) @@ -375,29 +404,29 @@ TEST(Utf8Test, Utf8IsDigit) Array<char, numDigitChars> digitChars{}; copyMem<numDigitChars>(digitChars, digitCharLiteral); - ASSERT_TRUE(allOf(digitChars.span(), charIsDigit)); + ASSERT_TRUE(allOf(digitChars.span(), static_cast<CharPredicate>(isDigit))); constexpr size_t numNonDigitChars = validAsciiSize - numDigitChars; Vector<char> nonDigitChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { - if (!charIsDigit(idx)) { + if (!isDigit(idx)) { ASSERT_EQ(nonDigitChars.pushBack(idx), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonDigitChars.span().takeOkay(), charIsDigit)); + ASSERT_FALSE(anyOf(nonDigitChars.span().takeOkay(), static_cast<CharPredicate>(isDigit))); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsDigit)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isDigit))); - ASSERT_FALSE(utf8IsDigit(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isDigit(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, digitChars.size()> digitGenerator{digitChars.span()}; auto utf8DigitGenerator = [&]() { return digitGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8DigitGenerator, utf8IsDigit)); + ASSERT_TRUE(allOf(utf8DigitGenerator, static_cast<FudUtf8Predicate>(isDigit))); SpanGenerator<char> nonDigitGenerator{nonDigitChars.span().takeOkay()}; auto utf8NonDigitGenerator = [&]() { return nonDigitGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonDigitGenerator, utf8IsDigit)); + ASSERT_FALSE(anyOf(utf8NonDigitGenerator, static_cast<FudUtf8Predicate>(isDigit))); } TEST(Utf8Test, Utf8IsHexDigit) @@ -407,29 +436,29 @@ TEST(Utf8Test, Utf8IsHexDigit) Array<char, numHexDigitChars> hexDigitChars{}; copyMem<numHexDigitChars>(hexDigitChars, hexDigitCharLiteral); - ASSERT_TRUE(allOf(hexDigitChars.span(), charIsHexDigit)); + ASSERT_TRUE(allOf(hexDigitChars.span(), static_cast<CharPredicate>(isHexDigit))); constexpr size_t numNonHexDigitChars = validAsciiSize - numHexDigitChars; Vector<char> nonHexDigitChars{}; for (char idx = 0; idx < INT8_MAX; ++idx) { - if (!charIsHexDigit(idx)) { + if (!isHexDigit(idx)) { ASSERT_EQ(nonHexDigitChars.pushBack(idx), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonHexDigitChars.span().takeOkay(), charIsHexDigit)); + ASSERT_FALSE(anyOf(nonHexDigitChars.span().takeOkay(), static_cast<CharPredicate>(isHexDigit))); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsHexDigit)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isHexDigit))); - ASSERT_FALSE(utf8IsHexDigit(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isHexDigit(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, hexDigitChars.size()> hexDigitGenerator{hexDigitChars.span()}; auto utf8HexDigitGenerator = [&]() { return hexDigitGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8HexDigitGenerator, utf8IsHexDigit)); + ASSERT_TRUE(allOf(utf8HexDigitGenerator, static_cast<FudUtf8Predicate>(isHexDigit))); SpanGenerator<char> nonHexDigitGenerator{nonHexDigitChars.span().takeOkay()}; auto utf8NonHexDigitGenerator = [&]() { return nonHexDigitGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonHexDigitGenerator, utf8IsHexDigit)); + ASSERT_FALSE(anyOf(utf8NonHexDigitGenerator, static_cast<FudUtf8Predicate>(isHexDigit))); } TEST(Utf8Test, Utf8IsControl) @@ -439,7 +468,7 @@ TEST(Utf8Test, Utf8IsControl) constexpr const char deleteChar = 0x7F; controlChars.back() = deleteChar; - ASSERT_TRUE(allOf(controlChars.span(), charIsControl)); + ASSERT_TRUE(allOf(controlChars.span(), static_cast<CharPredicate>(isControl))); constexpr size_t numNonControlChars = INT8_MAX + 1 - numControlChars; Vector<char> nonControlChars{}; @@ -447,21 +476,21 @@ TEST(Utf8Test, Utf8IsControl) for (auto idx = numControlChars - 1; idx < deleteChar; ++idx) { ASSERT_EQ(nonControlChars.pushBack(idx), FudStatus::Success); } - ASSERT_FALSE(anyOf(nonControlChars.span().takeOkay(), charIsControl)); - ASSERT_TRUE(allOf(nonControlChars.span().takeOkay(), charIsAscii)); + ASSERT_FALSE(anyOf(nonControlChars.span().takeOkay(), static_cast<CharPredicate>(isControl))); + ASSERT_TRUE(allOf(nonControlChars.span().takeOkay(), static_cast<CharPredicate>(isAscii))); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsControl)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isControl))); - ASSERT_FALSE(utf8IsControl(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isControl(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, controlChars.size()> controlGenerator{controlChars.span()}; auto utf8ControlGenerator = [&]() { return controlGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8ControlGenerator, utf8IsControl)); + ASSERT_TRUE(allOf(utf8ControlGenerator, static_cast<FudUtf8Predicate>(isControl))); SpanGenerator<char> nonControlGenerator{nonControlChars.span().takeOkay()}; auto utf8NonControlGenerator = [&]() { return nonControlGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonControlGenerator, utf8IsControl)); + ASSERT_FALSE(anyOf(utf8NonControlGenerator, static_cast<FudUtf8Predicate>(isControl))); } TEST(Utf8Test, Utf8IsGraphical) @@ -471,32 +500,32 @@ TEST(Utf8Test, Utf8IsGraphical) Array<char, numGraphicalChars> graphicalChars{}; copyMem<numGraphicalChars>(graphicalChars, graphicalCharLiteral); - ASSERT_TRUE(allOf(graphicalChars.span(), charIsGraphical)); + ASSERT_TRUE(allOf(graphicalChars.span(), static_cast<CharPredicate>(isGraphical))); constexpr size_t numNonGraphicalChars = validAsciiSize - numGraphicalChars; Vector<char> nonGraphicalChars{}; ASSERT_EQ(nonGraphicalChars.reserve(numNonGraphicalChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { - if (!charIsGraphical(static_cast<char>(idx))) { + if (!isGraphical(static_cast<char>(idx))) { ASSERT_EQ(nonGraphicalChars.pushBack(static_cast<char>(idx)), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonGraphicalChars.span().takeOkay(), charIsGraphical)); - ASSERT_TRUE(allOf(nonGraphicalChars.span().takeOkay(), charIsAscii)); + ASSERT_FALSE(anyOf(nonGraphicalChars.span().takeOkay(), static_cast<CharPredicate>(isGraphical))); + ASSERT_TRUE(allOf(nonGraphicalChars.span().takeOkay(), static_cast<CharPredicate>(isAscii))); ASSERT_EQ(nonGraphicalChars.size() + graphicalChars.size(), INT8_MAX + 1); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsGraphical)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isGraphical))); - ASSERT_FALSE(utf8IsGraphical(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isGraphical(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, graphicalChars.size()> graphicalGenerator{graphicalChars.span()}; auto utf8GraphicalGenerator = [&]() { return graphicalGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8GraphicalGenerator, utf8IsGraphical)); + ASSERT_TRUE(allOf(utf8GraphicalGenerator, static_cast<FudUtf8Predicate>(isGraphical))); SpanGenerator<char> nonGraphicalGenerator{nonGraphicalChars.span().takeOkay()}; auto utf8NonGraphicalGenerator = [&]() { return nonGraphicalGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonGraphicalGenerator, utf8IsGraphical)); + ASSERT_FALSE(anyOf(utf8NonGraphicalGenerator, static_cast<FudUtf8Predicate>(isGraphical))); } TEST(Utf8Test, Utf8IsSpace) @@ -506,32 +535,32 @@ TEST(Utf8Test, Utf8IsSpace) Array<char, numSpaceChars> spaceChars{}; copyMem<numSpaceChars>(spaceChars, spaceCharLiteral); - ASSERT_TRUE(allOf(spaceChars.span(), charIsSpace)); + ASSERT_TRUE(allOf(spaceChars.span(), static_cast<CharPredicate>(isSpace))); constexpr size_t numNonSpaceChars = validAsciiSize - numSpaceChars; Vector<char> nonSpaceChars{}; ASSERT_EQ(nonSpaceChars.reserve(numNonSpaceChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { - if (!charIsSpace(static_cast<char>(idx))) { + if (!isSpace(static_cast<char>(idx))) { ASSERT_EQ(nonSpaceChars.pushBack(static_cast<char>(idx)), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonSpaceChars.span().takeOkay(), charIsSpace)); - ASSERT_TRUE(allOf(nonSpaceChars.span().takeOkay(), charIsAscii)); + ASSERT_FALSE(anyOf(nonSpaceChars.span().takeOkay(), static_cast<CharPredicate>(isSpace))); + ASSERT_TRUE(allOf(nonSpaceChars.span().takeOkay(), static_cast<CharPredicate>(isAscii))); ASSERT_EQ(nonSpaceChars.size() + spaceChars.size(), INT8_MAX + 1); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsSpace)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isSpace))); - ASSERT_FALSE(utf8IsSpace(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isSpace(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, spaceChars.size()> spaceGenerator{spaceChars.span()}; auto utf8SpaceGenerator = [&]() { return spaceGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8SpaceGenerator, utf8IsSpace)); + ASSERT_TRUE(allOf(utf8SpaceGenerator, static_cast<FudUtf8Predicate>(isSpace))); SpanGenerator<char> nonSpaceGenerator{nonSpaceChars.span().takeOkay()}; auto utf8NonSpaceGenerator = [&]() { return nonSpaceGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonSpaceGenerator, utf8IsSpace)); + ASSERT_FALSE(anyOf(utf8NonSpaceGenerator, static_cast<FudUtf8Predicate>(isSpace))); } TEST(Utf8Test, Utf8IsBlank) @@ -541,32 +570,32 @@ TEST(Utf8Test, Utf8IsBlank) Array<char, numBlankChars> blankChars{}; copyMem<numBlankChars>(blankChars, blankCharLiteral); - ASSERT_TRUE(allOf(blankChars.span(), charIsBlank)); + ASSERT_TRUE(allOf(blankChars.span(), static_cast<CharPredicate>(isBlank))); constexpr size_t numNonBlankChars = validAsciiSize - numBlankChars; Vector<char> nonBlankChars{}; ASSERT_EQ(nonBlankChars.reserve(numNonBlankChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { - if (!charIsBlank(static_cast<char>(idx))) { + if (!isBlank(static_cast<char>(idx))) { ASSERT_EQ(nonBlankChars.pushBack(static_cast<char>(idx)), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonBlankChars.span().takeOkay(), charIsBlank)); - ASSERT_TRUE(allOf(nonBlankChars.span().takeOkay(), charIsAscii)); + ASSERT_FALSE(anyOf(nonBlankChars.span().takeOkay(), static_cast<CharPredicate>(isBlank))); + ASSERT_TRUE(allOf(nonBlankChars.span().takeOkay(), static_cast<CharPredicate>(isAscii))); ASSERT_EQ(nonBlankChars.size() + blankChars.size(), INT8_MAX + 1); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsBlank)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isBlank))); - ASSERT_FALSE(utf8IsBlank(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isBlank(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, blankChars.size()> blankGenerator{blankChars.span()}; auto utf8BlankGenerator = [&]() { return blankGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8BlankGenerator, utf8IsBlank)); + ASSERT_TRUE(allOf(utf8BlankGenerator, static_cast<FudUtf8Predicate>(isBlank))); SpanGenerator<char> nonBlankGenerator{nonBlankChars.span().takeOkay()}; auto utf8NonBlankGenerator = [&]() { return nonBlankGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonBlankGenerator, utf8IsBlank)); + ASSERT_FALSE(anyOf(utf8NonBlankGenerator, static_cast<FudUtf8Predicate>(isBlank))); } TEST(Utf8Test, Utf8IsPrintable) @@ -576,32 +605,32 @@ TEST(Utf8Test, Utf8IsPrintable) Array<char, numPrintableChars> printableChars{}; copyMem<numPrintableChars>(printableChars, printableCharLiteral); - ASSERT_TRUE(allOf(printableChars.span(), charIsPrintable)); + ASSERT_TRUE(allOf(printableChars.span(), static_cast<CharPredicate>(isPrintable))); constexpr size_t numNonPrintableChars = validAsciiSize - numPrintableChars; Vector<char> nonPrintableChars{}; ASSERT_EQ(nonPrintableChars.reserve(numNonPrintableChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { - if (!charIsPrintable(static_cast<char>(idx))) { + if (!isPrintable(static_cast<char>(idx))) { ASSERT_EQ(nonPrintableChars.pushBack(static_cast<char>(idx)), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonPrintableChars.span().takeOkay(), charIsPrintable)); - ASSERT_TRUE(allOf(nonPrintableChars.span().takeOkay(), charIsAscii)); + ASSERT_FALSE(anyOf(nonPrintableChars.span().takeOkay(), static_cast<CharPredicate>(isPrintable))); + ASSERT_TRUE(allOf(nonPrintableChars.span().takeOkay(), static_cast<CharPredicate>(isAscii))); ASSERT_EQ(nonPrintableChars.size() + printableChars.size(), INT8_MAX + 1); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsPrintable)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isPrintable))); - ASSERT_FALSE(utf8IsPrintable(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isPrintable(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, printableChars.size()> printableGenerator{printableChars.span()}; auto utf8PrintableGenerator = [&]() { return printableGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8PrintableGenerator, utf8IsPrintable)); + ASSERT_TRUE(allOf(utf8PrintableGenerator, static_cast<FudUtf8Predicate>(isPrintable))); SpanGenerator<char> nonPrintableGenerator{nonPrintableChars.span().takeOkay()}; auto utf8NonPrintableGenerator = [&]() { return nonPrintableGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonPrintableGenerator, utf8IsPrintable)); + ASSERT_FALSE(anyOf(utf8NonPrintableGenerator, static_cast<FudUtf8Predicate>(isPrintable))); } TEST(Utf8Test, Utf8IsPunctuation) @@ -611,32 +640,32 @@ TEST(Utf8Test, Utf8IsPunctuation) Array<char, numPunctuationChars> punctuationChars{}; copyMem<numPunctuationChars>(punctuationChars, punctuationCharLiteral); - ASSERT_TRUE(allOf(punctuationChars.span(), charIsPunctuation)); + ASSERT_TRUE(allOf(punctuationChars.span(), static_cast<CharPredicate>(isPunctuation))); constexpr size_t numNonPunctuationChars = validAsciiSize - numPunctuationChars; Vector<char> nonPunctuationChars{}; ASSERT_EQ(nonPunctuationChars.reserve(numNonPunctuationChars), FudStatus::Success); for (uint8_t idx = 0; idx < INT8_MAX + 1; ++idx) { - if (!charIsPunctuation(static_cast<char>(idx))) { + if (!isPunctuation(static_cast<char>(idx))) { ASSERT_EQ(nonPunctuationChars.pushBack(static_cast<char>(idx)), FudStatus::Success); } } - ASSERT_FALSE(anyOf(nonPunctuationChars.span().takeOkay(), charIsPunctuation)); - ASSERT_TRUE(allOf(nonPunctuationChars.span().takeOkay(), charIsAscii)); + ASSERT_FALSE(anyOf(nonPunctuationChars.span().takeOkay(), static_cast<CharPredicate>(isPunctuation))); + ASSERT_TRUE(allOf(nonPunctuationChars.span().takeOkay(), static_cast<CharPredicate>(isAscii))); ASSERT_EQ(nonPunctuationChars.size() + punctuationChars.size(), INT8_MAX + 1); auto invalidAsciiChars = invalidAsciiGenerator(); - ASSERT_FALSE(anyOf(invalidAsciiChars, charIsPunctuation)); + ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isPunctuation))); - ASSERT_FALSE(utf8IsPunctuation(FudUtf8{Ascii{invalidAscii}})); + ASSERT_FALSE(isPunctuation(FudUtf8{Ascii{invalidAscii}})); SpanGenerator<char, punctuationChars.size()> punctuationGenerator{punctuationChars.span()}; auto utf8PunctuationGenerator = [&]() { return punctuationGenerator().map(toUtf8<uint16_t>); }; - ASSERT_TRUE(allOf(utf8PunctuationGenerator, utf8IsPunctuation)); + ASSERT_TRUE(allOf(utf8PunctuationGenerator, static_cast<FudUtf8Predicate>(isPunctuation))); SpanGenerator<char> nonPunctuationGenerator{nonPunctuationChars.span().takeOkay()}; auto utf8NonPunctuationGenerator = [&]() { return nonPunctuationGenerator().map(toUtf8<uint16_t>); }; - ASSERT_FALSE(anyOf(utf8NonPunctuationGenerator, utf8IsPunctuation)); + ASSERT_FALSE(anyOf(utf8NonPunctuationGenerator, static_cast<FudUtf8Predicate>(isPunctuation))); } } // namespace fud |