Lunderberg commented on code in PR #15672:
URL: https://github.com/apache/tvm/pull/15672#discussion_r1323342788


##########
tests/cpp/container_test.cc:
##########
@@ -853,3 +854,23 @@ TEST(Optional, PackedCall) {
   test_ffi(s, static_cast<int>(kTVMObjectHandle));
   test_ffi(String(s), static_cast<int>(kTVMObjectRValueRefArg));
 }
+
+TEST(Variant, Construct) {
+  Variant<PrimExpr, String> variant;
+  variant = PrimExpr(1);
+  ICHECK(variant.as<PrimExpr>());
+  ICHECK(!variant.as<String>());
+
+  variant = String("hello");
+  ICHECK(variant.as<String>());
+  ICHECK(!variant.as<PrimExpr>());
+}
+
+TEST(Variant, InvalidTypeThrowsError) {
+  auto expected_to_throw = []() {
+    ObjectPtr<Object> node = make_object<Object>();
+    Variant<PrimExpr, String> variant(node);
+  };
+
+  EXPECT_THROW(expected_to_throw(), InternalError);
+}

Review Comment:
   Good point.  I made the API surface as small as possible, but there were 
additional tests that should be included.  I've added tests to validate that 
reference equality is preserved across `Variant` assignments, and that the 
values are correctly preserved.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to