summaryrefslogtreecommitdiff
path: root/libc/test/src/string
diff options
context:
space:
mode:
Diffstat (limited to 'libc/test/src/string')
-rw-r--r--libc/test/src/string/memchr_test.cpp10
-rw-r--r--libc/test/src/string/memrchr_test.cpp10
-rw-r--r--libc/test/src/string/strcspn_test.cpp4
-rw-r--r--libc/test/src/string/strpbrk_test.cpp4
-rw-r--r--libc/test/src/string/strsep_test.cpp8
-rw-r--r--libc/test/src/string/strspn_test.cpp4
-rw-r--r--libc/test/src/string/strtok_r_test.cpp8
-rw-r--r--libc/test/src/string/strtok_test.cpp7
8 files changed, 51 insertions, 4 deletions
diff --git a/libc/test/src/string/memchr_test.cpp b/libc/test/src/string/memchr_test.cpp
index 4a7c88bfe6e1..ede841118fe0 100644
--- a/libc/test/src/string/memchr_test.cpp
+++ b/libc/test/src/string/memchr_test.cpp
@@ -6,11 +6,15 @@
//
//===----------------------------------------------------------------------===//
-#include "hdr/signal_macros.h"
#include "src/string/memchr.h"
-#include "test/UnitTest/Test.h"
+
#include <stddef.h>
+#include "hdr/signal_macros.h"
+#include "test/UnitTest/Test.h"
+
+namespace {
+
// A helper function that calls memchr and abstracts away the explicit cast for
// readability purposes.
const char *call_memchr(const void *src, int c, size_t size) {
@@ -130,3 +134,5 @@ TEST(LlvmLibcMemChrTest, CrashOnNullPtr) {
}
#endif // defined(LIBC_ADD_NULL_CHECKS)
+
+} // namespace
diff --git a/libc/test/src/string/memrchr_test.cpp b/libc/test/src/string/memrchr_test.cpp
index 140395b3046f..e92dd3ad9c91 100644
--- a/libc/test/src/string/memrchr_test.cpp
+++ b/libc/test/src/string/memrchr_test.cpp
@@ -6,11 +6,15 @@
//
//===----------------------------------------------------------------------===//
-#include "hdr/signal_macros.h"
#include "src/string/memrchr.h"
-#include "test/UnitTest/Test.h"
+
#include <stddef.h>
+#include "hdr/signal_macros.h"
+#include "test/UnitTest/Test.h"
+
+namespace {
+
// A helper function that calls memrchr and abstracts away the explicit cast for
// readability purposes.
const char *call_memrchr(const void *src, int c, size_t size) {
@@ -122,3 +126,5 @@ TEST(LlvmLibcMemRChrTest, CrashOnNullPtr) {
}
#endif // defined(LIBC_ADD_NULL_CHECKS)
+
+} // namespace
diff --git a/libc/test/src/string/strcspn_test.cpp b/libc/test/src/string/strcspn_test.cpp
index d83b3cf4fdfe..ec98f72e3711 100644
--- a/libc/test/src/string/strcspn_test.cpp
+++ b/libc/test/src/string/strcspn_test.cpp
@@ -48,3 +48,7 @@ TEST(LlvmLibcStrCSpnTest, DuplicatedCharactersNotPartOfComplementarySpan) {
EXPECT_EQ(LIBC_NAMESPACE::strcspn("aaaa", "aa"), size_t{0});
EXPECT_EQ(LIBC_NAMESPACE::strcspn("aaaa", "baa"), size_t{0});
}
+
+TEST(LlvmLibcStrCSpnTest, TopBitSet) {
+ EXPECT_EQ(LIBC_NAMESPACE::strcspn("hello\x80world", "\x80"), size_t{5});
+}
diff --git a/libc/test/src/string/strpbrk_test.cpp b/libc/test/src/string/strpbrk_test.cpp
index fbe14da12ac1..cc802460d10b 100644
--- a/libc/test/src/string/strpbrk_test.cpp
+++ b/libc/test/src/string/strpbrk_test.cpp
@@ -60,3 +60,7 @@ TEST(LlvmLibcStrPBrkTest, FindsFirstOfRepeated) {
TEST(LlvmLibcStrPBrkTest, FindsFirstInBreakset) {
EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("12345", "34"), "345");
}
+
+TEST(LlvmLibcStrPBrkTest, TopBitSet) {
+ EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("hello\x80world", "\x80 "), "\x80world");
+}
diff --git a/libc/test/src/string/strsep_test.cpp b/libc/test/src/string/strsep_test.cpp
index e2a5d52bbedd..553edd99604e 100644
--- a/libc/test/src/string/strsep_test.cpp
+++ b/libc/test/src/string/strsep_test.cpp
@@ -61,6 +61,14 @@ TEST(LlvmLibcStrsepTest, SubsequentSearchesReturnNull) {
ASSERT_EQ(LIBC_NAMESPACE::strsep(&string, ":"), nullptr);
}
+TEST(LlvmLibcStrsepTest, TopBitSet) {
+ char top_bit_set_str[] = "hello\x80world";
+ char *p = top_bit_set_str;
+ ASSERT_STREQ(LIBC_NAMESPACE::strsep(&p, "\x80"), "hello");
+ ASSERT_STREQ(LIBC_NAMESPACE::strsep(&p, "\x80"), "world");
+ ASSERT_EQ(LIBC_NAMESPACE::strsep(&p, "\x80"), nullptr);
+}
+
#if defined(LIBC_ADD_NULL_CHECKS)
TEST(LlvmLibcStrsepTest, CrashOnNullPtr) {
diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp
index 82f9b2aef0df..813612f09fc1 100644
--- a/libc/test/src/string/strspn_test.cpp
+++ b/libc/test/src/string/strspn_test.cpp
@@ -85,6 +85,10 @@ TEST(LlvmLibcStrSpnTest, DuplicatedCharactersToBeSearchedForShouldStillMatch) {
EXPECT_EQ(LIBC_NAMESPACE::strspn("aaaa", "aa"), size_t{4});
}
+TEST(LlvmLibcStrSpnTest, TopBitSet) {
+ EXPECT_EQ(LIBC_NAMESPACE::strspn("hello\x80world", "helo\x80rld"), size_t{6});
+}
+
#if defined(LIBC_ADD_NULL_CHECKS)
TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) {
diff --git a/libc/test/src/string/strtok_r_test.cpp b/libc/test/src/string/strtok_r_test.cpp
index a19390d0b0c2..8c4d3c362f77 100644
--- a/libc/test/src/string/strtok_r_test.cpp
+++ b/libc/test/src/string/strtok_r_test.cpp
@@ -131,3 +131,11 @@ TEST(LlvmLibcStrTokReentrantTest, SubsequentSearchesReturnNull) {
ASSERT_EQ(LIBC_NAMESPACE::strtok_r(nullptr, ":", &reserve), nullptr);
ASSERT_EQ(LIBC_NAMESPACE::strtok_r(nullptr, ":", &reserve), nullptr);
}
+
+TEST(LlvmLibcStrTokReentrantTest, TopBitSet) {
+ char top_bit_set_str[] = "hello\x80world";
+ char *p;
+ ASSERT_STREQ(LIBC_NAMESPACE::strtok_r(top_bit_set_str, "\x80", &p), "hello");
+ ASSERT_STREQ(LIBC_NAMESPACE::strtok_r(nullptr, "\x80", &p), "world");
+ ASSERT_EQ(LIBC_NAMESPACE::strtok_r(nullptr, "\x80", &p), nullptr);
+}
diff --git a/libc/test/src/string/strtok_test.cpp b/libc/test/src/string/strtok_test.cpp
index 76efeddda6f4..3c097fdee071 100644
--- a/libc/test/src/string/strtok_test.cpp
+++ b/libc/test/src/string/strtok_test.cpp
@@ -83,3 +83,10 @@ TEST(LlvmLibcStrTokTest, SubsequentSearchesReturnNull) {
ASSERT_EQ(LIBC_NAMESPACE::strtok(nullptr, ":"), nullptr);
ASSERT_EQ(LIBC_NAMESPACE::strtok(nullptr, ":"), nullptr);
}
+
+TEST(LlvmLibcStrTokTest, TopBitSet) {
+ char top_bit_set_str[] = "hello\x80world";
+ ASSERT_STREQ(LIBC_NAMESPACE::strtok(top_bit_set_str, "\x80"), "hello");
+ ASSERT_STREQ(LIBC_NAMESPACE::strtok(nullptr, "\x80"), "world");
+ ASSERT_EQ(LIBC_NAMESPACE::strtok(nullptr, "\x80"), nullptr);
+}