blob: 2e6640b8b1cab843d4b617246a8be6dd1f11a4fb [file] [log] [blame]
Bram Moolenaar4019cf92017-01-28 16:39:34 +01001/* vi:set ts=8 sts=4 sw=4 noet:
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 * kword_test.c: Unittests for vim_iswordc() and vim_iswordp().
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 the tested functions are static */
22#include "charset.c"
23
24#ifdef FEAT_MBYTE
25/*
26 * Test the results of vim_iswordc() and vim_iswordp() are matched.
27 */
28 static void
29test_isword_funcs_utf8(void)
30{
31 buf_T buf;
32 int c;
33
34 vim_memset(&buf, 0, sizeof(buf));
35 p_enc = (char_u *)"utf-8";
36 p_isi = (char_u *)"";
37 p_isp = (char_u *)"";
38 p_isf = (char_u *)"";
39 buf.b_p_isk = (char_u *)"@,48-57,_,128-167,224-235";
40
41 curbuf = &buf;
42 mb_init(); /* calls init_chartab() */
43
44 for (c = 0; c < 0x10000; ++c)
45 {
46 char_u p[4] = {0};
47 int c1;
48 int retc;
49 int retp;
50
51 utf_char2bytes(c, p);
52 c1 = utf_ptr2char(p);
53 if (c != c1)
54 {
55 fprintf(stderr, "Failed: ");
56 fprintf(stderr,
57 "[c = %#04x, p = {%#02x, %#02x, %#02x}] ",
58 c, p[0], p[1], p[2]);
59 fprintf(stderr, "c != utf_ptr2char(p) (=%#04x)\n", c1);
60 abort();
61 }
62 retc = vim_iswordc_buf(c, &buf);
63 retp = vim_iswordp_buf(p, &buf);
64 if (retc != retp)
65 {
66 fprintf(stderr, "Failed: ");
67 fprintf(stderr,
68 "[c = %#04x, p = {%#02x, %#02x, %#02x}] ",
69 c, p[0], p[1], p[2]);
70 fprintf(stderr, "vim_iswordc(c) (=%d) != vim_iswordp(p) (=%d)\n",
71 retc, retp);
72 abort();
73 }
74 }
75}
76#endif
77
78 int
79main(void)
80{
81#ifdef FEAT_MBYTE
82 test_isword_funcs_utf8();
83#endif
84 return 0;
85}