Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / string / strsep_test.cpp
blob0daa29f6a7ad59ff5ae224463653d44cf47991c3
1 //===-- Unittests for strsep ----------------------------------------------===//
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/strsep.h"
10 #include "test/UnitTest/Test.h"
12 TEST(LlvmLibcStrsepTest, NullSrc) {
13 char *string = nullptr;
14 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, ""), nullptr);
17 TEST(LlvmLibcStrsepTest, NoTokenFound) {
19 char s[] = "";
20 char *string = s, *orig = s;
21 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, ""), nullptr);
22 EXPECT_EQ(orig, string);
25 char s[] = "abcde";
26 char *string = s, *orig = s;
27 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, ""), orig);
28 EXPECT_EQ(string, orig + 5);
31 char s[] = "abcde";
32 char *string = s, *orig = s;
33 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, "fghijk"), orig);
34 EXPECT_EQ(string, orig + 5);
38 TEST(LlvmLibcStrsepTest, TokenFound) {
39 char s[] = "abacd";
40 char *string = s;
41 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, "c"), "aba");
42 EXPECT_STREQ(string, "d");
45 TEST(LlvmLibcStrsepTest, DelimitersShouldNotBeIncludedInToken) {
46 char s[] = "__ab__:cd_:_ef_:_";
47 char *string = s;
48 const char *expected[] = {"", "", "ab", "", "", "cd", "",
49 "", "ef", "", "", "", nullptr};
50 for (int i = 0; expected[i]; i++) {
51 ASSERT_STREQ(LIBC_NAMESPACE::strsep(&string, "_:"), expected[i]);