DebugStringConvertibleTest.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #include <memory>
  8. #include <gtest/gtest.h>
  9. #include <react/debug/DebugStringConvertibleItem.h>
  10. using namespace facebook::react;
  11. TEST(DebugStringConvertibleTest, handleSimpleNode) {
  12. SharedDebugStringConvertibleList empty;
  13. auto item = std::make_shared<DebugStringConvertibleItem>(
  14. "View", "hello", empty, empty);
  15. ASSERT_STREQ(item->getDebugName().c_str(), "View");
  16. ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
  17. ASSERT_STREQ(item->getDebugDescription().c_str(), "<View=hello/>");
  18. }
  19. TEST(DebugStringConvertibleTest, handleSimpleNodeWithProps) {
  20. SharedDebugStringConvertibleList empty;
  21. SharedDebugStringConvertibleList props = {
  22. std::make_shared<DebugStringConvertibleItem>("x", "1", empty, empty)};
  23. auto item = std::make_shared<DebugStringConvertibleItem>(
  24. "View", "hello", props, empty);
  25. ASSERT_STREQ(item->getDebugName().c_str(), "View");
  26. ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
  27. ASSERT_STREQ(item->getDebugDescription().c_str(), "<View=hello x=1/>");
  28. }
  29. TEST(DebugStringConvertibleTest, handleSimpleNodeWithChildren) {
  30. SharedDebugStringConvertibleList empty;
  31. SharedDebugStringConvertibleList children = {
  32. std::make_shared<DebugStringConvertibleItem>("Child", "a", empty, empty)};
  33. auto item = std::make_shared<DebugStringConvertibleItem>(
  34. "View", "hello", empty, children);
  35. ASSERT_STREQ(item->getDebugName().c_str(), "View");
  36. ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
  37. ASSERT_STREQ(
  38. item->getDebugDescription().c_str(),
  39. "<View=hello>\n <Child=a/>\n</View>");
  40. }
  41. TEST(DebugStringConvertibleTest, handleNestedNode) {
  42. SharedDebugStringConvertibleList empty;
  43. SharedDebugStringConvertibleList props = {
  44. std::make_shared<DebugStringConvertibleItem>("x", "1", empty, empty)};
  45. SharedDebugStringConvertibleList children = {
  46. std::make_shared<DebugStringConvertibleItem>("Child", "a", props, empty)};
  47. auto item = std::make_shared<DebugStringConvertibleItem>(
  48. "View", "hello", props, children);
  49. ASSERT_STREQ(item->getDebugName().c_str(), "View");
  50. ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
  51. ASSERT_STREQ(
  52. item->getDebugDescription().c_str(),
  53. "<View=hello x=1>\n <Child=a x=1/>\n</View>");
  54. }
  55. TEST(DebugStringConvertibleTest, handleNodeWithComplexProps) {
  56. SharedDebugStringConvertibleList empty;
  57. SharedDebugStringConvertibleList subProps = {
  58. std::make_shared<DebugStringConvertibleItem>(
  59. "height", "100", empty, empty),
  60. std::make_shared<DebugStringConvertibleItem>(
  61. "width", "200", empty, empty)};
  62. SharedDebugStringConvertibleList props = {
  63. std::make_shared<DebugStringConvertibleItem>("x", "1", subProps, empty)};
  64. auto item = std::make_shared<DebugStringConvertibleItem>(
  65. "View", "hello", props, empty);
  66. ASSERT_STREQ(item->getDebugName().c_str(), "View");
  67. ASSERT_STREQ(item->getDebugValue().c_str(), "hello");
  68. ASSERT_STREQ(
  69. item->getDebugDescription().c_str(),
  70. "<View=hello x=1(height=100 width=200)/>");
  71. }