[libc-commits] [libc] 5954755 - [libc] [obvious] Fix strchr and strrchr tests so that constness is
via libc-commits
libc-commits at lists.llvm.org
Fri Jul 31 17:01:22 PDT 2020
Author: cgyurgyik
Date: 2020-07-31T20:00:59-04:00
New Revision: 5954755939febabcf1edb52b53214f25f06ce584
URL: https://github.com/llvm/llvm-project/commit/5954755939febabcf1edb52b53214f25f06ce584
DIFF: https://github.com/llvm/llvm-project/commit/5954755939febabcf1edb52b53214f25f06ce584.diff
LOG: [libc] [obvious] Fix strchr and strrchr tests so that constness is
actually verified.
Added:
Modified:
libc/test/src/string/strchr_test.cpp
libc/test/src/string/strrchr_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/string/strchr_test.cpp b/libc/test/src/string/strchr_test.cpp
index 37b373385799..dda930c0c155 100644
--- a/libc/test/src/string/strchr_test.cpp
+++ b/libc/test/src/string/strchr_test.cpp
@@ -11,42 +11,38 @@
TEST(StrChrTest, FindsFirstCharacter) {
const char *src = "abcde";
- const char *src_copy = src;
// 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, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrChrTest, FindsMiddleCharacter) {
const char *src = "abcde";
- const char *src_copy = src;
// Should return characters after (and including) 'c'.
ASSERT_STREQ(__llvm_libc::strchr(src, 'c'), "cde");
// Source string should not change.
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrChrTest, FindsLastCharacterThatIsNotNullTerminator) {
const char *src = "abcde";
- const char *src_copy = src;
// Should return 'e' and null-terminator.
ASSERT_STREQ(__llvm_libc::strchr(src, 'e'), "e");
// Source string should not change.
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrChrTest, FindsNullTerminator) {
const char *src = "abcde";
- const char *src_copy = src;
// Should return null terminator.
ASSERT_STREQ(__llvm_libc::strchr(src, '\0'), "");
// Source string should not change.
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrChrTest, CharacterNotWithinStringShouldReturnNullptr) {
@@ -56,16 +52,15 @@ TEST(StrChrTest, CharacterNotWithinStringShouldReturnNullptr) {
TEST(StrChrTest, TheSourceShouldNotChange) {
const char *src = "abcde";
- const char *src_copy = src;
// When the character is found, the source string should not change.
__llvm_libc::strchr(src, 'd');
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
// Same case for when the character is not found.
__llvm_libc::strchr(src, 'z');
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
// Same case for when looking for nullptr.
__llvm_libc::strchr(src, '\0');
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrChrTest, ShouldFindFirstOfDuplicates) {
diff --git a/libc/test/src/string/strrchr_test.cpp b/libc/test/src/string/strrchr_test.cpp
index cf29de220d49..5ed83aa64bfb 100644
--- a/libc/test/src/string/strrchr_test.cpp
+++ b/libc/test/src/string/strrchr_test.cpp
@@ -11,42 +11,38 @@
TEST(StrRChrTest, FindsFirstCharacter) {
const char *src = "abcde";
- const char *src_copy = src;
// Should return original string since 'a' is the first character.
ASSERT_STREQ(__llvm_libc::strrchr(src, 'a'), "abcde");
// Source string should not change.
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrRChrTest, FindsMiddleCharacter) {
const char *src = "abcde";
- const char *src_copy = src;
// Should return characters after (and including) 'c'.
ASSERT_STREQ(__llvm_libc::strrchr(src, 'c'), "cde");
// Source string should not change.
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrRChrTest, FindsLastCharacterThatIsNotNullTerminator) {
const char *src = "abcde";
- const char *src_copy = src;
// Should return 'e' and null-terminator.
ASSERT_STREQ(__llvm_libc::strrchr(src, 'e'), "e");
// Source string should not change.
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrRChrTest, FindsNullTerminator) {
const char *src = "abcde";
- const char *src_copy = src;
// Should return null terminator.
ASSERT_STREQ(__llvm_libc::strrchr(src, '\0'), "");
// Source string should not change.
- ASSERT_STREQ(src, src_copy);
+ ASSERT_STREQ(src, "abcde");
}
TEST(StrRChrTest, FindsLastBehindFirstNullTerminator) {
More information about the libc-commits
mailing list