diff options
Diffstat (limited to 'tests/test_string.h')
| -rw-r--r-- | tests/test_string.h | 40 | 
1 files changed, 34 insertions, 6 deletions
diff --git a/tests/test_string.h b/tests/test_string.h index 17f24fb0d8..6e214574af 100644 --- a/tests/test_string.h +++ b/tests/test_string.h @@ -299,6 +299,7 @@ TEST_CASE("[String] hex_encode_buffer") {  TEST_CASE("[String] Substr") {  	String s = "Killer Baby";  	CHECK(s.substr(3, 4) == "ler "); +	CHECK(s.substr(3) == "ler Baby");  }  TEST_CASE("[String] Find") { @@ -860,10 +861,10 @@ TEST_CASE("[String] match") {  }  TEST_CASE("[String] IPVX address to string") { -	IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); -	IP_Address ip(0x0123, 0x4567, 0x89ab, 0xcdef, true); -	IP_Address ip2("fe80::52e5:49ff:fe93:1baf"); -	IP_Address ip3("::ffff:192.168.0.1"); +	IPAddress ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); +	IPAddress ip(0x0123, 0x4567, 0x89ab, 0xcdef, true); +	IPAddress ip2("fe80::52e5:49ff:fe93:1baf"); +	IPAddress ip3("::ffff:192.168.0.1");  	String ip4 = "192.168.0.1";  	CHECK(ip4.is_valid_ip_address()); @@ -1045,7 +1046,7 @@ TEST_CASE("[String] lstrip and rstrip") {  TEST_CASE("[String] ensuring empty string into parse_utf8 passes empty string") {  	String empty; -	CHECK(empty.parse_utf8(NULL, -1)); +	CHECK(empty.parse_utf8(nullptr, -1));  }  TEST_CASE("[String] Cyrillic to_lower()") { @@ -1156,6 +1157,17 @@ TEST_CASE("[String] uri_encode/unescape") {  	String s = "Godot Engine:'docs'";  	String t = "Godot%20Engine%3A%27docs%27"; +	String x1 = "T%C4%93%C5%A1t"; +	static const uint8_t u8str[] = { 0x54, 0xC4, 0x93, 0xC5, 0xA1, 0x74, 0x00 }; +	String x2 = String::utf8((const char *)u8str); +	String x3 = U"Tēšt"; + +	CHECK(x1.uri_decode() == x2); +	CHECK(x1.uri_decode() == x3); +	CHECK((x1 + x3).uri_decode() == (x2 + x3)); // Mixed unicode and URL encoded string, e.g. GTK+ bookmark. +	CHECK(x2.uri_encode() == x1); +	CHECK(x3.uri_encode() == x1); +  	CHECK(s.uri_encode() == t);  	CHECK(t.uri_decode() == s);  } @@ -1241,8 +1253,10 @@ TEST_CASE("[String] Trim") {  TEST_CASE("[String] Right/Left") {  	String s = "aaaTestbbb";  	//                ^ -	CHECK(s.right(6) == "tbbb"); +	CHECK(s.right(6) == "estbbb"); +	CHECK(s.right(-6) == "tbbb");  	CHECK(s.left(6) == "aaaTes"); +	CHECK(s.left(-6) == "aaaT");  }  TEST_CASE("[String] Repeat") { @@ -1318,6 +1332,20 @@ TEST_CASE("[String] humanize_size") {  	CHECK(String::humanize_size(100523550) == "95.86 MiB");  	CHECK(String::humanize_size(5345555000) == "4.97 GiB");  } + +TEST_CASE("[String] validate_node_name") { +	String numeric_only = "12345"; +	CHECK(numeric_only.validate_node_name() == "12345"); + +	String name_with_spaces = "Name with spaces"; +	CHECK(name_with_spaces.validate_node_name() == "Name with spaces"); + +	String name_with_kana = "Name with kana ゴドツ"; +	CHECK(name_with_kana.validate_node_name() == "Name with kana ゴドツ"); + +	String name_with_invalid_chars = "Name with invalid characters :.@removed!"; +	CHECK(name_with_invalid_chars.validate_node_name() == "Name with invalid characters removed!"); +}  } // namespace TestString  #endif // TEST_STRING_H  |