Add a unit test for parsing fully qualified asset names.

This commit is contained in:
Grant Paul 2016-05-24 16:28:30 -07:00
parent a5d41e0fe7
commit 9e031785a5
3 changed files with 39 additions and 1 deletions

View File

@ -40,5 +40,6 @@ target_include_directories(xcassets PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Headers"
add_executable(dump_xcassets Tools/dump_xcassets.cpp)
target_link_libraries(dump_xcassets PRIVATE xcassets)
ADD_UNIT_GTEST(xcassets FullyQualifiedName Tests/test_FullyQualifiedName.cpp)
ADD_UNIT_GTEST(xcassets IconSet Tests/test_IconSet.cpp)
ADD_UNIT_GTEST(xcassets Scale Tests/test_Scale.cpp)

View File

@ -39,7 +39,9 @@ Parse(std::string const &string)
std::vector<std::string> groups;
while (pos != std::string::npos) {
std::string group = string.substr(prev, pos - prev);
groups.push_back(group);
if (!group.empty()) {
groups.push_back(group);
}
prev = pos + 1;
pos = string.find('/', prev);

View File

@ -0,0 +1,35 @@
/**
Copyright (c) 2015-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
*/
#include <gtest/gtest.h>
#include <xcassets/FullyQualifiedName.h>
using xcassets::FullyQualifiedName;
TEST(FullyQualifiedName, Parse)
{
auto name1 = FullyQualifiedName::Parse("");
EXPECT_EQ(name1.name(), "");
EXPECT_EQ(name1.groups(), std::vector<std::string>());
auto name2 = FullyQualifiedName::Parse("name");
EXPECT_EQ(name2.name(), "name");
EXPECT_EQ(name2.groups(), std::vector<std::string>());
auto name3 = FullyQualifiedName::Parse("group1/group2/name");
EXPECT_EQ(name3.name(), "name");
EXPECT_EQ(name3.groups(), std::vector<std::string>({ "group1", "group2" }));
EXPECT_EQ(name3.string(), "group1/group2/name");
auto name4 = FullyQualifiedName::Parse("//group//name");
EXPECT_EQ(name4.name(), "name");
EXPECT_EQ(name4.groups(), std::vector<std::string>({ "group" }));
EXPECT_EQ(name4.string(), "group/name");
}