88#include < memory>
99
1010#include < gtest/gtest.h>
11+ #include < hermes/hermes.h>
1112#include < react/debug/flags.h>
1213#include < react/renderer/core/ConcreteShadowNode.h>
1314#include < react/renderer/core/PropsParserContext.h>
1617
1718#include " TestComponent.h"
1819
20+ using namespace facebook ;
1921using namespace facebook ::react;
2022
2123class PropsSingleFloat : public Props {
@@ -151,7 +153,7 @@ TEST(RawPropsTest, handleProps) {
151153 ContextContainer contextContainer{};
152154 PropsParserContext parserContext{-1 , contextContainer};
153155
154- const auto & raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
156+ auto raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
155157 auto parser = RawPropsParser ();
156158 parser.prepare <Props>();
157159 raw.parse (parser);
@@ -168,7 +170,7 @@ TEST(RawPropsTest, handleRawPropsSingleString) {
168170 ContextContainer contextContainer{};
169171 PropsParserContext parserContext{-1 , contextContainer};
170172
171- const auto & raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
173+ auto raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
172174 auto parser = RawPropsParser ();
173175 parser.prepare <Props>();
174176 raw.parse (parser);
@@ -182,8 +184,7 @@ TEST(RawPropsTest, handleRawPropsSingleFloat) {
182184 ContextContainer contextContainer{};
183185 PropsParserContext parserContext{-1 , contextContainer};
184186
185- const auto & raw =
186- RawProps (folly::dynamic::object (" floatValue" , (float )42.42 ));
187+ auto raw = RawProps (folly::dynamic::object (" floatValue" , (float )42.42 ));
187188 auto parser = RawPropsParser ();
188189 parser.prepare <PropsSingleFloat>();
189190 raw.parse (parser);
@@ -197,8 +198,7 @@ TEST(RawPropsTest, handleRawPropsSingleDouble) {
197198 ContextContainer contextContainer{};
198199 PropsParserContext parserContext{-1 , contextContainer};
199200
200- const auto & raw =
201- RawProps (folly::dynamic::object (" doubleValue" , (double )42.42 ));
201+ auto raw = RawProps (folly::dynamic::object (" doubleValue" , (double )42.42 ));
202202 auto parser = RawPropsParser ();
203203 parser.prepare <PropsSingleDouble>();
204204 raw.parse (parser);
@@ -212,7 +212,7 @@ TEST(RawPropsTest, handleRawPropsSingleInt) {
212212 ContextContainer contextContainer{};
213213 PropsParserContext parserContext{-1 , contextContainer};
214214
215- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
215+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
216216 auto parser = RawPropsParser ();
217217 parser.prepare <PropsSingleInt>();
218218 raw.parse (parser);
@@ -226,7 +226,7 @@ TEST(RawPropsTest, handleRawPropsSingleIntGetManyTimes) {
226226 ContextContainer contextContainer{};
227227 PropsParserContext parserContext{-1 , contextContainer};
228228
229- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
229+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
230230 auto parser = RawPropsParser ();
231231 parser.prepare <PropsSingleInt>();
232232 raw.parse (parser);
@@ -240,7 +240,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypes) {
240240 ContextContainer contextContainer{};
241241 PropsParserContext parserContext{-1 , contextContainer};
242242
243- const auto & raw = RawProps (
243+ auto raw = RawProps (
244244 folly::dynamic::object (" intValue" , (int )42 )(" doubleValue" , (double )17.42 )(
245245 " floatValue" ,
246246 (float )66.67 )(" stringValue" , " helloworld" )(" boolValue" , true ));
@@ -262,7 +262,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetTwice) {
262262 ContextContainer contextContainer{};
263263 PropsParserContext parserContext{-1 , contextContainer};
264264
265- const auto & raw = RawProps (
265+ auto raw = RawProps (
266266 folly::dynamic::object (" intValue" , (int )42 )(" doubleValue" , (double )17.42 )(
267267 " floatValue" ,
268268 (float )66.67 )(" stringValue" , " helloworld" )(" boolValue" , true ));
@@ -292,7 +292,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetOutOfOrder) {
292292 ContextContainer contextContainer{};
293293 PropsParserContext parserContext{-1 , contextContainer};
294294
295- const auto & raw = RawProps (
295+ auto raw = RawProps (
296296 folly::dynamic::object (" intValue" , (int )42 )(" doubleValue" , (double )17.42 )(
297297 " floatValue" ,
298298 (float )66.67 )(" stringValue" , " helloworld" )(" boolValue" , true ));
@@ -322,7 +322,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncomplete) {
322322 ContextContainer contextContainer{};
323323 PropsParserContext parserContext{-1 , contextContainer};
324324
325- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
325+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
326326
327327 auto parser = RawPropsParser ();
328328 parser.prepare <PropsPrimitiveTypes>();
@@ -342,7 +342,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncorrectLookup) {
342342 ContextContainer contextContainer{};
343343 PropsParserContext parserContext{-1 , contextContainer};
344344
345- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
345+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
346346
347347 auto parser = RawPropsParser ();
348348 parser.prepare <PropsPrimitiveTypes>();
@@ -360,7 +360,7 @@ TEST(RawPropsTest, handlePropsMultiLookup) {
360360 ContextContainer contextContainer{};
361361 PropsParserContext parserContext{-1 , contextContainer};
362362
363- const auto & raw = RawProps (folly::dynamic::object (" floatValue" , (float )10.0 ));
363+ auto raw = RawProps (folly::dynamic::object (" floatValue" , (float )10.0 ));
364364 auto parser = RawPropsParser ();
365365 parser.prepare <PropsMultiLookup>();
366366 raw.parse (parser);
@@ -374,3 +374,96 @@ TEST(RawPropsTest, handlePropsMultiLookup) {
374374 EXPECT_NEAR (props->floatValue , 10.0 , 0.00001 );
375375 EXPECT_NEAR (props->derivedFloatValue , 20.0 , 0.00001 );
376376}
377+
378+ TEST (RawPropsTest, copyDynamicRawProps) {
379+ ContextContainer contextContainer{};
380+ PropsParserContext parserContext{-1 , contextContainer};
381+
382+ auto rawProps = RawProps (folly::dynamic::object (" floatValue" , (float )10.0 ));
383+
384+ auto copy = RawProps (rawProps);
385+
386+ EXPECT_FALSE (copy.isEmpty ());
387+
388+ auto parser = RawPropsParser ();
389+ parser.prepare <PropsMultiLookup>();
390+
391+ rawProps.parse (parser);
392+ copy.parse (parser);
393+
394+ auto originalProps = std::make_shared<PropsMultiLookup>(
395+ parserContext, PropsMultiLookup (), rawProps);
396+ auto copyProps = std::make_shared<PropsMultiLookup>(
397+ parserContext, PropsMultiLookup (), copy);
398+
399+ // Props are not sealed after applying raw props.
400+ EXPECT_FALSE (copyProps->getSealed ());
401+
402+ EXPECT_NEAR (copyProps->floatValue , originalProps->floatValue , 0.00001 );
403+ EXPECT_NEAR (
404+ copyProps->derivedFloatValue , originalProps->derivedFloatValue , 0.00001 );
405+ }
406+
407+ TEST (RawPropsTest, copyEmptyRawProps) {
408+ ContextContainer contextContainer{};
409+ PropsParserContext parserContext{-1 , contextContainer};
410+
411+ auto rawProps = RawProps ();
412+
413+ auto copy = RawProps (rawProps);
414+
415+ EXPECT_TRUE (rawProps.isEmpty ());
416+ EXPECT_TRUE (copy.isEmpty ());
417+
418+ EXPECT_TRUE (((folly::dynamic)copy).empty ());
419+ }
420+
421+ TEST (RawPropsTest, copyNullJSIRawProps) {
422+ auto runtime = facebook::hermes::makeHermesRuntime ();
423+
424+ ContextContainer contextContainer{};
425+ PropsParserContext parserContext{-1 , contextContainer};
426+
427+ auto rawProps = RawProps (*runtime, jsi::Value::null ());
428+
429+ auto copy = RawProps (rawProps);
430+
431+ EXPECT_TRUE (rawProps.isEmpty ());
432+ EXPECT_TRUE (copy.isEmpty ());
433+
434+ EXPECT_TRUE (((folly::dynamic)copy).empty ());
435+ }
436+
437+ TEST (RawPropsTest, copyJSIRawProps) {
438+ auto runtime = facebook::hermes::makeHermesRuntime ();
439+
440+ ContextContainer contextContainer{};
441+ PropsParserContext parserContext{-1 , contextContainer};
442+
443+ auto object = jsi::Object (*runtime);
444+ object.setProperty (*runtime, " floatValue" , 10.0 );
445+
446+ auto rawProps = RawProps (*runtime, jsi::Value (*runtime, object));
447+ auto copy = RawProps (rawProps);
448+
449+ EXPECT_FALSE (rawProps.isEmpty ());
450+ EXPECT_FALSE (copy.isEmpty ());
451+
452+ auto parser = RawPropsParser ();
453+ parser.prepare <PropsMultiLookup>();
454+
455+ rawProps.parse (parser);
456+ copy.parse (parser);
457+
458+ auto originalProps = std::make_shared<PropsMultiLookup>(
459+ parserContext, PropsMultiLookup (), rawProps);
460+ auto copyProps = std::make_shared<PropsMultiLookup>(
461+ parserContext, PropsMultiLookup (), copy);
462+
463+ // Props are not sealed after applying raw props.
464+ EXPECT_FALSE (copyProps->getSealed ());
465+
466+ EXPECT_NEAR (copyProps->floatValue , originalProps->floatValue , 0.00001 );
467+ EXPECT_NEAR (
468+ copyProps->derivedFloatValue , originalProps->derivedFloatValue , 0.00001 );
469+ }
0 commit comments