summaryrefslogtreecommitdiffstats
path: root/tests/core
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2024-08-23 14:30:51 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2024-08-27 11:34:08 +0800
commit8bf4ecc026029eb7b16645c11930b73cf642dbfa (patch)
treef681d221372ac3ae1558941b016b4af47ff7ebe3 /tests/core
parentdb76de5de8a415b29be4c7dd84b99bd0fe260822 (diff)
downloadredot-engine-8bf4ecc026029eb7b16645c11930b73cf642dbfa.tar.gz
Add `String.is_valid_unicode_identifier()`
- Adds `is_valid_unicode_identifier()` - Adds `is_valid_ascii_identifier()` - Deprecates `is_valid_identifier()` - Renames `validate_identifier()` to `validate_ascii_identifier()`
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/object/test_class_db.h4
-rw-r--r--tests/core/string/test_string.h28
2 files changed, 17 insertions, 15 deletions
diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h
index 8515ba7644..924e93129d 100644
--- a/tests/core/object/test_class_db.h
+++ b/tests/core/object/test_class_db.h
@@ -603,7 +603,7 @@ void add_exposed_classes(Context &r_context) {
MethodData method;
method.name = method_info.name;
- TEST_FAIL_COND(!String(method.name).is_valid_identifier(),
+ TEST_FAIL_COND(!String(method.name).is_valid_ascii_identifier(),
"Method name is not a valid identifier: '", exposed_class.name, ".", method.name, "'.");
if (method_info.flags & METHOD_FLAG_VIRTUAL) {
@@ -729,7 +729,7 @@ void add_exposed_classes(Context &r_context) {
const MethodInfo &method_info = signal_map.get(K.key);
signal.name = method_info.name;
- TEST_FAIL_COND(!String(signal.name).is_valid_identifier(),
+ TEST_FAIL_COND(!String(signal.name).is_valid_ascii_identifier(),
"Signal name is not a valid identifier: '", exposed_class.name, ".", signal.name, "'.");
int i = 0;
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index 933eeff524..b47e5b1eb9 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -1821,21 +1821,23 @@ TEST_CASE("[String] Join") {
}
TEST_CASE("[String] Is_*") {
- static const char *data[12] = { "-30", "100", "10.1", "10,1", "1e2", "1e-2", "1e2e3", "0xAB", "AB", "Test1", "1Test", "Test*1" };
- static bool isnum[12] = { true, true, true, false, false, false, false, false, false, false, false, false };
- static bool isint[12] = { true, true, false, false, false, false, false, false, false, false, false, false };
- static bool ishex[12] = { true, true, false, false, true, false, true, false, true, false, false, false };
- static bool ishex_p[12] = { false, false, false, false, false, false, false, true, false, false, false, false };
- static bool isflt[12] = { true, true, true, false, true, true, false, false, false, false, false, false };
- static bool isid[12] = { false, false, false, false, false, false, false, false, true, true, false, false };
+ static const char *data[13] = { "-30", "100", "10.1", "10,1", "1e2", "1e-2", "1e2e3", "0xAB", "AB", "Test1", "1Test", "Test*1", "文字" };
+ static bool isnum[13] = { true, true, true, false, false, false, false, false, false, false, false, false, false };
+ static bool isint[13] = { true, true, false, false, false, false, false, false, false, false, false, false, false };
+ static bool ishex[13] = { true, true, false, false, true, false, true, false, true, false, false, false, false };
+ static bool ishex_p[13] = { false, false, false, false, false, false, false, true, false, false, false, false, false };
+ static bool isflt[13] = { true, true, true, false, true, true, false, false, false, false, false, false, false };
+ static bool isaid[13] = { false, false, false, false, false, false, false, false, true, true, false, false, false };
+ static bool isuid[13] = { false, false, false, false, false, false, false, false, true, true, false, false, true };
for (int i = 0; i < 12; i++) {
- String s = String(data[i]);
+ String s = String::utf8(data[i]);
CHECK(s.is_numeric() == isnum[i]);
CHECK(s.is_valid_int() == isint[i]);
CHECK(s.is_valid_hex_number(false) == ishex[i]);
CHECK(s.is_valid_hex_number(true) == ishex_p[i]);
CHECK(s.is_valid_float() == isflt[i]);
- CHECK(s.is_valid_identifier() == isid[i]);
+ CHECK(s.is_valid_ascii_identifier() == isaid[i]);
+ CHECK(s.is_valid_unicode_identifier() == isuid[i]);
}
}
@@ -1863,16 +1865,16 @@ TEST_CASE("[String] validate_node_name") {
TEST_CASE("[String] validate_identifier") {
String empty_string;
- CHECK(empty_string.validate_identifier() == "_");
+ CHECK(empty_string.validate_ascii_identifier() == "_");
String numeric_only = "12345";
- CHECK(numeric_only.validate_identifier() == "_12345");
+ CHECK(numeric_only.validate_ascii_identifier() == "_12345");
String name_with_spaces = "Name with spaces";
- CHECK(name_with_spaces.validate_identifier() == "Name_with_spaces");
+ CHECK(name_with_spaces.validate_ascii_identifier() == "Name_with_spaces");
String name_with_invalid_chars = U"Invalid characters:@*#&世界";
- CHECK(name_with_invalid_chars.validate_identifier() == "Invalid_characters_______");
+ CHECK(name_with_invalid_chars.validate_ascii_identifier() == "Invalid_characters_______");
}
TEST_CASE("[String] Variant indexed get") {