1 //===-- Unittests for char_vector ---------------------------------------===//
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/__support/char_vector.h"
10 #include "test/UnitTest/Test.h"
12 using LIBC_NAMESPACE::CharVector
;
14 TEST(LlvmLibcCharVectorTest
, InitializeCheck
) {
16 ASSERT_EQ(v
.length(), size_t(0));
19 TEST(LlvmLibcCharVectorTest
, AppendShort
) {
21 ASSERT_EQ(v
.length(), size_t(0));
23 static constexpr char test_str
[] = "1234567890";
24 for (size_t i
= 0; test_str
[i
] != '\0'; ++i
) {
25 v
.append(test_str
[i
]);
27 ASSERT_STREQ(v
.c_str(), test_str
);
30 TEST(LlvmLibcCharVectorTest
, AppendMedium
) {
32 ASSERT_EQ(v
.length(), size_t(0));
34 // 100 characters (each row is 50)
35 static constexpr char test_str
[] =
36 "12345678901234567890123456789012345678901234567890"
37 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy";
38 for (size_t i
= 0; test_str
[i
] != '\0'; ++i
) {
39 ASSERT_EQ(v
.length(), i
);
40 v
.append(test_str
[i
]);
42 ASSERT_STREQ(v
.c_str(), test_str
);
43 ASSERT_EQ(v
.length(), size_t(100));
46 TEST(LlvmLibcCharVectorTest
, AppendLong
) {
48 ASSERT_EQ(v
.length(), size_t(0));
51 static constexpr char test_str
[] =
52 "12345678901234567890123456789012345678901234567890"
53 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
54 "12345678901234567890123456789012345678901234567890"
55 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
56 "12345678901234567890123456789012345678901234567890"
57 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
58 "12345678901234567890123456789012345678901234567890"
59 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
60 "12345678901234567890123456789012345678901234567890"
61 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
62 "12345678901234567890123456789012345678901234567890"
63 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
64 "12345678901234567890123456789012345678901234567890"
65 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
66 "12345678901234567890123456789012345678901234567890"
67 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
68 "12345678901234567890123456789012345678901234567890"
69 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
70 "12345678901234567890123456789012345678901234567890"
71 "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy";
72 for (size_t i
= 0; test_str
[i
] != '\0'; ++i
) {
73 ASSERT_EQ(v
.length(), i
);
74 ASSERT_TRUE(v
.append(test_str
[i
]));
76 ASSERT_EQ(v
.length(), size_t(1000));
77 ASSERT_STREQ(v
.c_str(), test_str
);