summaryrefslogtreecommitdiff
path: root/main/tests
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2019-01-04 16:01:54 +0000
committerHein-Pieter van Braam <hp@tmm.cx>2019-01-04 17:48:03 +0000
commitac99ed3cda12abe155f16a96ac0c716b2dbe6231 (patch)
tree2bae704d3f5852b415555b8393ec8eddf3b00500 /main/tests
parent1504c961125c76f007bc2ff061c3854effbe3e56 (diff)
String[size()] should return a default constructed CharType
As per the C++ standard 21.3.4.1 for std::string: Returns: If pos < size(), returns data()[pos]. Otherwise, if pos == size(), the const version returns charT(). Otherwise, the behavior is undefined. Since the behavior is undefined Godot now does the same thing for const and non-const versions of operator[]. This fixes #21242 and fixes #22221.
Diffstat (limited to 'main/tests')
-rw-r--r--main/tests/test_string.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp
index ddc36e807c..b4aeb4d215 100644
--- a/main/tests/test_string.cpp
+++ b/main/tests/test_string.cpp
@@ -942,6 +942,33 @@ bool test_30() {
OS::get_singleton()->print("Capitalize %ls: %ls, %s\n", input.c_str(), output.c_str(), success ? "OK" : "FAIL");
return state;
+}
+
+bool test_31() {
+ bool state = true;
+ bool success;
+
+ String a = "";
+ success = a[0] == 0;
+ OS::get_singleton()->print("Is 0 String[0]:, %s\n", success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ String b = "Godot";
+ success = b[b.size()] == 0;
+ OS::get_singleton()->print("Is 0 String[size()]:, %s\n", success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ const String c = "";
+ success = c[0] == 0;
+ OS::get_singleton()->print("Is 0 const String[0]:, %s\n", success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ const String d = "Godot";
+ success = d[d.size()] == 0;
+ OS::get_singleton()->print("Is 0 const String[size()]:, %s\n", success ? "OK" : "FAIL");
+ if (!success) state = false;
+
+ return state;
};
typedef bool (*TestFunc)(void);
@@ -978,6 +1005,7 @@ TestFunc test_funcs[] = {
test_28,
test_29,
test_30,
+ test_31,
0
};