Mercurial > vim
comparison src/testdir/test_utf8.vim @ 16235:219c58b3879c v8.1.1122
patch 8.1.1122: char2nr() does not handle composing characters
commit https://github.com/vim/vim/commit/9d40128afd7fcd038ff6532722b55b1a8c189ce8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 6 13:18:12 2019 +0200
patch 8.1.1122: char2nr() does not handle composing characters
Problem: char2nr() does not handle composing characters.
Solution: Add str2list() and list2str(). (Ozaki Kiichi, closes https://github.com/vim/vim/issues/4190)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 06 Apr 2019 13:30:04 +0200 |
parents | 90b0f2227d73 |
children | 2e53305f2239 |
comparison
equal
deleted
inserted
replaced
16234:dbfd219fe9b3 | 16235:219c58b3879c |
---|---|
60 call assert_equal(4, col("']")) | 60 call assert_equal(4, col("']")) |
61 call assert_equal(2, virtcol("'[")) | 61 call assert_equal(2, virtcol("'[")) |
62 call assert_equal(2, virtcol("']")) | 62 call assert_equal(2, virtcol("']")) |
63 endfunc | 63 endfunc |
64 | 64 |
65 func Test_list2str_str2list_utf8() | |
66 " One Unicode codepoint | |
67 let s = "\u3042\u3044" | |
68 let l = [0x3042, 0x3044] | |
69 call assert_equal(l, str2list(s, 1)) | |
70 call assert_equal(s, list2str(l, 1)) | |
71 if &enc ==# 'utf-8' | |
72 call assert_equal(str2list(s), str2list(s, 1)) | |
73 call assert_equal(list2str(l), list2str(l, 1)) | |
74 endif | |
75 | |
76 " With composing characters | |
77 let s = "\u304b\u3099\u3044" | |
78 let l = [0x304b, 0x3099, 0x3044] | |
79 call assert_equal(l, str2list(s, 1)) | |
80 call assert_equal(s, list2str(l, 1)) | |
81 if &enc ==# 'utf-8' | |
82 call assert_equal(str2list(s), str2list(s, 1)) | |
83 call assert_equal(list2str(l), list2str(l, 1)) | |
84 endif | |
85 | |
86 " Null list is the same as an empty list | |
87 call assert_equal('', list2str([])) | |
88 call assert_equal('', list2str(test_null_list())) | |
89 endfunc | |
90 | |
91 func Test_list2str_str2list_latin1() | |
92 " When 'encoding' is not multi-byte can still get utf-8 string. | |
93 " But we need to create the utf-8 string while 'encoding' is utf-8. | |
94 let s = "\u3042\u3044" | |
95 let l = [0x3042, 0x3044] | |
96 | |
97 let save_encoding = &encoding | |
98 set encoding=latin1 | |
99 | |
100 let lres = str2list(s, 1) | |
101 let sres = list2str(l, 1) | |
102 | |
103 let &encoding = save_encoding | |
104 call assert_equal(l, lres) | |
105 call assert_equal(s, sres) | |
106 endfunc | |
107 | |
65 func Test_screenchar_utf8() | 108 func Test_screenchar_utf8() |
66 new | 109 new |
67 | 110 |
68 " 1-cell, with composing characters | 111 " 1-cell, with composing characters |
69 call setline(1, ["ABC\u0308"]) | 112 call setline(1, ["ABC\u0308"]) |