Add some utilities for working with camelCase names.

Swift SVN r15802
This commit is contained in:
Doug Gregor
2014-04-02 15:18:32 +00:00
parent f4c018d3f7
commit d6a173fead
7 changed files with 354 additions and 16 deletions

View File

@@ -0,0 +1,56 @@
#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());
}