summaryrefslogtreecommitdiffstats
path: root/tests/core/string/test_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core/string/test_string.h')
-rw-r--r--tests/core/string/test_string.h56
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index a9f615af84..0131f4c02a 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -1888,7 +1888,7 @@ TEST_CASE("[String] validate_node_name") {
CHECK(name_with_invalid_chars.validate_node_name() == "Name with invalid characters ____removed!");
}
-TEST_CASE("[String] validate_identifier") {
+TEST_CASE("[String] validate_ascii_identifier") {
String empty_string;
CHECK(empty_string.validate_ascii_identifier() == "_");
@@ -1902,6 +1902,20 @@ TEST_CASE("[String] validate_identifier") {
CHECK(name_with_invalid_chars.validate_ascii_identifier() == "Invalid_characters_______");
}
+TEST_CASE("[String] validate_unicode_identifier") {
+ String empty_string;
+ CHECK(empty_string.validate_unicode_identifier() == "_");
+
+ String numeric_only = "12345";
+ CHECK(numeric_only.validate_unicode_identifier() == "_12345");
+
+ String name_with_spaces = "Name with spaces";
+ CHECK(name_with_spaces.validate_unicode_identifier() == "Name_with_spaces");
+
+ String name_with_invalid_chars = U"Invalid characters:@*#&世界";
+ CHECK(name_with_invalid_chars.validate_unicode_identifier() == U"Invalid_characters_____世界");
+}
+
TEST_CASE("[String] Variant indexed get") {
Variant s = String("abcd");
bool valid = false;
@@ -1974,6 +1988,46 @@ TEST_CASE("[String] Variant ptr indexed set") {
CHECK_EQ(s, String("azcd"));
}
+TEST_CASE("[String] parse_url") {
+ String scheme, host, path, fragment;
+ int port;
+
+ SUBCASE("Typical URL") {
+ Error err = String("https://docs.godotengine.org/en/stable/").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == OK);
+ CHECK_EQ(scheme, "https://");
+ CHECK_EQ(host, "docs.godotengine.org");
+ CHECK_EQ(port, 0);
+ CHECK_EQ(path, "/en/stable/");
+ CHECK_EQ(fragment, "");
+ }
+
+ SUBCASE("All Elements") {
+ Error err = String("https://www.example.com:8080/path/to/file.html#fragment").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == OK);
+ CHECK_EQ(scheme, "https://");
+ CHECK_EQ(host, "www.example.com");
+ CHECK_EQ(port, 8080);
+ CHECK_EQ(path, "/path/to/file.html");
+ CHECK_EQ(fragment, "fragment");
+ }
+
+ SUBCASE("Invalid Scheme") {
+ Error err = String("http_://example.com").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == ERR_INVALID_PARAMETER); // Host being empty is an error.
+ }
+
+ SUBCASE("Scheme vs Fragment") {
+ Error err = String("google.com/#goto=http://redirect_url/").parse_url(scheme, host, port, path, fragment);
+ REQUIRE(err == OK);
+ CHECK_EQ(scheme, "");
+ CHECK_EQ(host, "google.com");
+ CHECK_EQ(port, 0);
+ CHECK_EQ(path, "/");
+ CHECK_EQ(fragment, "goto=http://redirect_url/");
+ }
+}
+
TEST_CASE("[Stress][String] Empty via ' == String()'") {
for (int i = 0; i < 100000; ++i) {
String str = "Hello World!";