You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Merge pull request #64564 from timothyqiu/word-wrap-3.x
[3.x] Fix `String::word_wrap()` for long words
This commit is contained in:
@@ -1219,6 +1219,41 @@ bool test_36() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_37() {
|
||||
#define CHECK_EQ(X, Y) \
|
||||
if ((X) != (Y)) { \
|
||||
OS::get_singleton()->print("\tFAIL: %s != %s\n", #X, #Y); \
|
||||
return false; \
|
||||
} else { \
|
||||
OS::get_singleton()->print("\tPASS\n"); \
|
||||
}
|
||||
OS::get_singleton()->print("\n\nTest 37: Word wrap\n");
|
||||
|
||||
// Long words.
|
||||
CHECK_EQ(String("12345678").word_wrap(8), "12345678");
|
||||
CHECK_EQ(String("1234567812345678").word_wrap(8), "12345678\n12345678");
|
||||
CHECK_EQ(String("123456781234567812345678").word_wrap(8), "12345678\n12345678\n12345678");
|
||||
|
||||
// Long line.
|
||||
CHECK_EQ(String("123 567 123456 123").word_wrap(8), "123 567\n123456\n123");
|
||||
|
||||
// Force newline at line length should not create another newline.
|
||||
CHECK_EQ(String("12345678 123").word_wrap(8), "12345678\n123");
|
||||
CHECK_EQ(String("12345678\n123").word_wrap(8), "12345678\n123");
|
||||
|
||||
// Wrapping removes spaces.
|
||||
CHECK_EQ(String("1234567 123").word_wrap(8), "1234567\n123");
|
||||
CHECK_EQ(String("12345678 123").word_wrap(8), "12345678\n123");
|
||||
|
||||
// Wrapping does not remove leading space.
|
||||
CHECK_EQ(String(" 123456 123 12").word_wrap(8), " 123456\n123 12");
|
||||
CHECK_EQ(String(" 123456\n 456 12").word_wrap(8), " 123456\n 456\n12");
|
||||
CHECK_EQ(String(" 123456\n 4 12345678").word_wrap(8), " 123456\n 4\n12345678");
|
||||
CHECK_EQ(String(" 123456\n 4 12345678123").word_wrap(8), " 123456\n 4\n12345678\n123");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef bool (*TestFunc)();
|
||||
|
||||
TestFunc test_funcs[] = {
|
||||
@@ -1259,6 +1294,7 @@ TestFunc test_funcs[] = {
|
||||
test_34,
|
||||
test_35,
|
||||
test_36,
|
||||
test_37,
|
||||
nullptr
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user