@@ -474,4 +474,42 @@ namespace Nui::Tests
474
474
globalEventContext.executeActiveEventsImmediately ();
475
475
EXPECT_EQ (Nui::val::global (" document" )[" body" ][" attributes" ][" id" ].as <std::string>(), " B" );
476
476
}
477
+
478
+ TEST_F (TestAttributes, AttributeCanBeVariant1)
479
+ {
480
+ using Nui::Elements::div;
481
+ using Nui::Attributes::id;
482
+
483
+ std::variant<std::string, int > idValue{" A" };
484
+
485
+ render (div{id = idValue}());
486
+ EXPECT_EQ (Nui::val::global (" document" )[" body" ][" attributes" ][" id" ].as <std::string>(), " A" );
487
+ }
488
+
489
+ TEST_F (TestAttributes, AttributeCanBeVariant2)
490
+ {
491
+ using Nui::Elements::div;
492
+ using Nui::Attributes::id;
493
+
494
+ std::variant<std::string, int > idValue{2 };
495
+
496
+ render (div{id = idValue}());
497
+ EXPECT_EQ (Nui::val::global (" document" )[" body" ][" attributes" ][" id" ].as <long long >(), 2 );
498
+ }
499
+
500
+ TEST_F (TestAttributes, AttributeCanBeObservedVariant)
501
+ {
502
+ using Nui::Elements::div;
503
+ using Nui::Attributes::id;
504
+
505
+ Observed<std::variant<std::string, int >> idValue{" A" };
506
+
507
+ render (div{id = idValue}());
508
+ EXPECT_EQ (Nui::val::global (" document" )[" body" ][" attributes" ][" id" ].as <std::string>(), " A" );
509
+
510
+ idValue = 2 ;
511
+ globalEventContext.executeActiveEventsImmediately ();
512
+
513
+ EXPECT_EQ (Nui::val::global (" document" )[" body" ][" attributes" ][" id" ].as <long long >(), 2 );
514
+ }
477
515
}
0 commit comments