1//===-- Unittests for char_vector ---------------------------------------===//
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//===----------------------------------------------------------------------===//
8
9#include "src/__support/char_vector.h"
10#include "test/UnitTest/Test.h"
11
12using LIBC_NAMESPACE::CharVector;
13
14TEST(LlvmLibcCharVectorTest, InitializeCheck) {
15 CharVector v;
16 ASSERT_EQ(v.length(), size_t(0));
17}
18
19TEST(LlvmLibcCharVectorTest, AppendShort) {
20 CharVector v;
21 ASSERT_EQ(v.length(), size_t(0));
22
23 static constexpr char test_str[] = "1234567890";
24 for (size_t i = 0; test_str[i] != '\0'; ++i) {
25 v.append(new_char: test_str[i]);
26 }
27 ASSERT_STREQ(v.c_str(), test_str);
28}
29
30TEST(LlvmLibcCharVectorTest, AppendMedium) {
31 CharVector v;
32 ASSERT_EQ(v.length(), size_t(0));
33
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(new_char: test_str[i]);
41 }
42 ASSERT_STREQ(v.c_str(), test_str);
43 ASSERT_EQ(v.length(), size_t(100));
44}
45
46TEST(LlvmLibcCharVectorTest, AppendLong) {
47 CharVector v;
48 ASSERT_EQ(v.length(), size_t(0));
49
50 // 1000 characters
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]));
75 }
76 ASSERT_EQ(v.length(), size_t(1000));
77 ASSERT_STREQ(v.c_str(), test_str);
78}
79

source code of libc/test/src/__support/char_vector_test.cpp