comparison src/kword_test.c @ 10724:ae1c6bf22e5f v8.0.0252

patch 8.0.0252: not properly recognizing word characters between 128 and 255 commit https://github.com/vim/vim/commit/4019cf90b8657d4ab1c39744db63550f44f405a2 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 28 16:39:34 2017 +0100 patch 8.0.0252: not properly recognizing word characters between 128 and 255 Problem: Characters below 256 that are not one byte are not always recognized as word characters. Solution: Make vim_iswordc() and vim_iswordp() work the same way. Add a test for this. (Ozaki Kiichi)
author Christian Brabandt <cb@256bit.org>
date Sat, 28 Jan 2017 16:45:04 +0100
parents
children 536dd2bc5ac9
comparison
equal deleted inserted replaced
10723:72cb227772e7 10724:ae1c6bf22e5f
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 #ifdef FEAT_MBYTE
25 /*
26 * Test the results of vim_iswordc() and vim_iswordp() are matched.
27 */
28 static void
29 test_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
79 main(void)
80 {
81 #ifdef FEAT_MBYTE
82 test_isword_funcs_utf8();
83 #endif
84 return 0;
85 }