diff options
Diffstat (limited to 'tests/core/string/test_string.h')
-rw-r--r-- | tests/core/string/test_string.h | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index a9f615af84..8559737e74 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,61 @@ TEST_CASE("[String] Variant ptr indexed set") { CHECK_EQ(s, String("azcd")); } +TEST_CASE("[String][URL] Parse URL") { +#define CHECK_URL(m_url_to_parse, m_expected_schema, m_expected_host, m_expected_port, m_expected_path, m_expected_fragment, m_expected_error) \ + if (true) { \ + int port; \ + String url(m_url_to_parse), schema, host, path, fragment; \ + \ + CHECK_EQ(url.parse_url(schema, host, port, path, fragment), m_expected_error); \ + CHECK_EQ(schema, m_expected_schema); \ + CHECK_EQ(host, m_expected_host); \ + CHECK_EQ(path, m_expected_path); \ + CHECK_EQ(fragment, m_expected_fragment); \ + CHECK_EQ(port, m_expected_port); \ + } else \ + ((void)0) + + // All elements. + CHECK_URL("https://www.example.com:8080/path/to/file.html#fragment", "https://", "www.example.com", 8080, "/path/to/file.html", "fragment", Error::OK); + + // Valid URLs. + CHECK_URL("https://godotengine.org", "https://", "godotengine.org", 0, "", "", Error::OK); + CHECK_URL("https://godotengine.org/", "https://", "godotengine.org", 0, "/", "", Error::OK); + CHECK_URL("godotengine.org/", "", "godotengine.org", 0, "/", "", Error::OK); + CHECK_URL("HTTPS://godotengine.org/", "https://", "godotengine.org", 0, "/", "", Error::OK); + CHECK_URL("https://GODOTENGINE.ORG/", "https://", "godotengine.org", 0, "/", "", Error::OK); + CHECK_URL("http://godotengine.org", "http://", "godotengine.org", 0, "", "", Error::OK); + CHECK_URL("https://godotengine.org:8080", "https://", "godotengine.org", 8080, "", "", Error::OK); + CHECK_URL("https://godotengine.org/blog", "https://", "godotengine.org", 0, "/blog", "", Error::OK); + CHECK_URL("https://godotengine.org/blog/", "https://", "godotengine.org", 0, "/blog/", "", Error::OK); + CHECK_URL("https://docs.godotengine.org/en/stable", "https://", "docs.godotengine.org", 0, "/en/stable", "", Error::OK); + CHECK_URL("https://docs.godotengine.org/en/stable/", "https://", "docs.godotengine.org", 0, "/en/stable/", "", Error::OK); + CHECK_URL("https://me:secret@godotengine.org", "https://", "godotengine.org", 0, "", "", Error::OK); + CHECK_URL("https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]/ipv6", "https://", "fedc:ba98:7654:3210:fedc:ba98:7654:3210", 0, "/ipv6", "", Error::OK); + + // Scheme vs Fragment. + CHECK_URL("google.com/#goto=http://redirect_url/", "", "google.com", 0, "/", "goto=http://redirect_url/", Error::OK); + + // Invalid URLs. + + // Invalid Scheme. + CHECK_URL("https_://godotengine.org", "", "https_", 0, "//godotengine.org", "", Error::ERR_INVALID_PARAMETER); + + // Multiple ports. + CHECK_URL("https://godotengine.org:8080:433", "https://", "", 0, "", "", Error::ERR_INVALID_PARAMETER); + // Missing ] on literal IPv6. + CHECK_URL("https://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210/ipv6", "https://", "", 0, "/ipv6", "", Error::ERR_INVALID_PARAMETER); + // Missing host. + CHECK_URL("https:///blog", "https://", "", 0, "/blog", "", Error::ERR_INVALID_PARAMETER); + // Invalid ports. + CHECK_URL("https://godotengine.org:notaport", "https://", "godotengine.org", 0, "", "", Error::ERR_INVALID_PARAMETER); + CHECK_URL("https://godotengine.org:-8080", "https://", "godotengine.org", -8080, "", "", Error::ERR_INVALID_PARAMETER); + CHECK_URL("https://godotengine.org:88888", "https://", "godotengine.org", 88888, "", "", Error::ERR_INVALID_PARAMETER); + +#undef CHECK_URL +} + TEST_CASE("[Stress][String] Empty via ' == String()'") { for (int i = 0; i < 100000; ++i) { String str = "Hello World!"; |