Fix String::word_wrap() for long words
(cherry picked from commit 51fd1c27aa)
This commit is contained in:
@ -1211,6 +1211,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[] = {
|
||||
@ -1251,6 +1286,7 @@ TestFunc test_funcs[] = {
|
||||
test_34,
|
||||
test_35,
|
||||
test_36,
|
||||
test_37,
|
||||
nullptr
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user