tqchen commented on a change in pull request #4628: [Object] Add String
container
URL: https://github.com/apache/incubator-tvm/pull/4628#discussion_r387973349
##########
File path: tests/cpp/container_test.cc
##########
@@ -221,11 +222,154 @@ TEST(Map, Iterator) {
using namespace tvm;
PrimExpr a = 1, b = 2;
Map<PrimExpr, PrimExpr> map1{{a, b}};
- std::unordered_map<PrimExpr, PrimExpr, ObjectHash, ObjectEqual>
- map2(map1.begin(), map1.end());
+ std::unordered_map<PrimExpr, PrimExpr, ObjectHash, ObjectEqual> map2(
+ map1.begin(), map1.end());
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, empty) {
+ using namespace std;
+ String s{"hello"};
+ CHECK_EQ(s.empty(), false);
+ s = "";
+ CHECK_EQ(s.empty(), 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";
+ size_t v1_size = v1.size();
+ v1[5] = '\0';
+ CHECK_EQ(v1[5], '\0');
+ CHECK_EQ(v1.size(), v1_size);
Review comment:
Need to add test coverage to test cases that would have been different if
the str is defined to terminate at \0
----------------------------------------------------------------
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