Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / string / strpbrk_test.cpp
blobfbe14da12ac10e071ba7dd4b0f3911d32f3c6a93
1 //===-- Unittests for strpbrk ---------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strpbrk.h"
11 #include "test/UnitTest/Test.h"
13 TEST(LlvmLibcStrPBrkTest, EmptyStringShouldReturnNullptr) {
14 // The search should not include the null terminator.
15 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("", ""), nullptr);
16 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("_", ""), nullptr);
17 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("", "_"), nullptr);
20 TEST(LlvmLibcStrPBrkTest, ShouldNotFindAnythingAfterNullTerminator) {
21 const char src[4] = {'a', 'b', '\0', 'c'};
22 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "c"), nullptr);
25 TEST(LlvmLibcStrPBrkTest, ShouldReturnNullptrIfNoCharactersFound) {
26 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("12345", "abcdef"), nullptr);
29 TEST(LlvmLibcStrPBrkTest, FindsFirstCharacter) {
30 const char *src = "12345";
31 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "1"), "12345");
32 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "-1"), "12345");
33 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "1_"), "12345");
34 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "f1_"), "12345");
35 ASSERT_STREQ(src, "12345");
38 TEST(LlvmLibcStrPBrkTest, FindsMiddleCharacter) {
39 const char *src = "12345";
40 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "3"), "345");
41 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "?3"), "345");
42 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "3F"), "345");
43 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "z3_"), "345");
44 ASSERT_STREQ(src, "12345");
47 TEST(LlvmLibcStrPBrkTest, FindsLastCharacter) {
48 const char *src = "12345";
49 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "5"), "5");
50 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "r5"), "5");
51 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "59"), "5");
52 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk(src, "n5_"), "5");
53 ASSERT_STREQ(src, "12345");
56 TEST(LlvmLibcStrPBrkTest, FindsFirstOfRepeated) {
57 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("A,B,C,D", ","), ",B,C,D");
60 TEST(LlvmLibcStrPBrkTest, FindsFirstInBreakset) {
61 EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("12345", "34"), "345");