From 2b5dd99d727a861e9e57b20f45227ef2063fb9fd Mon Sep 17 00:00:00 2001 From: Andres Kievsky Date: Tue, 31 Dec 2024 16:16:53 +1100 Subject: [PATCH] Add some tests for uid:// encoding and decoding --- tests/core/io/test_resource_uid.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/core/io/test_resource_uid.h b/tests/core/io/test_resource_uid.h index fe5508079e37..662dc520fc7b 100644 --- a/tests/core/io/test_resource_uid.h +++ b/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 UID -1 must encode correctly."); + CHECK_MESSAGE(rid->text_to_id("uid://") == -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