From 891bf38d8580b83cdf6ae315cb2650dae7d79006 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 10 May 2022 19:18:32 +0800 Subject: ... --- test/common/CMakeLists.txt | 2 +- test/common/HandlerRegistryTest.cpp | 11 +- test/common/PropertyTreeTest.cpp | 18 +-- test/common/StringTest.cpp | 96 ++++++------- test/common/StringToNumberConverterTest.cpp | 174 ++++++++++++----------- test/common/StringUtilTest.cpp | 118 +++++++-------- test/common/platform/unix/UnixFileStreamTest.cpp | 8 +- 7 files changed, 215 insertions(+), 212 deletions(-) (limited to 'test/common') diff --git a/test/common/CMakeLists.txt b/test/common/CMakeLists.txt index 6b2b594b..18f69e32 100644 --- a/test/common/CMakeLists.txt +++ b/test/common/CMakeLists.txt @@ -25,4 +25,4 @@ if (WIN32) ) endif() -gtest_discover_tests(cru_base_test) +catch_discover_tests(cru_base_test) diff --git a/test/common/HandlerRegistryTest.cpp b/test/common/HandlerRegistryTest.cpp index cf64ef4d..03e190e3 100644 --- a/test/common/HandlerRegistryTest.cpp +++ b/test/common/HandlerRegistryTest.cpp @@ -1,9 +1,10 @@ #include "cru/common/HandlerRegistry.h" -#include +#include + #include -TEST(HandlerRegistry, Work) { +TEST_CASE("HandlerRegistry", "[handler_registry]") { using namespace cru; HandlerRegistry registry; @@ -16,7 +17,7 @@ TEST(HandlerRegistry, Work) { handler(); } - ASSERT_EQ(counter, 3); + REQUIRE(counter == 3); registry.RemoveHandler(tag1); @@ -24,7 +25,7 @@ TEST(HandlerRegistry, Work) { handler(); } - ASSERT_EQ(counter, 4); + REQUIRE(counter == 4); registry.RemoveHandler(tag2); @@ -32,5 +33,5 @@ TEST(HandlerRegistry, Work) { handler(); } - ASSERT_EQ(counter, 4); + REQUIRE(counter == 4); } diff --git a/test/common/PropertyTreeTest.cpp b/test/common/PropertyTreeTest.cpp index 620bc10d..a14fe924 100644 --- a/test/common/PropertyTreeTest.cpp +++ b/test/common/PropertyTreeTest.cpp @@ -1,8 +1,8 @@ #include "cru/common/PropertyTree.h" -#include +#include -TEST(PropertyTree, Test) { +TEST_CASE("PropertyTree", "[property_tree]") { using cru::PropertySubTreeRef; using cru::PropertyTree; @@ -12,15 +12,15 @@ TEST(PropertyTree, Test) { {u"k3.sub", u"v3"}, }); - ASSERT_EQ(tree.GetValue(u"k1"), u"v1"); - ASSERT_EQ(tree.GetValue(u"k2"), u"v2"); - ASSERT_EQ(tree.GetValue(u"k3.sub"), u"v3"); + REQUIRE(tree.GetValue(u"k1") == u"v1"); + REQUIRE(tree.GetValue(u"k2") == u"v2"); + REQUIRE(tree.GetValue(u"k3.sub") == u"v3"); PropertySubTreeRef sub_tree = tree.GetSubTreeRef(u"k3"); - ASSERT_EQ(sub_tree.GetValue(u"sub"), u"v3"); + REQUIRE(sub_tree.GetValue(u"sub") == u"v3"); PropertySubTreeRef root_tree = sub_tree.GetParent(); - ASSERT_EQ(root_tree.GetValue(u"k1"), u"v1"); - ASSERT_EQ(root_tree.GetValue(u"k2"), u"v2"); - ASSERT_EQ(root_tree.GetValue(u"k3.sub"), u"v3"); + REQUIRE(root_tree.GetValue(u"k1") == u"v1"); + REQUIRE(root_tree.GetValue(u"k2") == u"v2"); + REQUIRE(root_tree.GetValue(u"k3.sub") == u"v3"); } diff --git a/test/common/StringTest.cpp b/test/common/StringTest.cpp index 1faab1cf..adbd5598 100644 --- a/test/common/StringTest.cpp +++ b/test/common/StringTest.cpp @@ -1,112 +1,112 @@ #include "cru/common/Format.h" #include "cru/common/String.h" -#include +#include -TEST(String, Append) { +TEST_CASE("String Append", "[string]") { using cru::String; String s; s.append(u"ha"); s.append(s); - ASSERT_EQ(s, String(u"haha")); + REQUIRE(s == String(u"haha")); } -TEST(String, IndexConvert) { +TEST_CASE("String IndexConvert", "[string]") { using cru::String; String s(u"123"); - ASSERT_EQ(s.IndexFromCodePointToCodeUnit(1), 1); - ASSERT_EQ(s.IndexFromCodeUnitToCodePoint(1), 1); - ASSERT_EQ(s.IndexFromCodeUnitToCodePoint(3), 3); - ASSERT_EQ(s.IndexFromCodeUnitToCodePoint(3), 3); + REQUIRE(s.IndexFromCodePointToCodeUnit(1) == 1); + REQUIRE(s.IndexFromCodeUnitToCodePoint(1) == 1); + REQUIRE(s.IndexFromCodeUnitToCodePoint(3) == 3); + REQUIRE(s.IndexFromCodeUnitToCodePoint(3) == 3); } -TEST(String, Format) { +TEST_CASE("String Format", "[string]") { using cru::Format; using cru::String; - ASSERT_EQ(Format(u"{} + {} = {}", 123, 321, 444), String(u"123 + 321 = 444")); + REQUIRE(Format(u"{} + {} = {}", 123, 321, 444) == String(u"123 + 321 = 444")); } -TEST(String, Trim) { +TEST_CASE("String Trim", "[string]") { using cru::String; - ASSERT_EQ(String(u" abc ").Trim(), u"abc"); + REQUIRE(String(u" abc ").Trim() == u"abc"); } -TEST(String, SplitToLines) { +TEST_CASE("String SplitToLines", "[string]") { using cru::String; String s(u"abc\ndef\nghi"); auto lines = s.SplitToLines(); - ASSERT_EQ(lines.size(), 3); - ASSERT_EQ(lines[0], String(u"abc")); - ASSERT_EQ(lines[1], String(u"def")); - ASSERT_EQ(lines[2], String(u"ghi")); + REQUIRE(lines.size() == 3); + REQUIRE(lines[0] == String(u"abc")); + REQUIRE(lines[1] == String(u"def")); + REQUIRE(lines[2] == String(u"ghi")); } -TEST(String, SplitToLinesWithEmptyLine) { +TEST_CASE("String SplitToLinesWithEmptyLine", "[string]") { using cru::String; String s(u"abc\n \ndef\n\nghi\n"); auto lines = s.SplitToLines(); - ASSERT_EQ(lines.size(), 6); - ASSERT_EQ(lines[0], String(u"abc")); - ASSERT_EQ(lines[1], String(u" ")); - ASSERT_EQ(lines[2], String(u"def")); - ASSERT_EQ(lines[3], String(u"")); - ASSERT_EQ(lines[4], String(u"ghi")); - ASSERT_EQ(lines[5], String(u"")); + REQUIRE(lines.size() == 6); + REQUIRE(lines[0] == String(u"abc")); + REQUIRE(lines[1] == String(u" ")); + REQUIRE(lines[2] == String(u"def")); + REQUIRE(lines[3] == String(u"")); + REQUIRE(lines[4] == String(u"ghi")); + REQUIRE(lines[5] == String(u"")); } -TEST(String, SplitToLinesRemoveSpaceLine) { +TEST_CASE("String SplitToLinesRemoveSpaceLine", "[string]") { using cru::String; String s(u"abc\n \ndef\n\nghi\n"); auto lines = s.SplitToLines(true); - ASSERT_EQ(lines.size(), 3); - ASSERT_EQ(lines[0], String(u"abc")); - ASSERT_EQ(lines[1], String(u"def")); - ASSERT_EQ(lines[2], String(u"ghi")); + REQUIRE(lines.size() == 3); + REQUIRE(lines[0] == String(u"abc")); + REQUIRE(lines[1] == String(u"def")); + REQUIRE(lines[2] == String(u"ghi")); } -TEST(StringView, ToUtf8) { +TEST_CASE("StringView ToUtf8", "[string]") { using cru::StringView; StringView utf16_text = u"aπ你🤣!"; std::string_view utf8_text = "aπ你🤣!"; - ASSERT_EQ(utf16_text.ToUtf8(), utf8_text); + REQUIRE(utf16_text.ToUtf8() == utf8_text); } -TEST(String, FromUtf8) { +TEST_CASE("String FromUtf8", "[string]") { std::u16string_view utf16_text = u"aπ你🤣!"; std::string_view utf8_text = "aπ你🤣!"; - ASSERT_EQ(cru::String::FromUtf8(utf8_text), utf16_text); + REQUIRE(cru::String::FromUtf8(utf8_text) == utf16_text); } -TEST(StringView, ParseToDouble) { +TEST_CASE("StringView ParseToDouble", "[string]") { using cru::StringToNumberFlags; using cru::StringView; - ASSERT_EQ(StringView(u"3.14159").ParseToDouble(), 3.14159); - ASSERT_EQ( + REQUIRE(StringView(u"3.14159").ParseToDouble() == 3.14159); + REQUIRE( StringView(u" 3.14159") - .ParseToDouble(nullptr, StringToNumberFlags::kAllowLeadingSpaces), - 3.14159); - ASSERT_EQ( - StringView(u" 3.14159 ") - .ParseToDouble(nullptr, StringToNumberFlags::kAllowLeadingSpaces | - StringToNumberFlags::kAllowTrailingSpaces), + .ParseToDouble(nullptr, StringToNumberFlags::kAllowLeadingSpaces) == 3.14159); + REQUIRE(StringView(u" 3.14159 ") + .ParseToDouble(nullptr, + StringToNumberFlags::kAllowLeadingSpaces | + StringToNumberFlags::kAllowTrailingSpaces) == + 3.14159); } -TEST(String, ParseToDoubleList) { +TEST_CASE("String ParseToDoubleList", "[string]") { using cru::StringView; auto list = StringView(u" 1.23 2.34 3.45 ").ParseToDoubleList(); - ASSERT_EQ(list.size(), 3); - ASSERT_EQ(list[0], 1.23); - ASSERT_EQ(list[1], 2.34); - ASSERT_EQ(list[2], 3.45); + REQUIRE(list.size() == 3); + REQUIRE(list[0] == 1.23); + REQUIRE(list[1] == 2.34); + REQUIRE(list[2] == 3.45); } diff --git a/test/common/StringToNumberConverterTest.cpp b/test/common/StringToNumberConverterTest.cpp index 7b009d1e..dc37bac0 100644 --- a/test/common/StringToNumberConverterTest.cpp +++ b/test/common/StringToNumberConverterTest.cpp @@ -1,136 +1,138 @@ #include "cru/common/Exception.h" #include "cru/common/StringToNumberConverter.h" -#include +#include -TEST(StringToIntegerConverterImpl, Base0) { +TEST_CASE("StringToIntegerConverterImpl Base0", "[string]") { using namespace cru; StringToIntegerConverterImpl converter(0, 0); Index processed_characters_count; - ASSERT_EQ(converter.Parse("12345678", &processed_characters_count), - StringToIntegerConverterImplResult(false, 12345678)); - ASSERT_EQ(processed_characters_count, 8); + REQUIRE(converter.Parse("12345678", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 12345678)); + REQUIRE(processed_characters_count == 8); - ASSERT_EQ(converter.Parse("0", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0)); - ASSERT_EQ(processed_characters_count, 1); + REQUIRE(converter.Parse("0", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0)); + REQUIRE(processed_characters_count == 1); - ASSERT_EQ(converter.Parse("012", &processed_characters_count), - StringToIntegerConverterImplResult(false, 012)); - ASSERT_EQ(processed_characters_count, 3); + REQUIRE(converter.Parse("012", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 012)); + REQUIRE(processed_characters_count == 3); - ASSERT_EQ(converter.Parse("0x12", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0x12)); - ASSERT_EQ(processed_characters_count, 4); + REQUIRE(converter.Parse("0x12", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0x12)); + REQUIRE(processed_characters_count == 4); - ASSERT_EQ(converter.Parse("0X12", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0x12)); - ASSERT_EQ(processed_characters_count, 4); + REQUIRE(converter.Parse("0X12", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0x12)); + REQUIRE(processed_characters_count == 4); - ASSERT_EQ(converter.Parse("0b101", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0b101)); - ASSERT_EQ(processed_characters_count, 5); + REQUIRE(converter.Parse("0b101", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0b101)); + REQUIRE(processed_characters_count == 5); - ASSERT_EQ(converter.Parse("0B101", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0b101)); - ASSERT_EQ(processed_characters_count, 5); + REQUIRE(converter.Parse("0B101", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0b101)); + REQUIRE(processed_characters_count == 5); - ASSERT_EQ(converter.Parse("-123", &processed_characters_count), - StringToIntegerConverterImplResult(true, 123)); - ASSERT_EQ(processed_characters_count, 4); + REQUIRE(converter.Parse("-123", &processed_characters_count) == + StringToIntegerConverterImplResult(true, 123)); + REQUIRE(processed_characters_count == 4); - ASSERT_EQ(converter.Parse("-0x10", &processed_characters_count), - StringToIntegerConverterImplResult(true, 0x10)); - ASSERT_EQ(processed_characters_count, 5); + REQUIRE(converter.Parse("-0x10", &processed_characters_count) == + StringToIntegerConverterImplResult(true, 0x10)); + REQUIRE(processed_characters_count == 5); } -TEST(StringToIntegerConverterImpl, Base0ForError) { +TEST_CASE("StringToIntegerConverterImpl Base0ForError", "[string]") { using namespace cru; StringToIntegerConverterImpl converter(0, 0); Index processed_characters_count; - ASSERT_EQ(converter.Parse("a", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0)); - ASSERT_EQ(processed_characters_count, 0); + REQUIRE(converter.Parse("a", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0)); + REQUIRE(processed_characters_count == 0); - ASSERT_EQ(converter.Parse("0a", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0)); - ASSERT_EQ(processed_characters_count, 0); + REQUIRE(converter.Parse("0a", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0)); + REQUIRE(processed_characters_count == 0); - ASSERT_EQ(converter.Parse("0x", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0)); - ASSERT_EQ(processed_characters_count, 0); + REQUIRE(converter.Parse("0x", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0)); + REQUIRE(processed_characters_count == 0); - ASSERT_EQ(converter.Parse("0xx", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0)); - ASSERT_EQ(processed_characters_count, 0); + REQUIRE(converter.Parse("0xx", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0)); + REQUIRE(processed_characters_count == 0); - ASSERT_EQ(converter.Parse(" 0", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0)); - ASSERT_EQ(processed_characters_count, 0); + REQUIRE(converter.Parse(" 0", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0)); + REQUIRE(processed_characters_count == 0); - ASSERT_EQ(converter.Parse("0 ", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0)); - ASSERT_EQ(processed_characters_count, 0); + REQUIRE(converter.Parse("0 ", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0)); + REQUIRE(processed_characters_count == 0); } -TEST(StringToIntegerConverterImpl, ThrowOnErrorFlag) { +TEST_CASE("StringToIntegerConverterImpl ThrowOnErrorFlag", "[string]") { using namespace cru; StringToIntegerConverterImpl converter(StringToNumberFlags::kThrowOnError, 0); Index processed_characters_count; - ASSERT_THROW(converter.Parse("?", &processed_characters_count), Exception); + REQUIRE_THROWS_AS(converter.Parse("?", &processed_characters_count), + Exception); } -TEST(StringToIntegerConverterImpl, AllowLeadingZeroFlag) { +TEST_CASE("StringToIntegerConverterImpl AllowLeadingZeroFlag", "[string]") { using namespace cru; StringToIntegerConverterImpl converter( StringToNumberFlags::kAllowLeadingSpaces, 0); Index processed_characters_count; - ASSERT_EQ(converter.Parse(" 123", &processed_characters_count), - StringToIntegerConverterImplResult(false, 123)); - ASSERT_EQ(processed_characters_count, 6); + REQUIRE(converter.Parse(" 123", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 123)); + REQUIRE(processed_characters_count == 6); } -TEST(StringToIntegerConverterImpl, AllowTrailingZeroFlag) { +TEST_CASE("StringToIntegerConverterImpl AllowTrailingZeroFlag", "[string]") { using namespace cru; StringToIntegerConverterImpl converter( StringToNumberFlags::kAllowTrailingSpaces, 0); Index processed_characters_count; - ASSERT_EQ(converter.Parse("123 ", &processed_characters_count), - StringToIntegerConverterImplResult(false, 123)); - ASSERT_EQ(processed_characters_count, 6); + REQUIRE(converter.Parse("123 ", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 123)); + REQUIRE(processed_characters_count == 6); } -TEST(StringToIntegerConverterImpl, AllowTrailingJunk) { +TEST_CASE("StringToIntegerConverterImpl AllowTrailingJunk", "[string]") { using namespace cru; StringToIntegerConverterImpl converter( StringToNumberFlags::kAllowLeadingZeroForInteger, 0); Index processed_characters_count; - ASSERT_EQ(converter.Parse("123 12", &processed_characters_count), - StringToIntegerConverterImplResult(false, 123)); - ASSERT_EQ(processed_characters_count, 3); + REQUIRE(converter.Parse("123 12", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 123)); + REQUIRE(processed_characters_count == 3); } -TEST(StringToIntegerConverterImpl, AllowLeadingZeroForInteger) { +TEST_CASE("StringToIntegerConverterImpl AllowLeadingZeroForInteger", + "[string]") { using namespace cru; StringToIntegerConverterImpl converter( StringToNumberFlags::kAllowLeadingZeroForInteger, 0); Index processed_characters_count; - ASSERT_EQ(converter.Parse("0x0012", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0x12)); - ASSERT_EQ(processed_characters_count, 6); + REQUIRE(converter.Parse("0x0012", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0x12)); + REQUIRE(processed_characters_count == 6); - ASSERT_EQ(converter.Parse("000011", &processed_characters_count), - StringToIntegerConverterImplResult(false, 000011)); - ASSERT_EQ(processed_characters_count, 6); + REQUIRE(converter.Parse("000011", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 000011)); + REQUIRE(processed_characters_count == 6); - ASSERT_EQ(converter.Parse("0b0011", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0b0011)); - ASSERT_EQ(processed_characters_count, 6); + REQUIRE(converter.Parse("0b0011", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0b0011)); + REQUIRE(processed_characters_count == 6); } -TEST(StringToIntegerConverterImpl, CompositeFlags) { +TEST_CASE("StringToIntegerConverterImpl CompositeFlags", "[string]") { using namespace cru; StringToIntegerConverterImpl converter( StringToNumberFlags::kAllowLeadingSpaces | @@ -139,26 +141,26 @@ TEST(StringToIntegerConverterImpl, CompositeFlags) { 0); Index processed_characters_count; - ASSERT_EQ(converter.Parse(" 0x00123!!!", &processed_characters_count), - StringToIntegerConverterImplResult(false, 0x00123)); - ASSERT_EQ(processed_characters_count, 10); + REQUIRE(converter.Parse(" 0x00123!!!", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 0x00123)); + REQUIRE(processed_characters_count == 10); } -TEST(StringToIntegerConverterImpl, OtherBase) { +TEST_CASE("StringToIntegerConverterImpl OtherBase", "[string]") { using namespace cru; StringToIntegerConverterImpl converter(0, 7); Index processed_characters_count; - ASSERT_EQ(converter.Parse("12", &processed_characters_count), - StringToIntegerConverterImplResult(false, 9)); - ASSERT_EQ(processed_characters_count, 2); + REQUIRE(converter.Parse("12", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 9)); + REQUIRE(processed_characters_count == 2); - ASSERT_EQ(converter.Parse("-12", &processed_characters_count), - StringToIntegerConverterImplResult(true, 9)); - ASSERT_EQ(processed_characters_count, 3); + REQUIRE(converter.Parse("-12", &processed_characters_count) == + StringToIntegerConverterImplResult(true, 9)); + REQUIRE(processed_characters_count == 3); converter.base = 11; - ASSERT_EQ(converter.Parse("1a", &processed_characters_count), - StringToIntegerConverterImplResult(false, 21)); - ASSERT_EQ(processed_characters_count, 2); + REQUIRE(converter.Parse("1a", &processed_characters_count) == + StringToIntegerConverterImplResult(false, 21)); + REQUIRE(processed_characters_count == 2); } diff --git a/test/common/StringUtilTest.cpp b/test/common/StringUtilTest.cpp index 54cdf30f..2dd980f9 100644 --- a/test/common/StringUtilTest.cpp +++ b/test/common/StringUtilTest.cpp @@ -1,68 +1,68 @@ #include "cru/common/String.h" #include "cru/common/StringUtil.h" -#include +#include using cru::k_invalid_code_point; -TEST(StringUtil, Utf8NextCodePoint) { +TEST_CASE("StringUtil Utf8NextCodePoint", "[string]") { using cru::Utf8NextCodePoint; std::string_view text = "aπ你🤣!"; gsl::index current = 0; - ASSERT_EQ(Utf8NextCodePoint(text.data(), text.size(), current, ¤t), - 0x0061); - ASSERT_EQ(Utf8NextCodePoint(text.data(), text.size(), current, ¤t), - 0x03C0); - ASSERT_EQ(Utf8NextCodePoint(text.data(), text.size(), current, ¤t), - 0x4F60); - ASSERT_EQ(Utf8NextCodePoint(text.data(), text.size(), current, ¤t), - 0x1F923); - ASSERT_EQ(Utf8NextCodePoint(text.data(), text.size(), current, ¤t), - 0x0021); - ASSERT_EQ(Utf8NextCodePoint(text.data(), text.size(), current, ¤t), - k_invalid_code_point); - ASSERT_EQ(current, static_cast(text.size())); + REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x0061); + REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x03C0); + REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x4F60); + REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x1F923); + REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x0021); + REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == + k_invalid_code_point); + REQUIRE(current == static_cast(text.size())); } -TEST(StringUtil, Utf16NextCodePoint) { +TEST_CASE("StringUtil Utf16NextCodePoint", "[string]") { using cru::Utf16NextCodePoint; std::u16string_view text = u"aπ你🤣!"; gsl::index current = 0; - ASSERT_EQ(Utf16NextCodePoint(text.data(), text.size(), current, ¤t), - 0x0061); - ASSERT_EQ(Utf16NextCodePoint(text.data(), text.size(), current, ¤t), - 0x03C0); - ASSERT_EQ(Utf16NextCodePoint(text.data(), text.size(), current, ¤t), - 0x4F60); - ASSERT_EQ(Utf16NextCodePoint(text.data(), text.size(), current, ¤t), - 0x1F923); - ASSERT_EQ(Utf16NextCodePoint(text.data(), text.size(), current, ¤t), - 0x0021); - ASSERT_EQ(Utf16NextCodePoint(text.data(), text.size(), current, ¤t), - k_invalid_code_point); - ASSERT_EQ(current, static_cast(text.size())); + REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x0061); + REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x03C0); + REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x4F60); + REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x1F923); + REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == + 0x0021); + REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == + k_invalid_code_point); + REQUIRE(current == static_cast(text.size())); } -TEST(StringUtil, Utf16PreviousCodePoint) { +TEST_CASE("StringUtil Utf16PreviousCodePoint", "[string]") { using cru::Utf16PreviousCodePoint; std::u16string_view text = u"aπ你🤣!"; gsl::index current = text.size(); - ASSERT_EQ(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t), - 0x0021); - ASSERT_EQ(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t), - 0x1F923); - ASSERT_EQ(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t), - 0x4F60); - ASSERT_EQ(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t), - 0x03C0); - ASSERT_EQ(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t), - 0x0061); - ASSERT_EQ(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t), - k_invalid_code_point); - ASSERT_EQ(current, 0); + REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == + 0x0021); + REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == + 0x1F923); + REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == + 0x4F60); + REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == + 0x03C0); + REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == + 0x0061); + REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == + k_invalid_code_point); + REQUIRE(current == 0); } -TEST(StringUtil, Utf8CodePointIterator) { +TEST_CASE("StringUtil Utf8CodePointIterator", "[string]") { using cru::Utf8CodePointIterator; std::string_view text = "aπ你🤣!"; std::vector code_points; @@ -74,10 +74,10 @@ TEST(StringUtil, Utf8CodePointIterator) { std::vector expected_code_points{0x0061, 0x03C0, 0x4F60, 0x1F923, 0x0021}; - ASSERT_EQ(code_points, expected_code_points); + REQUIRE(code_points == expected_code_points); } -TEST(StringUtil, Utf16CodePointIterator) { +TEST_CASE("StringUtil Utf16CodePointIterator", "[string]") { using cru::Utf16CodePointIterator; std::u16string_view text = u"aπ你🤣!"; std::vector code_points; @@ -89,29 +89,29 @@ TEST(StringUtil, Utf16CodePointIterator) { std::vector expected_code_points{0x0061, 0x03C0, 0x4F60, 0x1F923, 0x0021}; - ASSERT_EQ(code_points, expected_code_points); + REQUIRE(code_points == expected_code_points); } // TEST(WinString, IndexUtf8ToUtf16) { // using cru::platform::win::IndexUtf8ToUtf16; // std::string_view utf8_string = "aπ你🤣!"; // std::wstring_view utf16_string = L"aπ你🤣!"; -// ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 0, utf16_string), 0); -// ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 1, utf16_string), 1); -// ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 3, utf16_string), 2); -// ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 6, utf16_string), 3); -// ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 10, utf16_string), 5); -// ASSERT_EQ(IndexUtf8ToUtf16(utf8_string, 11, utf16_string), 6); +// REQUIRE(IndexUtf8ToUtf16(utf8_string, 0, utf16_string), 0); +// REQUIRE(IndexUtf8ToUtf16(utf8_string, 1, utf16_string), 1); +// REQUIRE(IndexUtf8ToUtf16(utf8_string, 3, utf16_string), 2); +// REQUIRE(IndexUtf8ToUtf16(utf8_string, 6, utf16_string), 3); +// REQUIRE(IndexUtf8ToUtf16(utf8_string, 10, utf16_string), 5); +// REQUIRE(IndexUtf8ToUtf16(utf8_string, 11, utf16_string), 6); // } // TEST(WinString, IndexUtf16ToUtf8) { // using cru::platform::win::IndexUtf16ToUtf8; // std::string_view utf8_string = "aπ你🤣!"; // std::wstring_view utf16_string = L"aπ你🤣!"; -// ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 0, utf8_string), 0); -// ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 1, utf8_string), 1); -// ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 2, utf8_string), 3); -// ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 3, utf8_string), 6); -// ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 5, utf8_string), 10); -// ASSERT_EQ(IndexUtf16ToUtf8(utf16_string, 6, utf8_string), 11); +// REQUIRE(IndexUtf16ToUtf8(utf16_string, 0, utf8_string), 0); +// REQUIRE(IndexUtf16ToUtf8(utf16_string, 1, utf8_string), 1); +// REQUIRE(IndexUtf16ToUtf8(utf16_string, 2, utf8_string), 3); +// REQUIRE(IndexUtf16ToUtf8(utf16_string, 3, utf8_string), 6); +// REQUIRE(IndexUtf16ToUtf8(utf16_string, 5, utf8_string), 10); +// REQUIRE(IndexUtf16ToUtf8(utf16_string, 6, utf8_string), 11); // } diff --git a/test/common/platform/unix/UnixFileStreamTest.cpp b/test/common/platform/unix/UnixFileStreamTest.cpp index 1ae8c48e..b9ff40da 100644 --- a/test/common/platform/unix/UnixFileStreamTest.cpp +++ b/test/common/platform/unix/UnixFileStreamTest.cpp @@ -1,12 +1,12 @@ #include "cru/common/io/OpenFileFlag.h" #include "cru/common/platform/unix/UnixFileStream.h" -#include +#include #include #include -TEST(UnixFileStream, Work) { +TEST_CASE("UnixFileStream Work", "[stream]") { using namespace cru; using namespace cru::io; using namespace cru::platform::unix; @@ -25,8 +25,8 @@ TEST(UnixFileStream, Work) { UnixFileStream file2(path, OpenFileFlags::Read); auto buffer = std::make_unique(3); file2.Read(buffer.get(), 3); - ASSERT_EQ(std::string_view(reinterpret_cast(buffer.get()), 3), - "abc"); + REQUIRE(std::string_view(reinterpret_cast(buffer.get()), 3) == + "abc"); file2.Close(); std::filesystem::remove(temp_file_path); -- cgit v1.2.3