aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-20 22:25:16 +0800
committercrupest <crupest@outlook.com>2022-01-20 22:25:16 +0800
commitb68d2027fe7505c14899db9fa1496b5ace09e25f (patch)
tree8361112fdf5a245794070ae8d58279c4b91cc54b /test/common
parent3c3a08a02a0f8fc56dc2da3374f025d4fdaf62c5 (diff)
downloadcru-b68d2027fe7505c14899db9fa1496b5ace09e25f.tar.gz
cru-b68d2027fe7505c14899db9fa1496b5ace09e25f.tar.bz2
cru-b68d2027fe7505c14899db9fa1496b5ace09e25f.zip
...
Diffstat (limited to 'test/common')
-rw-r--r--test/common/StringTest.cpp41
-rw-r--r--test/common/StringUtilTest.cpp17
2 files changed, 32 insertions, 26 deletions
diff --git a/test/common/StringTest.cpp b/test/common/StringTest.cpp
index 737a93ad..0a60e729 100644
--- a/test/common/StringTest.cpp
+++ b/test/common/StringTest.cpp
@@ -70,14 +70,35 @@ TEST(String, SplitToLinesRemoveSpaceLine) {
ASSERT_EQ(lines[2], String(u"ghi"));
}
-TEST(String, ParseToFloat) {
- using cru::String;
- ASSERT_EQ(String(u"3.14159").ParseToDouble(), 3.14159);
- ASSERT_EQ(String(u" 3.14159").ParseToDouble(), 3.14159);
- ASSERT_EQ(String(u" 3.14159 ").ParseToDouble(), 3.14159);
-
- cru::Index processed_char_count = 0;
- ASSERT_EQ(String(u" 3.14159 garbege").ParseToDouble(&processed_char_count),
- 3.14159);
- ASSERT_EQ(processed_char_count, 9);
+TEST(StringView, ToUtf8) {
+ using cru::StringView;
+ StringView utf16_text = u"aπ你🤣!";
+ std::string_view utf8_text = "aπ你🤣!";
+
+ ASSERT_EQ(utf16_text.ToUtf8(), utf8_text);
+}
+
+TEST(String, FromUtf8) {
+ std::u16string_view utf16_text = u"aπ你🤣!";
+ std::string_view utf8_text = "aπ你🤣!";
+
+ ASSERT_EQ(cru::String::FromUtf8(utf8_text), utf16_text);
+}
+
+TEST(StringView, ParseToDouble) {
+ using cru::StringView;
+ ASSERT_EQ(StringView(u"3.14159").ParseToDouble(), 3.14159);
+ ASSERT_EQ(StringView(u" 3.14159").ParseToDouble(), 3.14159);
+ ASSERT_EQ(StringView(u" 3.14159 ").ParseToDouble(), 3.14159);
+}
+
+TEST(String, ParseToDoubleList) {
+ 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);
}
diff --git a/test/common/StringUtilTest.cpp b/test/common/StringUtilTest.cpp
index 5e1753b8..0fc63685 100644
--- a/test/common/StringUtilTest.cpp
+++ b/test/common/StringUtilTest.cpp
@@ -1,3 +1,4 @@
+#include "cru/common/String.hpp"
#include "cru/common/StringUtil.hpp"
#include <gtest/gtest.h>
@@ -91,22 +92,6 @@ TEST(StringUtil, Utf16CodePointIterator) {
ASSERT_EQ(code_points, expected_code_points);
}
-TEST(StringUtil, ToUtf8) {
- using cru::ToUtf8;
- std::u16string_view utf16_text = u"aπ你🤣!";
- std::string_view utf8_text = "aπ你🤣!";
-
- ASSERT_EQ(ToUtf8(utf16_text.data(), utf16_text.size()), utf8_text);
-}
-
-TEST(StringUtil, ToUtf16) {
- using cru::ToUtf16;
- std::u16string_view utf16_text = u"aπ你🤣!";
- std::string_view utf8_text = "aπ你🤣!";
-
- ASSERT_EQ(ToUtf16(utf8_text.data(), utf8_text.size()), utf16_text);
-}
-
// TEST(WinString, IndexUtf8ToUtf16) {
// using cru::platform::win::IndexUtf8ToUtf16;
// std::string_view utf8_string = "aπ你🤣!";