tqchen commented on a change in pull request #4628: [Object] Add String
container
URL: https://github.com/apache/incubator-tvm/pull/4628#discussion_r376802418
##########
File path: tests/cpp/container_test.cc
##########
@@ -226,6 +226,94 @@ TEST(Map, Iterator) {
CHECK(map2[a].as<IntImmNode>()->value == 2);
}
+TEST(String, MoveFromStd) {
+ using namespace std;
+ string source = "this is a string";
+ string expect = source;
+ String s(std::move(source));
+ string copy = (string)s;
+ CHECK_EQ(copy, expect);
+ CHECK_EQ(source.size(), 0);
+}
+
+TEST(String, CopyFromStd) {
+ using namespace std;
+ string source = "this is a string";
+ string expect = source;
+ String s{source};
+ string copy = (string)s;
+ CHECK_EQ(copy, expect);
+ CHECK_EQ(source.size(), expect.size());
+}
+
+TEST(String, Assignment) {
+ using namespace std;
+ String s{string{"hello"}};
+ s = string{"world"};
+ CHECK_EQ(s == "world", true);
+ string s2{"world2"};
+ s = std::move(s2);
+ CHECK_EQ(s == "world2", true);
+}
+
+TEST(String, Comparisons) {
+ using namespace std;
+ string source = "a string";
+ string mismatch = "a string but longer";
+ String s{source};
+
+ CHECK_EQ(s == source, true);
+ CHECK_EQ(s == mismatch, false);
+ CHECK_EQ(s == source.data(), true);
+ CHECK_EQ(s == mismatch.data(), false);
+
+ // Check '\0' handling
+ string v1 = "hello world";
Review comment:
Add compare string with different length
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services