Browse Source

Add some tests for uid:// encoding and decoding

Andres Kievsky 7 months ago
parent
commit
2b5dd99d72
1 changed files with 19 additions and 0 deletions
  1. 19 0
      tests/core/io/test_resource_uid.h

+ 19 - 0
tests/core/io/test_resource_uid.h

@@ -47,6 +47,25 @@ TEST_CASE("[ResourceUID] Must encode/decode maximum/minimum UID correctly") {
 	CHECK_MESSAGE(ResourceUID::get_singleton()->text_to_id("uid://a") == 0, "Minimum UID must decode correctly.");
 }
 
+TEST_CASE("[ResourceUID] Must encode and decode invalid UIDs correctly") {
+	ResourceUID *rid = ResourceUID::get_singleton();
+	CHECK_MESSAGE(rid->id_to_text(-1) == "uid://<invalid>", "Invalid UID -1 must encode correctly.");
+	CHECK_MESSAGE(rid->text_to_id("uid://<invalid>") == -1, "Invalid UID -1 must decode correctly.");
+
+	CHECK_MESSAGE(rid->id_to_text(-2) == rid->id_to_text(-1), "Invalid UID -2 must encode to the same as -1.");
+
+	CHECK_MESSAGE(rid->text_to_id("dm3rdgs30kfci") == -1, "UID without scheme must decode correctly.");
+}
+
+TEST_CASE("[ResourceUID] Must encode and decode various UIDs correctly") {
+	ResourceUID *rid = ResourceUID::get_singleton();
+	CHECK_MESSAGE(rid->id_to_text(1) == "uid://b", "UID 1 must encode correctly.");
+	CHECK_MESSAGE(rid->text_to_id("uid://b") == 1, "UID 1 must decode correctly.");
+
+	CHECK_MESSAGE(rid->id_to_text(8060368642360689600) == "uid://dm3rdgs30kfci", "A normal UID must encode correctly.");
+	CHECK_MESSAGE(rid->text_to_id("uid://dm3rdgs30kfci") == 8060368642360689600, "A normal UID must decode correctly.");
+}
+
 } // namespace TestResourceUID
 
 #endif // TEST_RESOURCE_UID_H