diff options
author | Ralf Schandl <rakus@users.noreply.github.com> | 2021-05-28 14:12:14 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-05-28 14:12:14 +0200 |
commit | bc869874fedf094129831836f131c64f10d98854 (patch) | |
tree | 25f910004b20bbfd23fda1d1e55287ce768f1552 /src/message_test.c | |
parent | 89dcb4dce369de22fba13b9c3c63f11f8d42650b (diff) | |
download | vim-git-bc869874fedf094129831836f131c64f10d98854.tar.gz |
patch 8.2.2893: multi-byte text in popup title shows up wrongv8.2.2893
Problem: Multi-byte text in popup title shows up wrong.
Solution: Use the character width instead of the byte length. (Ralf Schandl,
closes #8267, closes #8264)
Diffstat (limited to 'src/message_test.c')
-rw-r--r-- | src/message_test.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/message_test.c b/src/message_test.c index 88335de26..882b591e4 100644 --- a/src/message_test.c +++ b/src/message_test.c @@ -121,6 +121,37 @@ test_trunc_string(void) } /* + * Test trunc_string() with mbyte chars. + */ + static void +test_trunc_string_mbyte(void) +{ + char_u *buf; // allocated every time to find uninit errors + char_u *s; + + buf = alloc(40); + s = vim_strsave((char_u *)"Ä text tha just fits"); + trunc_string(s, buf, 20, 40); + assert(STRCMP(buf, "Ä text tha just fits") == 0); + vim_free(buf); + vim_free(s); + + buf = alloc(40); + s = vim_strsave((char_u *)"a text ÄÖÜä nott fits"); + trunc_string(s, buf, 20, 40); + assert(STRCMP(buf, "a text Ä...nott fits") == 0); + vim_free(buf); + vim_free(s); + + buf = alloc(40); + s = vim_strsave((char_u *)"a text that not fitsÄ"); + trunc_string(s, buf, 20, 40); + assert(STRCMP(buf, "a text t...not fitsÄ") == 0); + vim_free(buf); + vim_free(s); +} + +/* * Test vim_snprintf() with a focus on checking that truncation is * correct when buffer is small, since it cannot be tested from * vim scrip tests. Check that: @@ -286,6 +317,7 @@ main(int argc, char **argv) set_option_value((char_u *)"encoding", 0, (char_u *)"utf-8", 0); init_chartab(); test_trunc_string(); + test_trunc_string_mbyte(); test_vim_snprintf(); set_option_value((char_u *)"encoding", 0, (char_u *)"latin1", 0); |