blob: 41b887579343712449b7b921104beacbe2ccaf62 [file] [log] [blame]
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * message_test.c: Unittests for message.c
12 */
13
14#undef NDEBUG
15#include <assert.h>
16
17/* Must include main.c because it contains much more than just main() */
18#define NO_VIM_MAIN
19#include "main.c"
20
21/* This file has to be included because some of the tested functions are
22 * static. */
23#include "message.c"
24
25/*
26 * Test trunc_string().
27 */
28 static void
29test_trunc_string(void)
30{
31 char_u buf[40];
32
33 /* in place */
34 STRCPY(buf, "text");
35 trunc_string(buf, buf, 20, 40);
36 assert(STRCMP(buf, "text") == 0);
37
38 STRCPY(buf, "a short text");
39 trunc_string(buf, buf, 20, 40);
40 assert(STRCMP(buf, "a short text") == 0);
41
42 STRCPY(buf, "a text tha just fits");
43 trunc_string(buf, buf, 20, 40);
44 assert(STRCMP(buf, "a text tha just fits") == 0);
45
46 STRCPY(buf, "a text that nott fits");
47 trunc_string(buf, buf, 20, 40);
48 assert(STRCMP(buf, "a text t...nott fits") == 0);
49
50 /* copy from string to buf */
51 trunc_string((char_u *)"text", buf, 20, 40);
52 assert(STRCMP(buf, "text") == 0);
53
54 trunc_string((char_u *)"a short text", buf, 20, 40);
55 assert(STRCMP(buf, "a short text") == 0);
56
57 trunc_string((char_u *)"a text tha just fits", buf, 20, 40);
58 assert(STRCMP(buf, "a text tha just fits") == 0);
59
60 trunc_string((char_u *)"a text that nott fits", buf, 20, 40);
61 assert(STRCMP(buf, "a text t...nott fits") == 0);
62}
63
64 int
65main(int argc, char **argv)
66{
67 mparm_T params;
68
69 vim_memset(&params, 0, sizeof(params));
70 params.argc = argc;
71 params.argv = argv;
72 common_init(&params);
73 init_chartab();
74
75 test_trunc_string();
76 return 0;
77}