mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 03:50:11 +08:00
Fabric: ShadowNode::backtrackAncestors(...)
Summary: We have to have a way to backtrack a pointer to a parent node and this is generalized version of that. This is the first naive implementations of the algorithm. We will invest in optimizing this later. Reviewed By: mdvacca Differential Revision: D12920856 fbshipit-source-id: 9facb4e16a0b5608feb6747df3804952025ef093
This commit is contained in:
committed by
Facebook Github Bot
parent
1f32b5d1da
commit
3ecf4eaccb
@@ -202,3 +202,78 @@ TEST(ShadowNodeTest, handleLocalData) {
|
||||
secondNode->sealRecursive();
|
||||
ASSERT_ANY_THROW(secondNode->setLocalData(localDataOver9000));
|
||||
}
|
||||
|
||||
TEST(ShadowNodeTest, handleBacktracking) {
|
||||
/*
|
||||
* The structure:
|
||||
* <A>
|
||||
* <AA/>
|
||||
* <AB>
|
||||
* <ABA/>
|
||||
* <ABB/>
|
||||
* <ABC/>
|
||||
* </AB>
|
||||
* <AC/>
|
||||
* </A>
|
||||
*/
|
||||
|
||||
auto props = std::make_shared<const TestProps>();
|
||||
|
||||
auto nodeAA = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{
|
||||
.props = props,
|
||||
.children = ShadowNode::emptySharedShadowNodeSharedList()},
|
||||
nullptr);
|
||||
|
||||
auto nodeABA = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{
|
||||
.props = props,
|
||||
.children = ShadowNode::emptySharedShadowNodeSharedList()},
|
||||
nullptr);
|
||||
auto nodeABB = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{
|
||||
.props = props,
|
||||
.children = ShadowNode::emptySharedShadowNodeSharedList()},
|
||||
nullptr);
|
||||
auto nodeABC = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{
|
||||
.props = props,
|
||||
.children = ShadowNode::emptySharedShadowNodeSharedList()},
|
||||
nullptr);
|
||||
|
||||
auto nodeABChildren = std::make_shared<std::vector<SharedShadowNode>>(
|
||||
std::vector<SharedShadowNode>{nodeABA, nodeABB, nodeABC});
|
||||
auto nodeAB = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{.props = props, .children = nodeABChildren}, nullptr);
|
||||
|
||||
auto nodeAC = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{
|
||||
.props = props,
|
||||
.children = ShadowNode::emptySharedShadowNodeSharedList()},
|
||||
nullptr);
|
||||
|
||||
auto nodeAChildren = std::make_shared<std::vector<SharedShadowNode>>(
|
||||
std::vector<SharedShadowNode>{nodeAA, nodeAB, nodeAC});
|
||||
auto nodeA = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{.props = props, .children = nodeAChildren}, nullptr);
|
||||
|
||||
auto nodeZ = std::make_shared<TestShadowNode>(
|
||||
ShadowNodeFragment{
|
||||
.props = props,
|
||||
.children = ShadowNode::emptySharedShadowNodeSharedList()},
|
||||
nullptr);
|
||||
|
||||
std::vector<std::reference_wrapper<const ShadowNode>> ancestors = {};
|
||||
|
||||
// Negative case:
|
||||
auto success = nodeZ->constructAncestorPath(*nodeA, ancestors);
|
||||
ASSERT_FALSE(success);
|
||||
ASSERT_EQ(ancestors.size(), 0);
|
||||
|
||||
// Positive case:
|
||||
success = nodeABC->constructAncestorPath(*nodeA, ancestors);
|
||||
ASSERT_TRUE(success);
|
||||
ASSERT_EQ(ancestors.size(), 2);
|
||||
ASSERT_EQ(&ancestors[0].get(), nodeAB.get());
|
||||
ASSERT_EQ(&ancestors[1].get(), nodeA.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user