summaryrefslogtreecommitdiff
path: root/libc/test/src/string/strchr_test.cpp
diff options
context:
space:
mode:
authorAlex Brachet <abrachet@google.com>2023-04-11 01:11:32 +0000
committerAlex Brachet <abrachet@google.com>2023-04-11 01:16:56 +0000
commit82ca29ce54d3b7d8e47aa151e0ce3dff37727c1a (patch)
tree76237a36a0a78c0d572b696575f49037eae258ec /libc/test/src/string/strchr_test.cpp
parentd8804ecd76db331b622d011f5b72838b25bbf910 (diff)
[libc] Move str{,r}chr implementation to headers
Differential Revision: https://reviews.llvm.org/D147463
Diffstat (limited to 'libc/test/src/string/strchr_test.cpp')
-rw-r--r--libc/test/src/string/strchr_test.cpp74
1 files changed, 3 insertions, 71 deletions
diff --git a/libc/test/src/string/strchr_test.cpp b/libc/test/src/string/strchr_test.cpp
index c61927925f16..684b631a6e9b 100644
--- a/libc/test/src/string/strchr_test.cpp
+++ b/libc/test/src/string/strchr_test.cpp
@@ -6,77 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#include "StrchrTest.h"
+
#include "src/string/strchr.h"
#include "test/UnitTest/Test.h"
-TEST(LlvmLibcStrChrTest, FindsFirstCharacter) {
- const char *src = "abcde";
-
- // Should return original string since 'a' is the first character.
- ASSERT_STREQ(__llvm_libc::strchr(src, 'a'), "abcde");
- // Source string should not change.
- ASSERT_STREQ(src, "abcde");
-}
-
-TEST(LlvmLibcStrChrTest, FindsMiddleCharacter) {
- const char *src = "abcde";
-
- // Should return characters after (and including) 'c'.
- ASSERT_STREQ(__llvm_libc::strchr(src, 'c'), "cde");
- // Source string should not change.
- ASSERT_STREQ(src, "abcde");
-}
-
-TEST(LlvmLibcStrChrTest, FindsLastCharacterThatIsNotNullTerminator) {
- const char *src = "abcde";
-
- // Should return 'e' and null-terminator.
- ASSERT_STREQ(__llvm_libc::strchr(src, 'e'), "e");
- // Source string should not change.
- ASSERT_STREQ(src, "abcde");
-}
-
-TEST(LlvmLibcStrChrTest, FindsNullTerminator) {
- const char *src = "abcde";
-
- // Should return null terminator.
- ASSERT_STREQ(__llvm_libc::strchr(src, '\0'), "");
- // Source string should not change.
- ASSERT_STREQ(src, "abcde");
-}
-
-TEST(LlvmLibcStrChrTest, CharacterNotWithinStringShouldReturnNullptr) {
- // Since 'z' is not within the string, should return nullptr.
- ASSERT_STREQ(__llvm_libc::strchr("123?", 'z'), nullptr);
-}
-
-TEST(LlvmLibcStrChrTest, TheSourceShouldNotChange) {
- const char *src = "abcde";
- // When the character is found, the source string should not change.
- __llvm_libc::strchr(src, 'd');
- ASSERT_STREQ(src, "abcde");
- // Same case for when the character is not found.
- __llvm_libc::strchr(src, 'z');
- ASSERT_STREQ(src, "abcde");
- // Same case for when looking for null terminator.
- __llvm_libc::strchr(src, '\0');
- ASSERT_STREQ(src, "abcde");
-}
-
-TEST(LlvmLibcStrChrTest, ShouldFindFirstOfDuplicates) {
- // '1' is duplicated in the string, but it should find the first copy.
- ASSERT_STREQ(__llvm_libc::strchr("abc1def1ghi", '1'), "1def1ghi");
-
- const char *dups = "XXXXX";
- // Should return original string since 'X' is the first character.
- ASSERT_STREQ(__llvm_libc::strchr(dups, 'X'), dups);
-}
-
-TEST(LlvmLibcStrChrTest, EmptyStringShouldOnlyMatchNullTerminator) {
- // Null terminator should match.
- ASSERT_STREQ(__llvm_libc::strchr("", '\0'), "");
- // All other characters should not match.
- ASSERT_STREQ(__llvm_libc::strchr("", 'Z'), nullptr);
- ASSERT_STREQ(__llvm_libc::strchr("", '3'), nullptr);
- ASSERT_STREQ(__llvm_libc::strchr("", '*'), nullptr);
-}
+STRCHR_TEST(Strchr, __llvm_libc::strchr)