mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add tests for AttributedStringBox
Summary: Changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D26168698 fbshipit-source-id: 4416c01a3d4b3721964e2c73e145fb346f45a66a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
93377ff508
commit
177e147335
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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 <gtest/gtest.h>
|
||||
#include <react/renderer/attributedstring/AttributedStringBox.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
TEST(AttributedStringBoxTest, testDefaultConstructor) {
|
||||
auto attributedStringBox = AttributedStringBox{};
|
||||
|
||||
EXPECT_EQ(attributedStringBox.getMode(), AttributedStringBox::Mode::Value);
|
||||
EXPECT_EQ(attributedStringBox.getValue(), AttributedString{});
|
||||
}
|
||||
|
||||
TEST(AttributedStringBoxTest, testValueConstructor) {
|
||||
auto attributedString = AttributedString{};
|
||||
auto fragment = AttributedString::Fragment{};
|
||||
fragment.string = "test string";
|
||||
attributedString.appendFragment(fragment);
|
||||
auto attributedStringBox = AttributedStringBox{attributedString};
|
||||
|
||||
EXPECT_EQ(attributedStringBox.getMode(), AttributedStringBox::Mode::Value);
|
||||
EXPECT_EQ(attributedStringBox.getValue(), attributedString);
|
||||
}
|
||||
|
||||
TEST(AttributedStringBoxTest, testOpaquePointerConstructor) {
|
||||
auto string = std::make_shared<std::string>("test string");
|
||||
auto attributedStringBox = AttributedStringBox{string};
|
||||
|
||||
EXPECT_EQ(
|
||||
attributedStringBox.getMode(), AttributedStringBox::Mode::OpaquePointer);
|
||||
EXPECT_EQ(attributedStringBox.getOpaquePointer(), string);
|
||||
EXPECT_EQ(string.use_count(), 2);
|
||||
}
|
||||
|
||||
TEST(AttributedStringBoxTest, testMoveConstructor) {
|
||||
{
|
||||
auto string = std::make_shared<std::string>("test string");
|
||||
auto movedFromAttributedStringBox = AttributedStringBox{string};
|
||||
|
||||
auto moveToAttributedStringBox =
|
||||
AttributedStringBox{std::move(movedFromAttributedStringBox)};
|
||||
|
||||
EXPECT_EQ(
|
||||
moveToAttributedStringBox.getMode(),
|
||||
AttributedStringBox::Mode::OpaquePointer);
|
||||
EXPECT_EQ(moveToAttributedStringBox.getOpaquePointer(), string);
|
||||
EXPECT_EQ(string.use_count(), 2);
|
||||
}
|
||||
{
|
||||
auto attributedString = AttributedString{};
|
||||
auto fragment = AttributedString::Fragment{};
|
||||
fragment.string = "test string";
|
||||
attributedString.appendFragment(fragment);
|
||||
auto movedFromAttributedStringBox = AttributedStringBox{attributedString};
|
||||
|
||||
auto moveToAttributedStringBox =
|
||||
AttributedStringBox{std::move(movedFromAttributedStringBox)};
|
||||
|
||||
EXPECT_EQ(
|
||||
moveToAttributedStringBox.getMode(), AttributedStringBox::Mode::Value);
|
||||
EXPECT_EQ(moveToAttributedStringBox.getValue(), attributedString);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AttributedStringBoxTest, testMoveAssignment) {
|
||||
{
|
||||
auto string = std::make_shared<std::string>("test string");
|
||||
auto movedFromAttributedStringBox = AttributedStringBox{string};
|
||||
|
||||
auto movedToAttributedStringBox = AttributedStringBox{};
|
||||
movedToAttributedStringBox = std::move(movedFromAttributedStringBox);
|
||||
|
||||
EXPECT_EQ(
|
||||
movedToAttributedStringBox.getMode(),
|
||||
AttributedStringBox::Mode::OpaquePointer);
|
||||
EXPECT_EQ(movedToAttributedStringBox.getOpaquePointer(), string);
|
||||
EXPECT_EQ(string.use_count(), 2);
|
||||
}
|
||||
{
|
||||
auto attributedString = AttributedString{};
|
||||
auto fragment = AttributedString::Fragment{};
|
||||
fragment.string = "test string";
|
||||
attributedString.appendFragment(fragment);
|
||||
auto movedFromAttributedStringBox = AttributedStringBox{attributedString};
|
||||
|
||||
auto moveToAttributedStringBox = AttributedStringBox{};
|
||||
moveToAttributedStringBox = std::move(movedFromAttributedStringBox);
|
||||
|
||||
EXPECT_EQ(
|
||||
moveToAttributedStringBox.getMode(), AttributedStringBox::Mode::Value);
|
||||
EXPECT_EQ(moveToAttributedStringBox.getValue(), attributedString);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user