mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add some utilities for working with camelCase names.
Swift SVN r15802
This commit is contained in:
56
unittests/Basic/StringExtrasTest.cpp
Normal file
56
unittests/Basic/StringExtrasTest.cpp
Normal 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());
|
||||
}
|
||||
Reference in New Issue
Block a user