csullivan commented on code in PR #15672:
URL: https://github.com/apache/tvm/pull/15672#discussion_r1322172370
##########
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:
A rather small set of tests, albeit for a fairly small API surface as
compared to Array and Map. Are there other tests we could add? Maybe check
assignment?
```
TEST(Variant, Assignment) {
Variant<PrimExpr, String> variant;
Variant<PrimExpr, String> variant2 = String("foo");
variant = PrimExpr(1);
variant2 = variant;
ICHECK(variant2.as<PrimExpr>());
# check the value of variant2
}
```
--
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]