strpbrk_test.cpp
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//===-- Unittests for strpbrk ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "src/string/strpbrk.h"
#include "utils/UnitTest/Test.h"
TEST(StrPBrkTest, EmptyStringShouldReturnNullptr) {
// The search should not include the null terminator.
EXPECT_STREQ(__llvm_libc::strpbrk("", ""), nullptr);
EXPECT_STREQ(__llvm_libc::strpbrk("_", ""), nullptr);
EXPECT_STREQ(__llvm_libc::strpbrk("", "_"), nullptr);
}
TEST(StrPBrkTest, ShouldNotFindAnythingAfterNullTerminator) {
const char src[4] = {'a', 'b', '\0', 'c'};
EXPECT_STREQ(__llvm_libc::strpbrk(src, "c"), nullptr);
}
TEST(StrPBrkTest, ShouldReturnNullptrIfNoCharactersFound) {
EXPECT_STREQ(__llvm_libc::strpbrk("12345", "abcdef"), nullptr);
}
TEST(StrPBrkTest, FindsFirstCharacter) {
const char *src = "12345";
EXPECT_STREQ(__llvm_libc::strpbrk(src, "1"), "12345");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "-1"), "12345");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "1_"), "12345");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "f1_"), "12345");
ASSERT_STREQ(src, "12345");
}
TEST(StrPBrkTest, FindsMiddleCharacter) {
const char *src = "12345";
EXPECT_STREQ(__llvm_libc::strpbrk(src, "3"), "345");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "?3"), "345");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "3F"), "345");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "z3_"), "345");
ASSERT_STREQ(src, "12345");
}
TEST(StrPBrkTest, FindsLastCharacter) {
const char *src = "12345";
EXPECT_STREQ(__llvm_libc::strpbrk(src, "5"), "5");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "r5"), "5");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "59"), "5");
EXPECT_STREQ(__llvm_libc::strpbrk(src, "n5_"), "5");
ASSERT_STREQ(src, "12345");
}
TEST(StrPBrkTest, FindsFirstOfRepeated) {
EXPECT_STREQ(__llvm_libc::strpbrk("A,B,C,D", ","), ",B,C,D");
}
TEST(StrPBrkTest, FindsFirstInBreakset) {
EXPECT_STREQ(__llvm_libc::strpbrk("12345", "34"), "345");
}