mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 20:25:33 +08:00
Fabric: Enabling clang-format for the rest of Fabric
Summary: This is the second and the final part of adopting clang-format. Reviewed By: mdvacca Differential Revision: D10229624 fbshipit-source-id: d97670b716800ea2488b84bd0aacaf54d8bd2e31
This commit is contained in:
committed by
Facebook Github Bot
parent
01af828d16
commit
8f51243957
@@ -12,7 +12,9 @@ namespace react {
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
std::string DebugStringConvertible::getDebugChildrenDescription(DebugStringConvertibleOptions options, int depth) const {
|
||||
std::string DebugStringConvertible::getDebugChildrenDescription(
|
||||
DebugStringConvertibleOptions options,
|
||||
int depth) const {
|
||||
if (depth >= options.maximumDepth) {
|
||||
return "";
|
||||
}
|
||||
@@ -30,7 +32,9 @@ std::string DebugStringConvertible::getDebugChildrenDescription(DebugStringConve
|
||||
return childrenString;
|
||||
}
|
||||
|
||||
std::string DebugStringConvertible::getDebugPropsDescription(DebugStringConvertibleOptions options, int depth) const {
|
||||
std::string DebugStringConvertible::getDebugPropsDescription(
|
||||
DebugStringConvertibleOptions options,
|
||||
int depth) const {
|
||||
if (depth >= options.maximumDepth) {
|
||||
return "";
|
||||
}
|
||||
@@ -45,8 +49,10 @@ std::string DebugStringConvertible::getDebugPropsDescription(DebugStringConverti
|
||||
auto name = prop->getDebugName();
|
||||
auto value = prop->getDebugValue();
|
||||
auto children = prop->getDebugPropsDescription(options, depth + 1);
|
||||
auto valueAndChildren = value + (children.empty() ? "" : "(" + children + ")");
|
||||
propsString += " " + name + (valueAndChildren.empty() ? "" : "=" + valueAndChildren);
|
||||
auto valueAndChildren =
|
||||
value + (children.empty() ? "" : "(" + children + ")");
|
||||
propsString +=
|
||||
" " + name + (valueAndChildren.empty() ? "" : "=" + valueAndChildren);
|
||||
}
|
||||
|
||||
if (!propsString.empty()) {
|
||||
@@ -57,19 +63,23 @@ std::string DebugStringConvertible::getDebugPropsDescription(DebugStringConverti
|
||||
return propsString;
|
||||
}
|
||||
|
||||
std::string DebugStringConvertible::getDebugDescription(DebugStringConvertibleOptions options, int depth) const {
|
||||
std::string DebugStringConvertible::getDebugDescription(
|
||||
DebugStringConvertibleOptions options,
|
||||
int depth) const {
|
||||
auto nameString = getDebugName();
|
||||
auto valueString = getDebugValue();
|
||||
auto childrenString = getDebugChildrenDescription(options, depth);
|
||||
auto propsString = getDebugPropsDescription(options, depth);
|
||||
|
||||
auto leading = options.format ? std::string(depth * 2, ' ') : std::string {""};
|
||||
auto trailing = options.format ? std::string {"\n"} : std::string {""};
|
||||
auto leading = options.format ? std::string(depth * 2, ' ') : std::string{""};
|
||||
auto trailing = options.format ? std::string{"\n"} : std::string{""};
|
||||
|
||||
return leading + "<" + nameString +
|
||||
(valueString.empty() ? "" : "=" + valueString) +
|
||||
(propsString.empty() ? "" : " " + propsString) +
|
||||
(childrenString.empty() ? "/>" + trailing : ">" + trailing + childrenString + leading + "</" + nameString + ">" + trailing);
|
||||
(valueString.empty() ? "" : "=" + valueString) +
|
||||
(propsString.empty() ? "" : " " + propsString) +
|
||||
(childrenString.empty() ? "/>" + trailing
|
||||
: ">" + trailing + childrenString + leading +
|
||||
"</" + nameString + ">" + trailing);
|
||||
}
|
||||
|
||||
std::string DebugStringConvertible::getDebugName() const {
|
||||
@@ -80,7 +90,8 @@ std::string DebugStringConvertible::getDebugValue() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
SharedDebugStringConvertibleList DebugStringConvertible::getDebugChildren() const {
|
||||
SharedDebugStringConvertibleList DebugStringConvertible::getDebugChildren()
|
||||
const {
|
||||
return SharedDebugStringConvertibleList();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace facebook {
|
||||
@@ -22,12 +22,14 @@ namespace react {
|
||||
|
||||
class DebugStringConvertible;
|
||||
|
||||
using SharedDebugStringConvertible = std::shared_ptr<const DebugStringConvertible>;
|
||||
using SharedDebugStringConvertibleList = std::vector<SharedDebugStringConvertible>;
|
||||
using SharedDebugStringConvertible =
|
||||
std::shared_ptr<const DebugStringConvertible>;
|
||||
using SharedDebugStringConvertibleList =
|
||||
std::vector<SharedDebugStringConvertible>;
|
||||
|
||||
struct DebugStringConvertibleOptions {
|
||||
bool format {true};
|
||||
int maximumDepth {INT_MAX};
|
||||
bool format{true};
|
||||
int maximumDepth{INT_MAX};
|
||||
};
|
||||
|
||||
// Abstract class describes conformance to DebugStringConvertible concept
|
||||
@@ -35,8 +37,7 @@ struct DebugStringConvertibleOptions {
|
||||
// Use this as a base class for providing a debugging textual representation
|
||||
// of your class.
|
||||
class DebugStringConvertible {
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual ~DebugStringConvertible() = default;
|
||||
|
||||
// Returns a name of the object.
|
||||
@@ -60,12 +61,18 @@ public:
|
||||
// Returns a string which represents the object in a human-readable way.
|
||||
// Default implementation returns a description of the subtree
|
||||
// rooted at this node, represented in XML-like format.
|
||||
virtual std::string getDebugDescription(DebugStringConvertibleOptions options = {}, int depth = 0) const;
|
||||
virtual std::string getDebugDescription(
|
||||
DebugStringConvertibleOptions options = {},
|
||||
int depth = 0) const;
|
||||
|
||||
// Do same as `getDebugDescription` but return only *children* and
|
||||
// *properties* parts (which are used in `getDebugDescription`).
|
||||
virtual std::string getDebugPropsDescription(DebugStringConvertibleOptions options = {}, int depth = 0) const;
|
||||
virtual std::string getDebugChildrenDescription(DebugStringConvertibleOptions options = {}, int depth = 0) const;
|
||||
virtual std::string getDebugPropsDescription(
|
||||
DebugStringConvertibleOptions options = {},
|
||||
int depth = 0) const;
|
||||
virtual std::string getDebugChildrenDescription(
|
||||
DebugStringConvertibleOptions options = {},
|
||||
int depth = 0) const;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
@@ -13,15 +13,11 @@ namespace react {
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
DebugStringConvertibleItem::DebugStringConvertibleItem(
|
||||
const std::string &name,
|
||||
const std::string &value,
|
||||
const SharedDebugStringConvertibleList &props,
|
||||
const SharedDebugStringConvertibleList &children
|
||||
):
|
||||
name_(name),
|
||||
value_(value),
|
||||
props_(props),
|
||||
children_(children) {}
|
||||
const std::string &name,
|
||||
const std::string &value,
|
||||
const SharedDebugStringConvertibleList &props,
|
||||
const SharedDebugStringConvertibleList &children)
|
||||
: name_(name), value_(value), props_(props), children_(children) {}
|
||||
|
||||
std::string DebugStringConvertibleItem::getDebugName() const {
|
||||
return name_;
|
||||
@@ -31,11 +27,13 @@ std::string DebugStringConvertibleItem::getDebugValue() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
SharedDebugStringConvertibleList DebugStringConvertibleItem::getDebugProps() const {
|
||||
SharedDebugStringConvertibleList DebugStringConvertibleItem::getDebugProps()
|
||||
const {
|
||||
return props_;
|
||||
}
|
||||
|
||||
SharedDebugStringConvertibleList DebugStringConvertibleItem::getDebugChildren() const {
|
||||
SharedDebugStringConvertibleList DebugStringConvertibleItem::getDebugChildren()
|
||||
const {
|
||||
return children_;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,26 +19,23 @@ namespace react {
|
||||
// Trivial implementation of `DebugStringConvertible` abstract class
|
||||
// with a stored output; useful for assembling `DebugStringConvertible` values
|
||||
// in custom implementations of `getDebugChildren` and `getDebugProps`.
|
||||
class DebugStringConvertibleItem:
|
||||
public DebugStringConvertible {
|
||||
|
||||
public:
|
||||
class DebugStringConvertibleItem : public DebugStringConvertible {
|
||||
public:
|
||||
DebugStringConvertibleItem() = default;
|
||||
DebugStringConvertibleItem(const DebugStringConvertibleItem &item) = default;
|
||||
|
||||
DebugStringConvertibleItem(
|
||||
const std::string &name = "",
|
||||
const std::string &value = "",
|
||||
const SharedDebugStringConvertibleList &props = {},
|
||||
const SharedDebugStringConvertibleList &children = {}
|
||||
);
|
||||
const std::string &name = "",
|
||||
const std::string &value = "",
|
||||
const SharedDebugStringConvertibleList &props = {},
|
||||
const SharedDebugStringConvertibleList &children = {});
|
||||
|
||||
std::string getDebugName() const override;
|
||||
std::string getDebugValue() const override;
|
||||
SharedDebugStringConvertibleList getDebugChildren() const override;
|
||||
SharedDebugStringConvertibleList getDebugProps() const override;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string name_;
|
||||
std::string value_;
|
||||
SharedDebugStringConvertibleList props_;
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fabric/debug/DebugStringConvertible.h>
|
||||
@@ -22,14 +22,25 @@ namespace react {
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
inline std::string toString(const std::string &value) { return value; }
|
||||
inline std::string toString(const int &value) { return folly::to<std::string>(value); }
|
||||
inline std::string toString(const bool &value) { return folly::to<std::string>(value); }
|
||||
inline std::string toString(const float &value) { return folly::to<std::string>(value); }
|
||||
inline std::string toString(const double &value) { return folly::to<std::string>(value); }
|
||||
inline std::string toString(const std::string &value) {
|
||||
return value;
|
||||
}
|
||||
inline std::string toString(const int &value) {
|
||||
return folly::to<std::string>(value);
|
||||
}
|
||||
inline std::string toString(const bool &value) {
|
||||
return folly::to<std::string>(value);
|
||||
}
|
||||
inline std::string toString(const float &value) {
|
||||
return folly::to<std::string>(value);
|
||||
}
|
||||
inline std::string toString(const double &value) {
|
||||
return folly::to<std::string>(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, T value, T defaultValue = {}) {
|
||||
inline SharedDebugStringConvertible
|
||||
debugStringConvertibleItem(std::string name, T value, T defaultValue = {}) {
|
||||
if (value == defaultValue) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -38,23 +49,33 @@ inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, folly::Optional<T> value, T defaultValue = {}) {
|
||||
inline SharedDebugStringConvertible debugStringConvertibleItem(
|
||||
std::string name,
|
||||
folly::Optional<T> value,
|
||||
T defaultValue = {}) {
|
||||
if (!value.hasValue()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return debugStringConvertibleItem(name, value.value_or(defaultValue), defaultValue);
|
||||
return debugStringConvertibleItem(
|
||||
name, value.value_or(defaultValue), defaultValue);
|
||||
}
|
||||
|
||||
inline SharedDebugStringConvertibleList operator+(const SharedDebugStringConvertibleList &lhs, const SharedDebugStringConvertibleList &rhs) {
|
||||
auto result = SharedDebugStringConvertibleList {};
|
||||
inline SharedDebugStringConvertibleList operator+(
|
||||
const SharedDebugStringConvertibleList &lhs,
|
||||
const SharedDebugStringConvertibleList &rhs) {
|
||||
auto result = SharedDebugStringConvertibleList{};
|
||||
std::move(lhs.begin(), lhs.end(), std::back_inserter(result));
|
||||
std::move(rhs.begin(), rhs.end(), std::back_inserter(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
inline SharedDebugStringConvertible debugStringConvertibleItem(std::string name, DebugStringConvertible value, std::string defaultValue) {
|
||||
return debugStringConvertibleItem(name, value.getDebugDescription(), defaultValue);
|
||||
inline SharedDebugStringConvertible debugStringConvertibleItem(
|
||||
std::string name,
|
||||
DebugStringConvertible value,
|
||||
std::string defaultValue) {
|
||||
return debugStringConvertibleItem(
|
||||
name, value.getDebugDescription(), defaultValue);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,8 @@ using namespace facebook::react;
|
||||
|
||||
TEST(DebugStringConvertibleTest, handleSimpleNode) {
|
||||
SharedDebugStringConvertibleList empty;
|
||||
auto item = std::make_shared<DebugStringConvertibleItem>("View", "hello", empty, 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");
|
||||
@@ -24,9 +25,9 @@ TEST(DebugStringConvertibleTest, handleSimpleNode) {
|
||||
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);
|
||||
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");
|
||||
@@ -36,42 +37,48 @@ TEST(DebugStringConvertibleTest, handleSimpleNodeWithProps) {
|
||||
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);
|
||||
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");
|
||||
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)
|
||||
};
|
||||
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);
|
||||
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");
|
||||
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)
|
||||
};
|
||||
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);
|
||||
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");
|
||||
ASSERT_STREQ(
|
||||
item->getDebugDescription().c_str(),
|
||||
"<View=hello x=1(height=100 width=200)/>\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user