@@ -2574,6 +2574,86 @@ TEST(TYsonStructTest, OuterYsonStructWithValidation)
2574
2574
EXPECT_EQ (deserialized->Inner ->MyInt , 42 );
2575
2575
}
2576
2576
2577
+ struct TWithYsonString
2578
+ : public TYsonStructLite
2579
+ {
2580
+ NYson::TYsonString MyString;
2581
+
2582
+ REGISTER_YSON_STRUCT_LITE (TWithYsonString);
2583
+
2584
+ static void Register (TRegistrar registrar)
2585
+ {
2586
+ registrar.Parameter (" my_string" , &TThis::MyString)
2587
+ .Default ();
2588
+ }
2589
+ };
2590
+
2591
+ TEST (TYsonStructTest, TYsonStringFieldSimple)
2592
+ {
2593
+ TWithYsonString value;
2594
+
2595
+ {
2596
+ auto node = BuildYsonNodeFluently ()
2597
+ .BeginMap ()
2598
+ .Item (" my_string" ).Value (ConvertToYsonString (42 ))
2599
+ .EndMap ();
2600
+
2601
+ Deserialize (value, node->AsMap ());
2602
+ EXPECT_TRUE (value.MyString );
2603
+ EXPECT_EQ (ConvertTo<i32 >(value.MyString ), 42 );
2604
+ }
2605
+
2606
+ {
2607
+ std::string message{" Hi mom!" };
2608
+
2609
+ auto node = BuildYsonNodeFluently ()
2610
+ .BeginMap ()
2611
+ .Item (" my_string" ).Value (ConvertToYsonString (message))
2612
+ .EndMap ();
2613
+
2614
+ Deserialize (value, node->AsMap ());
2615
+ EXPECT_TRUE (value.MyString );
2616
+ EXPECT_EQ (ConvertTo<std::string>(value.MyString ), message);
2617
+ }
2618
+
2619
+ {
2620
+ auto config = New<TTestConfig>();
2621
+ config->MyString = " Hello, world!" ;
2622
+
2623
+ auto node = BuildYsonNodeFluently ()
2624
+ .BeginMap ()
2625
+ .Item (" my_string" ).Value (ConvertToYsonString (config))
2626
+ .EndMap ();
2627
+
2628
+ Deserialize (value, node->AsMap ());
2629
+ EXPECT_TRUE (value.MyString );
2630
+
2631
+ auto extracted = ConvertTo<TTestConfigPtr>(value.MyString );
2632
+ EXPECT_EQ (extracted->NullableInt , config->NullableInt );
2633
+ EXPECT_EQ (extracted->MyString , extracted->MyString );
2634
+ }
2635
+ }
2636
+
2637
+ TEST (TYsonStructTest, TYsonStringFieldCompound)
2638
+ {
2639
+ TWithYsonString value;
2640
+
2641
+ auto config = New<TTestConfig>();
2642
+ config->MyString = " Hello, world!" ;
2643
+
2644
+ auto node = BuildYsonNodeFluently ()
2645
+ .BeginMap ()
2646
+ .Item (" my_string" ).Value (ConvertToYsonString (config))
2647
+ .EndMap ();
2648
+
2649
+ Deserialize (value, node->AsMap ());
2650
+ EXPECT_TRUE (value.MyString );
2651
+
2652
+ auto extracted = ConvertTo<TTestConfigPtr>(value.MyString );
2653
+ EXPECT_EQ (extracted->NullableInt , config->NullableInt );
2654
+ EXPECT_EQ (extracted->MyString , extracted->MyString );
2655
+ }
2656
+
2577
2657
// //////////////////////////////////////////////////////////////////////////////
2578
2658
2579
2659
struct TPolyBase
0 commit comments