summaryrefslogtreecommitdiff
path: root/src/testdir/test_utf8.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-04-06 13:18:12 +0200
committerBram Moolenaar <Bram@vim.org>2019-04-06 13:18:12 +0200
commit9d40128afd7fcd038ff6532722b55b1a8c189ce8 (patch)
tree158eb1ffa1c9e3b6a152284c96668d666677d3f3 /src/testdir/test_utf8.vim
parent4a5711b5ea54525a262a57ec0d418f76504bad46 (diff)
downloadvim-git-9d40128afd7fcd038ff6532722b55b1a8c189ce8.tar.gz
patch 8.1.1122: char2nr() does not handle composing charactersv8.1.1122
Problem: char2nr() does not handle composing characters. Solution: Add str2list() and list2str(). (Ozaki Kiichi, closes #4190)
Diffstat (limited to 'src/testdir/test_utf8.vim')
-rw-r--r--src/testdir/test_utf8.vim43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/testdir/test_utf8.vim b/src/testdir/test_utf8.vim
index 80ca8b529..ab1616aed 100644
--- a/src/testdir/test_utf8.vim
+++ b/src/testdir/test_utf8.vim
@@ -62,6 +62,49 @@ func Test_getvcol()
call assert_equal(2, virtcol("']"))
endfunc
+func Test_list2str_str2list_utf8()
+ " One Unicode codepoint
+ let s = "\u3042\u3044"
+ let l = [0x3042, 0x3044]
+ call assert_equal(l, str2list(s, 1))
+ call assert_equal(s, list2str(l, 1))
+ if &enc ==# 'utf-8'
+ call assert_equal(str2list(s), str2list(s, 1))
+ call assert_equal(list2str(l), list2str(l, 1))
+ endif
+
+ " With composing characters
+ let s = "\u304b\u3099\u3044"
+ let l = [0x304b, 0x3099, 0x3044]
+ call assert_equal(l, str2list(s, 1))
+ call assert_equal(s, list2str(l, 1))
+ if &enc ==# 'utf-8'
+ call assert_equal(str2list(s), str2list(s, 1))
+ call assert_equal(list2str(l), list2str(l, 1))
+ endif
+
+ " Null list is the same as an empty list
+ call assert_equal('', list2str([]))
+ call assert_equal('', list2str(test_null_list()))
+endfunc
+
+func Test_list2str_str2list_latin1()
+ " When 'encoding' is not multi-byte can still get utf-8 string.
+ " But we need to create the utf-8 string while 'encoding' is utf-8.
+ let s = "\u3042\u3044"
+ let l = [0x3042, 0x3044]
+
+ let save_encoding = &encoding
+ set encoding=latin1
+
+ let lres = str2list(s, 1)
+ let sres = list2str(l, 1)
+
+ let &encoding = save_encoding
+ call assert_equal(l, lres)
+ call assert_equal(s, sres)
+endfunc
+
func Test_screenchar_utf8()
new