Added sample iOS unit test setup for fabric/debug target

Summary: basic setup for unit testing Fabric impl

Reviewed By: hramos

Differential Revision: D7359239

fbshipit-source-id: ccaf36e775036f2fad4d8c882bce86bbbe06dd28
This commit is contained in:
Kevin Gozali
2018-03-21 16:38:43 -07:00
committed by Facebook Github Bot
parent f015900d30
commit 6ae38feb65
2 changed files with 105 additions and 5 deletions

View File

@@ -0,0 +1,77 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <memory>
#include <fabric/debug/DebugStringConvertibleItem.h>
#include <gtest/gtest.h>
using namespace facebook::react;
TEST(DebugStringConvertibleTest, handleSimpleNode) {
SharedDebugStringConvertibleList empty;
auto item = std::make_shared<DebugStringConvertibleItem>("View", "hello", empty, empty);
ASSERT_STREQ(item->getDebugName().c_str(), "View");
ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
ASSERT_STREQ(item->getDebugDescription().c_str(), "<View=hello/>\n");
}
TEST(DebugStringConvertibleTest, handleSimpleNodeWithProps) {
SharedDebugStringConvertibleList empty;
SharedDebugStringConvertibleList props = {
std::make_shared<DebugStringConvertibleItem>("x", "1", empty, empty)
};
auto item = std::make_shared<DebugStringConvertibleItem>("View", "hello", props, empty);
ASSERT_STREQ(item->getDebugName().c_str(), "View");
ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
ASSERT_STREQ(item->getDebugDescription().c_str(), "<View=hello x=1/>\n");
}
TEST(DebugStringConvertibleTest, handleSimpleNodeWithChildren) {
SharedDebugStringConvertibleList empty;
SharedDebugStringConvertibleList children = {
std::make_shared<DebugStringConvertibleItem>("Child", "a", empty, empty)
};
auto item = std::make_shared<DebugStringConvertibleItem>("View", "hello", empty, children);
ASSERT_STREQ(item->getDebugName().c_str(), "View");
ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
ASSERT_STREQ(item->getDebugDescription().c_str(), "<View=hello>\n <Child=a/>\n</View>\n");
}
TEST(DebugStringConvertibleTest, handleNestedNode) {
SharedDebugStringConvertibleList empty;
SharedDebugStringConvertibleList props = {
std::make_shared<DebugStringConvertibleItem>("x", "1", empty, empty)
};
SharedDebugStringConvertibleList children = {
std::make_shared<DebugStringConvertibleItem>("Child", "a", props, empty)
};
auto item = std::make_shared<DebugStringConvertibleItem>("View", "hello", props, children);
ASSERT_STREQ(item->getDebugName().c_str(), "View");
ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
ASSERT_STREQ(item->getDebugDescription().c_str(), "<View=hello x=1>\n <Child=a x=1/>\n</View>\n");
}
TEST(DebugStringConvertibleTest, handleNodeWithComplexProps) {
SharedDebugStringConvertibleList empty;
SharedDebugStringConvertibleList subProps = {
std::make_shared<DebugStringConvertibleItem>("height", "100", empty, empty),
std::make_shared<DebugStringConvertibleItem>("width", "200", empty, empty)
};
SharedDebugStringConvertibleList props = {
std::make_shared<DebugStringConvertibleItem>("x", "1", subProps, empty)
};
auto item = std::make_shared<DebugStringConvertibleItem>("View", "hello", props, empty);
ASSERT_STREQ(item->getDebugName().c_str(), "View");
ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
ASSERT_STREQ(item->getDebugDescription().c_str(), "<View=hello x=1(height=100 width=200)/>\n");
}