1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:57:36 +00:00

AK: Get rid of ConstVectorIterator.

We can achieve the same with just a VectorIterator<const Vector, const T>.
This commit is contained in:
Andreas Kling 2019-06-27 14:50:22 +02:00
parent ebe108efa6
commit 50700c107f
5 changed files with 54 additions and 42 deletions

3
AK/Tests/.gitignore vendored
View file

@ -1,2 +1,5 @@
TestString
TestQueue
TestVector
*.d
*.o

View file

@ -1,4 +1,4 @@
all: TestString TestQueue
all: TestString TestQueue TestVector
CXXFLAGS = -std=c++17 -Wall -Wextra
@ -8,5 +8,8 @@ TestString: TestString.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp
TestQueue: TestQueue.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestQueue.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
TestVector: TestVector.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp TestHelpers.h
$(CXX) $(CXXFLAGS) -I../ -I../../ -o $@ TestVector.cpp ../String.cpp ../StringImpl.cpp ../StringBuilder.cpp ../StringView.cpp
clean:
rm -f TestString TestQueue

45
AK/Tests/TestVector.cpp Normal file
View file

@ -0,0 +1,45 @@
#include "TestHelpers.h"
#include <AK/AKString.h>
#include <AK/Vector.h>
int main()
{
EXPECT(Vector<int>().is_empty());
EXPECT(Vector<int>().size() == 0);
Vector<int> ints;
ints.append(1);
ints.append(2);
ints.append(3);
EXPECT_EQ(ints.size(), 3);
EXPECT_EQ(ints.take_last(), 3);
EXPECT_EQ(ints.size(), 2);
EXPECT_EQ(ints.take_last(), 2);
EXPECT_EQ(ints.size(), 1);
EXPECT_EQ(ints.take_last(), 1);
EXPECT_EQ(ints.size(), 0);
ints.clear();
EXPECT_EQ(ints.size(), 0);
Vector<String> strings;
strings.append("ABC");
strings.append("DEF");
int loop_counter = 0;
for (const String& string : strings) {
EXPECT(!string.is_null());
EXPECT(!string.is_empty());
++loop_counter;
}
loop_counter = 0;
for (auto& string : (const_cast<const Vector<String>&>(strings))) {
EXPECT(!string.is_null());
EXPECT(!string.is_empty());
++loop_counter;
}
EXPECT_EQ(loop_counter, 2);
return 0;
}