-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
132 lines (104 loc) · 2.54 KB
/
Copy pathmain.cpp
File metadata and controls
132 lines (104 loc) · 2.54 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//#include <iostream>
//#include <typeinfo>
//
//using value_type = char;
//using pointer = value_type*;
//using const_pointer_1 = const pointer; // pointer const --> value_type* const --> char* const
//using const_pointer_2 = const value_type*; // const char *
//
//int main()
//{
// const_pointer_1 a1 = nullptr;
// const_pointer_2 a2 = nullptr;
//
// std::cout << typeid(a1).name() << '\n';
// std::cout << typeid(a2).name() << '\n';
//
// return 0;
//}
#include "buffer.h"
#include <string_view>
#include <gmock/gmock.h>
using namespace std::literals;
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
auto result = "abc"sv;
TEST(Buffer, iterators)
{
Buffer b(result);
EXPECT_EQ(result, b.toString());
auto pos = 0;
for (auto c = b.begin(); c != b.end(); ++c)
EXPECT_EQ(result[pos++], char(*c));
for (auto c = b.rbegin(); c != b.rend(); ++c)
EXPECT_EQ(result[--pos], char(*c));
}
TEST(Buffer, clear)
{
Buffer b(result);
EXPECT_EQ(result, b.toString());
EXPECT_FALSE(b.empty());
b.clear();
EXPECT_TRUE(b.empty());
}
TEST(Buffer, reserve)
{
Buffer b(result);
EXPECT_EQ(result, b.toString());
EXPECT_EQ(result.size(), b.capacity());
b.reserve(200);
EXPECT_EQ(result, b.toString());
EXPECT_EQ(200, b.capacity());
b.reserve(100); // do nothing
EXPECT_EQ(result, b.toString());
EXPECT_EQ(200, b.capacity());
}
TEST(Buffer, resize)
{
Buffer b(result);
EXPECT_EQ(result, b.toString());
EXPECT_EQ(result.size(), b.capacity());
b.resize(200);
EXPECT_EQ(200, b.size());
EXPECT_EQ(200, b.capacity());
b.resize(result.size());
EXPECT_EQ(200, b.capacity());
EXPECT_EQ(result, b.toString());
b.resize(result.size(), Buffer::Options::Shrink);
EXPECT_EQ(result.size(), b.capacity());
EXPECT_EQ(result, b.toString());
// test `Buffer::Options::Shrink` ??
}
TEST(Buffer, assign)
{
Buffer b;
b.assign(result);
EXPECT_EQ(result, b.toString());
EXPECT_EQ(result.size(), b.capacity());
auto r2 = "a"sv;
b.assign(r2);
EXPECT_EQ(r2, b.toString());
EXPECT_EQ(result.size(), b.capacity());
auto r3 = "aaaaaaaaaaa"sv;
b.assign(r3);
EXPECT_EQ(r3, b.toString());
EXPECT_EQ(r3.size(), b.capacity());
}
TEST(Buffer, insert)
{
}
TEST(Buffer, erase)
{
}
TEST(Buffer, swap)
{
Buffer b1, b2(result);
EXPECT_TRUE(b1.empty());
EXPECT_EQ(result, b2.toString());
swap(b1, b2);
EXPECT_TRUE(b2.empty());
EXPECT_EQ(result, b1.toString());
}