summaryrefslogtreecommitdiff
path: root/src/message_test.c
blob: 41b887579343712449b7b921104beacbe2ccaf62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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(&params, 0, sizeof(params));
    params.argc = argc;
    params.argv = argv;
    common_init(&params);
    init_chartab();

    test_trunc_string();
    return 0;
}