diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-27 14:50:22 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-27 14:52:12 +0200 |
commit | 50700c107fcde9d82e04c3fb86ffac299121bff2 (patch) | |
tree | 3ed97186c7729bd1be0b3e7fc5f6b355b33dec43 /AK/Tests | |
parent | ebe108efa659f45f1fbfb889006b36307979b2f0 (diff) | |
download | serenity-50700c107fcde9d82e04c3fb86ffac299121bff2.zip |
AK: Get rid of ConstVectorIterator.
We can achieve the same with just a VectorIterator<const Vector, const T>.
Diffstat (limited to 'AK/Tests')
-rw-r--r-- | AK/Tests/.gitignore | 3 | ||||
-rw-r--r-- | AK/Tests/Makefile | 5 | ||||
-rw-r--r-- | AK/Tests/TestVector.cpp | 45 |
3 files changed, 52 insertions, 1 deletions
diff --git a/AK/Tests/.gitignore b/AK/Tests/.gitignore index 2e42a5a41c..3e8c653d02 100644 --- a/AK/Tests/.gitignore +++ b/AK/Tests/.gitignore @@ -1,2 +1,5 @@ TestString TestQueue +TestVector +*.d +*.o diff --git a/AK/Tests/Makefile b/AK/Tests/Makefile index dd7fc4a8e8..1a87af2faa 100644 --- a/AK/Tests/Makefile +++ b/AK/Tests/Makefile @@ -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 diff --git a/AK/Tests/TestVector.cpp b/AK/Tests/TestVector.cpp new file mode 100644 index 0000000000..182a3acbe4 --- /dev/null +++ b/AK/Tests/TestVector.cpp @@ -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; +} |