Files
swift-mirror/unittests/Basic/StringExtrasTest.cpp
2014-04-02 15:18:32 +00:00

57 lines
1.1 KiB
C++

#include "swift/Basic/StringExtras.h"
#include "gtest/gtest.h"
#include <algorithm>
using namespace swift;
TEST(CamelCaseWordsTest, Iteration) {
auto words = camel_case::getWords("URLByPrependingHTTPToURL");
// Forward iteration count.
EXPECT_EQ(6, std::distance(words.begin(), words.end()));
// Reverse iteration count.
EXPECT_EQ(6, std::distance(words.rbegin(), words.rend()));
// Iteration contents.
auto iter = words.begin();
EXPECT_EQ(*iter, "URL");
// Stepping forward.
++iter;
EXPECT_EQ(*iter, "By");
// Immediately stepping back (fast path).
--iter;
EXPECT_EQ(*iter, "URL");
// Immediately stepping forward (fast path).
++iter;
EXPECT_EQ(*iter, "By");
// Stepping forward.
++iter;
EXPECT_EQ(*iter, "Prepending");
// Stepping back twice (slow path).
--iter;
--iter;
EXPECT_EQ(*iter, "URL");
// Stepping forward to visit the remaining elements.
++iter;
EXPECT_EQ(*iter, "By");
++iter;
EXPECT_EQ(*iter, "Prepending");
++iter;
EXPECT_EQ(*iter, "HTTP");
++iter;
EXPECT_EQ(*iter, "To");
++iter;
EXPECT_EQ(*iter, "URL");
// We're done.
++iter;
EXPECT_EQ(iter, words.end());
}