2016-08-29 22:49:24 +02:00
|
|
|
/* vi:set ts=8 sts=4 sw=4 noet:
|
2016-07-16 19:50:13 +02:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2016-07-19 12:33:44 +02:00
|
|
|
char_u *buf; /*allocated every time to find uninit errors */
|
|
|
|
char_u *s;
|
2016-07-16 19:50:13 +02:00
|
|
|
|
|
|
|
/* in place */
|
2016-07-19 12:33:44 +02:00
|
|
|
buf = alloc(40);
|
2016-07-16 19:50:13 +02:00
|
|
|
STRCPY(buf, "text");
|
|
|
|
trunc_string(buf, buf, 20, 40);
|
|
|
|
assert(STRCMP(buf, "text") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
2016-07-16 19:50:13 +02:00
|
|
|
|
2016-07-19 12:33:44 +02:00
|
|
|
buf = alloc(40);
|
2016-07-16 19:50:13 +02:00
|
|
|
STRCPY(buf, "a short text");
|
|
|
|
trunc_string(buf, buf, 20, 40);
|
|
|
|
assert(STRCMP(buf, "a short text") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
2016-07-16 19:50:13 +02:00
|
|
|
|
2016-07-19 12:33:44 +02:00
|
|
|
buf = alloc(40);
|
2016-07-16 19:50:13 +02:00
|
|
|
STRCPY(buf, "a text tha just fits");
|
|
|
|
trunc_string(buf, buf, 20, 40);
|
|
|
|
assert(STRCMP(buf, "a text tha just fits") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
2016-07-16 19:50:13 +02:00
|
|
|
|
2016-07-19 12:33:44 +02:00
|
|
|
buf = alloc(40);
|
2016-07-16 19:50:13 +02:00
|
|
|
STRCPY(buf, "a text that nott fits");
|
|
|
|
trunc_string(buf, buf, 20, 40);
|
|
|
|
assert(STRCMP(buf, "a text t...nott fits") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
2016-07-16 19:50:13 +02:00
|
|
|
|
|
|
|
/* copy from string to buf */
|
2016-07-19 12:33:44 +02:00
|
|
|
buf = alloc(40);
|
|
|
|
s = vim_strsave((char_u *)"text");
|
|
|
|
trunc_string(s, buf, 20, 40);
|
2016-07-16 19:50:13 +02:00
|
|
|
assert(STRCMP(buf, "text") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
|
|
|
vim_free(s);
|
|
|
|
|
|
|
|
buf = alloc(40);
|
|
|
|
s = vim_strsave((char_u *)"a text that fits");
|
|
|
|
trunc_string(s, buf, 34, 40);
|
|
|
|
assert(STRCMP(buf, "a text that fits") == 0);
|
|
|
|
vim_free(buf);
|
|
|
|
vim_free(s);
|
|
|
|
|
|
|
|
buf = alloc(40);
|
|
|
|
s = vim_strsave((char_u *)"a short text");
|
|
|
|
trunc_string(s, buf, 20, 40);
|
2016-07-16 19:50:13 +02:00
|
|
|
assert(STRCMP(buf, "a short text") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
|
|
|
vim_free(s);
|
2016-07-16 19:50:13 +02:00
|
|
|
|
2016-07-19 12:33:44 +02:00
|
|
|
buf = alloc(40);
|
|
|
|
s = vim_strsave((char_u *)"a text tha just fits");
|
|
|
|
trunc_string(s, buf, 20, 40);
|
2016-07-16 19:50:13 +02:00
|
|
|
assert(STRCMP(buf, "a text tha just fits") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
|
|
|
vim_free(s);
|
2016-07-16 19:50:13 +02:00
|
|
|
|
2016-07-19 12:33:44 +02:00
|
|
|
buf = alloc(40);
|
|
|
|
s = vim_strsave((char_u *)"a text that nott fits");
|
|
|
|
trunc_string(s, buf, 20, 40);
|
2016-07-16 19:50:13 +02:00
|
|
|
assert(STRCMP(buf, "a text t...nott fits") == 0);
|
2016-07-19 12:33:44 +02:00
|
|
|
vim_free(buf);
|
|
|
|
vim_free(s);
|
2016-07-16 19:50:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
vim_memset(¶ms, 0, sizeof(params));
|
|
|
|
params.argc = argc;
|
|
|
|
params.argv = argv;
|
|
|
|
common_init(¶ms);
|
|
|
|
init_chartab();
|
|
|
|
|
|
|
|
test_trunc_string();
|
|
|
|
return 0;
|
|
|
|
}
|