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