Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 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 | |
Bram Moolenaar | 4ba37b5 | 2019-12-04 21:57:43 +0100 | [diff] [blame] | 17 | // Must include main.c because it contains much more than just main() |
Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 18 | #define NO_VIM_MAIN |
| 19 | #include "main.c" |
| 20 | |
Bram Moolenaar | 4ba37b5 | 2019-12-04 21:57:43 +0100 | [diff] [blame] | 21 | // This file has to be included because the tested functions are static |
Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 22 | #include "charset.c" |
| 23 | |
Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 24 | /* |
| 25 | * Test the results of vim_iswordc() and vim_iswordp() are matched. |
| 26 | */ |
| 27 | static void |
| 28 | test_isword_funcs_utf8(void) |
| 29 | { |
| 30 | buf_T buf; |
| 31 | int c; |
| 32 | |
| 33 | vim_memset(&buf, 0, sizeof(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; |
Bram Moolenaar | 4ba37b5 | 2019-12-04 21:57:43 +0100 | [diff] [blame] | 41 | mb_init(); // calls init_chartab() |
Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 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 | } |
Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 75 | |
| 76 | int |
| 77 | main(void) |
| 78 | { |
Bram Moolenaar | 1a47ae3 | 2019-12-29 23:04:25 +0100 | [diff] [blame] | 79 | estack_init(); |
Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 80 | test_isword_funcs_utf8(); |
Bram Moolenaar | 4019cf9 | 2017-01-28 16:39:34 +0100 | [diff] [blame] | 81 | return 0; |
| 82 | } |