diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-07-16 19:50:13 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-07-16 19:50:13 +0200 |
commit | 502ae4ba63561c98ac69af26cd9883bfd18d225f (patch) | |
tree | eeb8f200bd2cf8526bd96debaf35835fe03b1890 /src/message_test.c | |
parent | 015102e91e978a0bb42a14461c132a85e8f7e1ea (diff) | |
download | vim-git-502ae4ba63561c98ac69af26cd9883bfd18d225f.tar.gz |
patch 7.4.2051v7.4.2051
Problem: No proper testing of trunc_string().
Solution: Add a unittest for message.c.
Diffstat (limited to 'src/message_test.c')
-rw-r--r-- | src/message_test.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/message_test.c b/src/message_test.c new file mode 100644 index 000000000..41b887579 --- /dev/null +++ b/src/message_test.c @@ -0,0 +1,77 @@ +/* vi:set ts=8 sts=4 sw=4: + * + * VIM - Vi IMproved by Bram Moolenaar + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + +/* + * message_test.c: Unittests for message.c + */ + +#undef NDEBUG +#include <assert.h> + +/* Must include main.c because it contains much more than just main() */ +#define NO_VIM_MAIN +#include "main.c" + +/* This file has to be included because some of the tested functions are + * static. */ +#include "message.c" + +/* + * Test trunc_string(). + */ + static void +test_trunc_string(void) +{ + char_u buf[40]; + + /* in place */ + STRCPY(buf, "text"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "text") == 0); + + STRCPY(buf, "a short text"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "a short text") == 0); + + STRCPY(buf, "a text tha just fits"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "a text tha just fits") == 0); + + STRCPY(buf, "a text that nott fits"); + trunc_string(buf, buf, 20, 40); + assert(STRCMP(buf, "a text t...nott fits") == 0); + + /* copy from string to buf */ + trunc_string((char_u *)"text", buf, 20, 40); + assert(STRCMP(buf, "text") == 0); + + trunc_string((char_u *)"a short text", buf, 20, 40); + assert(STRCMP(buf, "a short text") == 0); + + trunc_string((char_u *)"a text tha just fits", buf, 20, 40); + assert(STRCMP(buf, "a text tha just fits") == 0); + + trunc_string((char_u *)"a text that nott fits", buf, 20, 40); + assert(STRCMP(buf, "a text t...nott fits") == 0); +} + + int +main(int argc, char **argv) +{ + mparm_T params; + + vim_memset(¶ms, 0, sizeof(params)); + params.argc = argc; + params.argv = argv; + common_init(¶ms); + init_chartab(); + + test_trunc_string(); + return 0; +} |