8
8
#include < memory>
9
9
10
10
#include < gtest/gtest.h>
11
+ #include < hermes/hermes.h>
11
12
#include < react/debug/flags.h>
12
13
#include < react/renderer/core/ConcreteShadowNode.h>
13
14
#include < react/renderer/core/PropsParserContext.h>
16
17
17
18
#include " TestComponent.h"
18
19
20
+ using namespace facebook ;
19
21
using namespace facebook ::react;
20
22
21
23
class PropsSingleFloat : public Props {
@@ -151,7 +153,7 @@ TEST(RawPropsTest, handleProps) {
151
153
ContextContainer contextContainer{};
152
154
PropsParserContext parserContext{-1 , contextContainer};
153
155
154
- const auto & raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
156
+ auto raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
155
157
auto parser = RawPropsParser ();
156
158
parser.prepare <Props>();
157
159
raw.parse (parser);
@@ -168,7 +170,7 @@ TEST(RawPropsTest, handleRawPropsSingleString) {
168
170
ContextContainer contextContainer{};
169
171
PropsParserContext parserContext{-1 , contextContainer};
170
172
171
- const auto & raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
173
+ auto raw = RawProps (folly::dynamic::object (" nativeID" , " abc" ));
172
174
auto parser = RawPropsParser ();
173
175
parser.prepare <Props>();
174
176
raw.parse (parser);
@@ -182,8 +184,7 @@ TEST(RawPropsTest, handleRawPropsSingleFloat) {
182
184
ContextContainer contextContainer{};
183
185
PropsParserContext parserContext{-1 , contextContainer};
184
186
185
- const auto & raw =
186
- RawProps (folly::dynamic::object (" floatValue" , (float )42.42 ));
187
+ auto raw = RawProps (folly::dynamic::object (" floatValue" , (float )42.42 ));
187
188
auto parser = RawPropsParser ();
188
189
parser.prepare <PropsSingleFloat>();
189
190
raw.parse (parser);
@@ -197,8 +198,7 @@ TEST(RawPropsTest, handleRawPropsSingleDouble) {
197
198
ContextContainer contextContainer{};
198
199
PropsParserContext parserContext{-1 , contextContainer};
199
200
200
- const auto & raw =
201
- RawProps (folly::dynamic::object (" doubleValue" , (double )42.42 ));
201
+ auto raw = RawProps (folly::dynamic::object (" doubleValue" , (double )42.42 ));
202
202
auto parser = RawPropsParser ();
203
203
parser.prepare <PropsSingleDouble>();
204
204
raw.parse (parser);
@@ -212,7 +212,7 @@ TEST(RawPropsTest, handleRawPropsSingleInt) {
212
212
ContextContainer contextContainer{};
213
213
PropsParserContext parserContext{-1 , contextContainer};
214
214
215
- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
215
+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
216
216
auto parser = RawPropsParser ();
217
217
parser.prepare <PropsSingleInt>();
218
218
raw.parse (parser);
@@ -226,7 +226,7 @@ TEST(RawPropsTest, handleRawPropsSingleIntGetManyTimes) {
226
226
ContextContainer contextContainer{};
227
227
PropsParserContext parserContext{-1 , contextContainer};
228
228
229
- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
229
+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42.42 ));
230
230
auto parser = RawPropsParser ();
231
231
parser.prepare <PropsSingleInt>();
232
232
raw.parse (parser);
@@ -240,7 +240,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypes) {
240
240
ContextContainer contextContainer{};
241
241
PropsParserContext parserContext{-1 , contextContainer};
242
242
243
- const auto & raw = RawProps (
243
+ auto raw = RawProps (
244
244
folly::dynamic::object (" intValue" , (int )42 )(" doubleValue" , (double )17.42 )(
245
245
" floatValue" ,
246
246
(float )66.67 )(" stringValue" , " helloworld" )(" boolValue" , true ));
@@ -262,7 +262,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetTwice) {
262
262
ContextContainer contextContainer{};
263
263
PropsParserContext parserContext{-1 , contextContainer};
264
264
265
- const auto & raw = RawProps (
265
+ auto raw = RawProps (
266
266
folly::dynamic::object (" intValue" , (int )42 )(" doubleValue" , (double )17.42 )(
267
267
" floatValue" ,
268
268
(float )66.67 )(" stringValue" , " helloworld" )(" boolValue" , true ));
@@ -292,7 +292,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetOutOfOrder) {
292
292
ContextContainer contextContainer{};
293
293
PropsParserContext parserContext{-1 , contextContainer};
294
294
295
- const auto & raw = RawProps (
295
+ auto raw = RawProps (
296
296
folly::dynamic::object (" intValue" , (int )42 )(" doubleValue" , (double )17.42 )(
297
297
" floatValue" ,
298
298
(float )66.67 )(" stringValue" , " helloworld" )(" boolValue" , true ));
@@ -322,7 +322,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncomplete) {
322
322
ContextContainer contextContainer{};
323
323
PropsParserContext parserContext{-1 , contextContainer};
324
324
325
- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
325
+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
326
326
327
327
auto parser = RawPropsParser ();
328
328
parser.prepare <PropsPrimitiveTypes>();
@@ -342,7 +342,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncorrectLookup) {
342
342
ContextContainer contextContainer{};
343
343
PropsParserContext parserContext{-1 , contextContainer};
344
344
345
- const auto & raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
345
+ auto raw = RawProps (folly::dynamic::object (" intValue" , (int )42 ));
346
346
347
347
auto parser = RawPropsParser ();
348
348
parser.prepare <PropsPrimitiveTypes>();
@@ -360,7 +360,7 @@ TEST(RawPropsTest, handlePropsMultiLookup) {
360
360
ContextContainer contextContainer{};
361
361
PropsParserContext parserContext{-1 , contextContainer};
362
362
363
- const auto & raw = RawProps (folly::dynamic::object (" floatValue" , (float )10.0 ));
363
+ auto raw = RawProps (folly::dynamic::object (" floatValue" , (float )10.0 ));
364
364
auto parser = RawPropsParser ();
365
365
parser.prepare <PropsMultiLookup>();
366
366
raw.parse (parser);
@@ -374,3 +374,96 @@ TEST(RawPropsTest, handlePropsMultiLookup) {
374
374
EXPECT_NEAR (props->floatValue , 10.0 , 0.00001 );
375
375
EXPECT_NEAR (props->derivedFloatValue , 20.0 , 0.00001 );
376
376
}
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