1 //===-- Unittests for strsep ----------------------------------------------===//
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
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
) {
20 char *string
= s
, *orig
= s
;
21 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string
, ""), nullptr);
22 EXPECT_EQ(orig
, string
);
26 char *string
= s
, *orig
= s
;
27 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string
, ""), orig
);
28 EXPECT_EQ(string
, orig
+ 5);
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
) {
41 EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string
, "c"), "aba");
42 EXPECT_STREQ(string
, "d");
45 TEST(LlvmLibcStrsepTest
, DelimitersShouldNotBeIncludedInToken
) {
46 char s
[] = "__ab__:cd_:_ef_:_";
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
]);