test_digraph.vim 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. " Tests for digraphs
  2. source check.vim
  3. CheckFeature digraphs
  4. source term_util.vim
  5. func Put_Dig(chars)
  6. exe "norm! o\<c-k>".a:chars
  7. endfu
  8. func Put_Dig_BS(char1, char2)
  9. exe "norm! o".a:char1."\<bs>".a:char2
  10. endfu
  11. func Test_digraphs()
  12. new
  13. call Put_Dig("00")
  14. call assert_equal("∞", getline('.'))
  15. " not a digraph
  16. call Put_Dig("el")
  17. call assert_equal("l", getline('.'))
  18. call Put_Dig("ht")
  19. call assert_equal("þ", getline('.'))
  20. " digraph "ab" is the same as "ba"
  21. call Put_Dig("ab")
  22. call Put_Dig("ba")
  23. call assert_equal(["ば","ば"], getline(line('.')-1,line('.')))
  24. " Euro sign
  25. call Put_Dig("e=")
  26. call Put_Dig("=e")
  27. call Put_Dig("Eu")
  28. call Put_Dig("uE")
  29. call assert_equal(['е']+repeat(["€"],3), getline(line('.')-3,line('.')))
  30. " Rouble sign
  31. call Put_Dig("R=")
  32. call Put_Dig("=R")
  33. call Put_Dig("=P")
  34. call Put_Dig("P=")
  35. call assert_equal(['Р']+repeat(["₽"],2)+['П'], getline(line('.')-3,line('.')))
  36. " Quadruple prime
  37. call Put_Dig("'4")
  38. call assert_equal("⁗", getline('.'))
  39. " Not a digraph
  40. call Put_Dig("a\<bs>")
  41. call Put_Dig("\<bs>a")
  42. call assert_equal(["<BS>", "<BS>a"], getline(line('.')-1,line('.')))
  43. " Grave
  44. call Put_Dig("a!")
  45. call Put_Dig("!e")
  46. call Put_Dig("b!") " not defined
  47. call assert_equal(["à", "è", "!"], getline(line('.')-2,line('.')))
  48. " Acute accent
  49. call Put_Dig("a'")
  50. call Put_Dig("'e")
  51. call Put_Dig("b'") " not defined
  52. call assert_equal(["á", "é", "'"], getline(line('.')-2,line('.')))
  53. " Circumflex
  54. call Put_Dig("a>")
  55. call Put_Dig(">e")
  56. call Put_Dig("b>") " not defined
  57. call assert_equal(['â', 'ê', '>'], getline(line('.')-2,line('.')))
  58. " Tilde
  59. call Put_Dig("o~")
  60. call Put_Dig("~u") " not defined
  61. call Put_Dig("z~") " not defined
  62. call assert_equal(['õ', 'u', '~'], getline(line('.')-2,line('.')))
  63. " Tilde
  64. call Put_Dig("o?")
  65. call Put_Dig("?u")
  66. call Put_Dig("z?") " not defined
  67. call assert_equal(['õ', 'ũ', '?'], getline(line('.')-2,line('.')))
  68. " Macron
  69. call Put_Dig("o-")
  70. call Put_Dig("-u")
  71. call Put_Dig("z-") " not defined
  72. call assert_equal(['ō', 'ū', '-'], getline(line('.')-2,line('.')))
  73. " Breve
  74. call Put_Dig("o(")
  75. call Put_Dig("(u")
  76. call Put_Dig("z(") " not defined
  77. call assert_equal(['ŏ', 'ŭ', '('], getline(line('.')-2,line('.')))
  78. " Dot above
  79. call Put_Dig("b.")
  80. call Put_Dig(".e")
  81. call Put_Dig("a.") " not defined
  82. call assert_equal(['ḃ', 'ė', '.'], getline(line('.')-2,line('.')))
  83. " Diaeresis
  84. call Put_Dig("a:")
  85. call Put_Dig(":u")
  86. call Put_Dig("b:") " not defined
  87. call assert_equal(['ä', 'ü', ':'], getline(line('.')-2,line('.')))
  88. " Cedilla
  89. call Put_Dig("',")
  90. call Put_Dig(",C")
  91. call Put_Dig("b,") " not defined
  92. call assert_equal(['¸', 'Ç', ','], getline(line('.')-2,line('.')))
  93. " Underline
  94. call Put_Dig("B_")
  95. call Put_Dig("_t")
  96. call Put_Dig("a_") " not defined
  97. call assert_equal(['Ḇ', 'ṯ', '_'], getline(line('.')-2,line('.')))
  98. " Stroke
  99. call Put_Dig("j/")
  100. call Put_Dig("/l")
  101. call Put_Dig("b/") " not defined
  102. call assert_equal(['/', 'ł', '/'], getline(line('.')-2,line('.')))
  103. " Double acute
  104. call Put_Dig('O"')
  105. call Put_Dig('"y')
  106. call Put_Dig('b"') " not defined
  107. call assert_equal(['Ő', 'ÿ', '"'], getline(line('.')-2,line('.')))
  108. " Ogonek
  109. call Put_Dig('u;')
  110. call Put_Dig(';E')
  111. call Put_Dig('b;') " not defined
  112. call assert_equal(['ų', 'Ę', ';'], getline(line('.')-2,line('.')))
  113. " Caron
  114. call Put_Dig('u<')
  115. call Put_Dig('<E')
  116. call Put_Dig('b<') " not defined
  117. call assert_equal(['ǔ', 'Ě', '<'], getline(line('.')-2,line('.')))
  118. " Ring above
  119. call Put_Dig('u0')
  120. call Put_Dig('0E') " not defined
  121. call Put_Dig('b0') " not defined
  122. call assert_equal(['ů', 'E', '0'], getline(line('.')-2,line('.')))
  123. " Hook
  124. call Put_Dig('u2')
  125. call Put_Dig('2E')
  126. call Put_Dig('b2') " not defined
  127. call assert_equal(['ủ', 'Ẻ', '2'], getline(line('.')-2,line('.')))
  128. " Horn
  129. call Put_Dig('u9')
  130. call Put_Dig('9E') " not defined
  131. call Put_Dig('b9') " not defined
  132. call assert_equal(['ư', 'E', '9'], getline(line('.')-2,line('.')))
  133. " Cyrillic
  134. call Put_Dig('u=')
  135. call Put_Dig('=b')
  136. call Put_Dig('=_')
  137. call assert_equal(['у', 'б', '〓'], getline(line('.')-2,line('.')))
  138. " Greek
  139. call Put_Dig('u*')
  140. call Put_Dig('*b')
  141. call Put_Dig('*_')
  142. call assert_equal(['υ', 'β', '々'], getline(line('.')-2,line('.')))
  143. " Greek/Cyrillic special
  144. call Put_Dig('u%')
  145. call Put_Dig('%b') " not defined
  146. call Put_Dig('%_') " not defined
  147. call assert_equal(['ύ', 'b', '_'], getline(line('.')-2,line('.')))
  148. " Arabic
  149. call Put_Dig('u+')
  150. call Put_Dig('+b')
  151. call Put_Dig('+_') " japanese industrial symbol
  152. call assert_equal(['+', 'ب', '〄'], getline(line('.')-2,line('.')))
  153. " Hebrew
  154. call Put_Dig('Q+')
  155. call Put_Dig('+B')
  156. call Put_Dig('+X')
  157. call assert_equal(['ק', 'ב', 'ח'], getline(line('.')-2,line('.')))
  158. " Latin
  159. call Put_Dig('a3')
  160. call Put_Dig('A3')
  161. call Put_Dig('3X')
  162. call assert_equal(['ǣ', 'Ǣ', 'X'], getline(line('.')-2,line('.')))
  163. " Bopomofo
  164. call Put_Dig('a4')
  165. call Put_Dig('A4')
  166. call Put_Dig('4X')
  167. call assert_equal(['ㄚ', '4', 'X'], getline(line('.')-2,line('.')))
  168. " Hiragana
  169. call Put_Dig('a5')
  170. call Put_Dig('A5')
  171. call Put_Dig('5X')
  172. call assert_equal(['あ', 'ぁ', 'X'], getline(line('.')-2,line('.')))
  173. " Katakana
  174. call Put_Dig('a6')
  175. call Put_Dig('A6')
  176. call Put_Dig('6X')
  177. call assert_equal(['ァ', 'ア', 'X'], getline(line('.')-2,line('.')))
  178. " Superscripts
  179. call Put_Dig('1S')
  180. call Put_Dig('2S')
  181. call Put_Dig('3S')
  182. call assert_equal(['¹', '²', '³'], getline(line('.')-2,line('.')))
  183. " Subscripts
  184. call Put_Dig('1s')
  185. call Put_Dig('2s')
  186. call Put_Dig('3s')
  187. call assert_equal(['₁', '₂', '₃'], getline(line('.')-2,line('.')))
  188. " Eszet (only lowercase)
  189. call Put_Dig("ss")
  190. call Put_Dig("SS") " start of string
  191. call assert_equal(["ß", "˜"], getline(line('.')-1,line('.')))
  192. " High bit set
  193. call Put_Dig("a ")
  194. call Put_Dig(" A")
  195. call assert_equal(['á', 'Á'], getline(line('.')-1,line('.')))
  196. " Escape is not part of a digraph
  197. call Put_Dig("a\<esc>")
  198. call Put_Dig("\<esc>A")
  199. call assert_equal(['', 'A'], getline(line('.')-1,line('.')))
  200. " define some custom digraphs
  201. " old: 00 ∞
  202. " old: el l
  203. digraph 00 9216
  204. digraph el 0252
  205. call Put_Dig("00")
  206. call Put_Dig("el")
  207. " Reset digraphs
  208. digraph 00 8734
  209. digraph el 108
  210. call Put_Dig("00")
  211. call Put_Dig("el")
  212. call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.')))
  213. call assert_fails('exe "digraph a\<Esc> 100"', 'E104:')
  214. call assert_fails('exe "digraph \<Esc>a 100"', 'E104:')
  215. call assert_fails('digraph xy z', 'E39:')
  216. call assert_fails('digraph x', 'E1214:')
  217. bw!
  218. endfunc
  219. func Test_digraphs_option()
  220. " reset whichwrap option, so that testing <esc><bs>A works,
  221. " without moving up a line
  222. set digraph ww=
  223. new
  224. call Put_Dig_BS("0","0")
  225. call assert_equal("∞", getline('.'))
  226. " not a digraph
  227. call Put_Dig_BS("e","l")
  228. call assert_equal("l", getline('.'))
  229. call Put_Dig_BS("h","t")
  230. call assert_equal("þ", getline('.'))
  231. " digraph "ab" is the same as "ba"
  232. call Put_Dig_BS("a","b")
  233. call Put_Dig_BS("b","a")
  234. call assert_equal(["ば","ば"], getline(line('.')-1,line('.')))
  235. " Euro sign
  236. call Put_Dig_BS("e","=")
  237. call Put_Dig_BS("=","e")
  238. call Put_Dig_BS("E","u")
  239. call Put_Dig_BS("u","E")
  240. call assert_equal(['е']+repeat(["€"],3), getline(line('.')-3,line('.')))
  241. " Rouble sign
  242. call Put_Dig_BS("R","=")
  243. call Put_Dig_BS("=","R")
  244. call Put_Dig_BS("=","P")
  245. call Put_Dig_BS("P","=")
  246. call assert_equal(['Р']+repeat(["₽"],2)+['П'], getline(line('.')-3,line('.')))
  247. " Not a digraph: this is different from <c-k>!
  248. call Put_Dig_BS("a","\<bs>")
  249. call Put_Dig_BS("\<bs>","a")
  250. call assert_equal(['','a'], getline(line('.')-1,line('.')))
  251. " Grave
  252. call Put_Dig_BS("a","!")
  253. call Put_Dig_BS("!","e")
  254. call Put_Dig_BS("b","!") " not defined
  255. call assert_equal(["à", "è", "!"], getline(line('.')-2,line('.')))
  256. " Acute accent
  257. call Put_Dig_BS("a","'")
  258. call Put_Dig_BS("'","e")
  259. call Put_Dig_BS("b","'") " not defined
  260. call assert_equal(["á", "é", "'"], getline(line('.')-2,line('.')))
  261. " Cicumflex
  262. call Put_Dig_BS("a",">")
  263. call Put_Dig_BS(">","e")
  264. call Put_Dig_BS("b",">") " not defined
  265. call assert_equal(['â', 'ê', '>'], getline(line('.')-2,line('.')))
  266. " Tilde
  267. call Put_Dig_BS("o","~")
  268. call Put_Dig_BS("~","u") " not defined
  269. call Put_Dig_BS("z","~") " not defined
  270. call assert_equal(['õ', 'u', '~'], getline(line('.')-2,line('.')))
  271. " Tilde
  272. call Put_Dig_BS("o","?")
  273. call Put_Dig_BS("?","u")
  274. call Put_Dig_BS("z","?") " not defined
  275. call assert_equal(['õ', 'ũ', '?'], getline(line('.')-2,line('.')))
  276. " Macron
  277. call Put_Dig_BS("o","-")
  278. call Put_Dig_BS("-","u")
  279. call Put_Dig_BS("z","-") " not defined
  280. call assert_equal(['ō', 'ū', '-'], getline(line('.')-2,line('.')))
  281. " Breve
  282. call Put_Dig_BS("o","(")
  283. call Put_Dig_BS("(","u")
  284. call Put_Dig_BS("z","(") " not defined
  285. call assert_equal(['ŏ', 'ŭ', '('], getline(line('.')-2,line('.')))
  286. " Dot above
  287. call Put_Dig_BS("b",".")
  288. call Put_Dig_BS(".","e")
  289. call Put_Dig_BS("a",".") " not defined
  290. call assert_equal(['ḃ', 'ė', '.'], getline(line('.')-2,line('.')))
  291. " Diaeresis
  292. call Put_Dig_BS("a",":")
  293. call Put_Dig_BS(":","u")
  294. call Put_Dig_BS("b",":") " not defined
  295. call assert_equal(['ä', 'ü', ':'], getline(line('.')-2,line('.')))
  296. " Cedilla
  297. call Put_Dig_BS("'",",")
  298. call Put_Dig_BS(",","C")
  299. call Put_Dig_BS("b",",") " not defined
  300. call assert_equal(['¸', 'Ç', ','], getline(line('.')-2,line('.')))
  301. " Underline
  302. call Put_Dig_BS("B","_")
  303. call Put_Dig_BS("_","t")
  304. call Put_Dig_BS("a","_") " not defined
  305. call assert_equal(['Ḇ', 'ṯ', '_'], getline(line('.')-2,line('.')))
  306. " Stroke
  307. call Put_Dig_BS("j","/")
  308. call Put_Dig_BS("/","l")
  309. call Put_Dig_BS("b","/") " not defined
  310. call assert_equal(['/', 'ł', '/'], getline(line('.')-2,line('.')))
  311. " Double acute
  312. call Put_Dig_BS('O','"')
  313. call Put_Dig_BS('"','y')
  314. call Put_Dig_BS('b','"') " not defined
  315. call assert_equal(['Ő', 'ÿ', '"'], getline(line('.')-2,line('.')))
  316. " Ogonek
  317. call Put_Dig_BS('u',';')
  318. call Put_Dig_BS(';','E')
  319. call Put_Dig_BS('b',';') " not defined
  320. call assert_equal(['ų', 'Ę', ';'], getline(line('.')-2,line('.')))
  321. " Caron
  322. call Put_Dig_BS('u','<')
  323. call Put_Dig_BS('<','E')
  324. call Put_Dig_BS('b','<') " not defined
  325. call assert_equal(['ǔ', 'Ě', '<'], getline(line('.')-2,line('.')))
  326. " Ring above
  327. call Put_Dig_BS('u','0')
  328. call Put_Dig_BS('0','E') " not defined
  329. call Put_Dig_BS('b','0') " not defined
  330. call assert_equal(['ů', 'E', '0'], getline(line('.')-2,line('.')))
  331. " Hook
  332. call Put_Dig_BS('u','2')
  333. call Put_Dig_BS('2','E')
  334. call Put_Dig_BS('b','2') " not defined
  335. call assert_equal(['ủ', 'Ẻ', '2'], getline(line('.')-2,line('.')))
  336. " Horn
  337. call Put_Dig_BS('u','9')
  338. call Put_Dig_BS('9','E') " not defined
  339. call Put_Dig_BS('b','9') " not defined
  340. call assert_equal(['ư', 'E', '9'], getline(line('.')-2,line('.')))
  341. " Cyrillic
  342. call Put_Dig_BS('u','=')
  343. call Put_Dig_BS('=','b')
  344. call Put_Dig_BS('=','_')
  345. call assert_equal(['у', 'б', '〓'], getline(line('.')-2,line('.')))
  346. " Greek
  347. call Put_Dig_BS('u','*')
  348. call Put_Dig_BS('*','b')
  349. call Put_Dig_BS('*','_')
  350. call assert_equal(['υ', 'β', '々'], getline(line('.')-2,line('.')))
  351. " Greek/Cyrillic special
  352. call Put_Dig_BS('u','%')
  353. call Put_Dig_BS('%','b') " not defined
  354. call Put_Dig_BS('%','_') " not defined
  355. call assert_equal(['ύ', 'b', '_'], getline(line('.')-2,line('.')))
  356. " Arabic
  357. call Put_Dig_BS('u','+')
  358. call Put_Dig_BS('+','b')
  359. call Put_Dig_BS('+','_') " japanese industrial symbol
  360. call assert_equal(['+', 'ب', '〄'], getline(line('.')-2,line('.')))
  361. " Hebrew
  362. call Put_Dig_BS('Q','+')
  363. call Put_Dig_BS('+','B')
  364. call Put_Dig_BS('+','X')
  365. call assert_equal(['ק', 'ב', 'ח'], getline(line('.')-2,line('.')))
  366. " Latin
  367. call Put_Dig_BS('a','3')
  368. call Put_Dig_BS('A','3')
  369. call Put_Dig_BS('3','X')
  370. call assert_equal(['ǣ', 'Ǣ', 'X'], getline(line('.')-2,line('.')))
  371. " Bopomofo
  372. call Put_Dig_BS('a','4')
  373. call Put_Dig_BS('A','4')
  374. call Put_Dig_BS('4','X')
  375. call assert_equal(['ㄚ', '4', 'X'], getline(line('.')-2,line('.')))
  376. " Hiragana
  377. call Put_Dig_BS('a','5')
  378. call Put_Dig_BS('A','5')
  379. call Put_Dig_BS('5','X')
  380. call assert_equal(['あ', 'ぁ', 'X'], getline(line('.')-2,line('.')))
  381. " Katakana
  382. call Put_Dig_BS('a','6')
  383. call Put_Dig_BS('A','6')
  384. call Put_Dig_BS('6','X')
  385. call assert_equal(['ァ', 'ア', 'X'], getline(line('.')-2,line('.')))
  386. " Superscripts
  387. call Put_Dig_BS('1','S')
  388. call Put_Dig_BS('2','S')
  389. call Put_Dig_BS('3','S')
  390. call assert_equal(['¹', '²', '³'], getline(line('.')-2,line('.')))
  391. " Subscripts
  392. call Put_Dig_BS('1','s')
  393. call Put_Dig_BS('2','s')
  394. call Put_Dig_BS('3','s')
  395. call assert_equal(['₁', '₂', '₃'], getline(line('.')-2,line('.')))
  396. " Eszet (only lowercase)
  397. call Put_Dig_BS("s","s")
  398. call Put_Dig_BS("S","S") " start of string
  399. call assert_equal(["ß", "˜"], getline(line('.')-1,line('.')))
  400. " High bit set (different from <c-k>)
  401. call Put_Dig_BS("a"," ")
  402. call Put_Dig_BS(" ","A")
  403. call assert_equal([' ', 'A'], getline(line('.')-1,line('.')))
  404. " Escape is not part of a digraph (different from <c-k>)
  405. call Put_Dig_BS("a","\<esc>")
  406. call Put_Dig_BS("\<esc>","A")
  407. call assert_equal(['', ''], getline(line('.')-1,line('.')))
  408. " define some custom digraphs
  409. " old: 00 ∞
  410. " old: el l
  411. digraph 00 9216
  412. digraph el 0252
  413. call Put_Dig_BS("0","0")
  414. call Put_Dig_BS("e","l")
  415. " Reset digraphs
  416. digraph 00 8734
  417. digraph el 108
  418. call Put_Dig_BS("0","0")
  419. call Put_Dig_BS("e","l")
  420. call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.')))
  421. set nodigraph ww&vim
  422. bw!
  423. endfunc
  424. func Test_digraphs_output()
  425. new
  426. let out = execute(':digraph')
  427. call assert_equal('Eu € 8364', matchstr(out, '\C\<Eu\D*8364\>'))
  428. call assert_equal('=e € 8364', matchstr(out, '\C=e\D*8364\>'))
  429. call assert_equal('=R ₽ 8381', matchstr(out, '\C=R\D*8381\>'))
  430. call assert_equal('=P ₽ 8381', matchstr(out, '\C=P\D*8381\>'))
  431. call assert_equal('o: ö 246', matchstr(out, '\C\<o:\D*246\>'))
  432. call assert_equal('v4 ㄪ 12586', matchstr(out, '\C\<v4\D*12586\>'))
  433. call assert_equal("'0 ˚ 730", matchstr(out, '\C''0\D*730\>'))
  434. call assert_equal('Z% Ж 1046', matchstr(out, '\C\<Z%\D*1046\>'))
  435. call assert_equal('u- ū 363', matchstr(out, '\C\<u-\D*363\>'))
  436. call assert_equal('SH ^A 1', matchstr(out, '\C\<SH\D*1\>'))
  437. call assert_notmatch('Latin supplement', out)
  438. let out_bang_without_custom = execute(':digraph!')
  439. digraph lt 60
  440. let out_bang_with_custom = execute(':digraph!')
  441. call assert_notmatch('lt', out_bang_without_custom)
  442. call assert_match("^\n"
  443. \ .. "NU ^@ 10 .*\n"
  444. \ .. "Latin supplement\n"
  445. \ .. "!I ¡ 161 .*\n"
  446. \ .. ".*\n"
  447. \ .. 'Custom\n.*\<lt < 60\>', out_bang_with_custom)
  448. bw!
  449. endfunc
  450. func Test_loadkeymap()
  451. CheckFeature keymap
  452. new
  453. set keymap=czech
  454. set iminsert=0
  455. call feedkeys("o|\<c-^>|01234567890|\<esc>", 'tx')
  456. call assert_equal("|'é+ěščřžýáíé'", getline('.'))
  457. " reset keymap and encoding option
  458. set keymap=
  459. bw!
  460. endfunc
  461. func Test_digraph_cmndline()
  462. " Create digraph on commandline
  463. call feedkeys(":\"\<c-k>Eu\<cr>", 'xt')
  464. call assert_equal('"€', @:)
  465. " Canceling a CTRL-K on the cmdline
  466. call feedkeys(":\"a\<c-k>\<esc>b\<cr>", 'xt')
  467. call assert_equal('"ab', @:)
  468. endfunc
  469. func Test_show_digraph()
  470. new
  471. call Put_Dig("e=")
  472. call assert_equal("\n<е> 1077, Hex 0435, Oct 2065, Digr e=", execute('ascii'))
  473. bwipe!
  474. endfunc
  475. func Test_show_digraph_cp1251()
  476. throw 'skipped: Nvim supports ''utf8'' encoding only'
  477. new
  478. set encoding=cp1251
  479. call Put_Dig("='")
  480. call assert_equal("\n<\xfa> <|z> <M-z> 250, Hex fa, Oct 372, Digr ='", execute('ascii'))
  481. set encoding=utf-8
  482. bwipe!
  483. endfunc
  484. " Test for error in a keymap file
  485. func Test_loadkeymap_error()
  486. CheckFeature keymap
  487. call assert_fails('loadkeymap', 'E105:')
  488. call writefile(['loadkeymap', 'a'], 'Xkeymap', 'D')
  489. call assert_fails('source Xkeymap', 'E791:')
  490. endfunc
  491. " Test for the characters displayed on the screen when entering a digraph
  492. func Test_entering_digraph()
  493. CheckRunVimInTerminal
  494. let buf = RunVimInTerminal('', {'rows': 6})
  495. call term_sendkeys(buf, "i\<C-K>")
  496. call term_wait(buf)
  497. call assert_equal('?', term_getline(buf, 1))
  498. call term_sendkeys(buf, "1")
  499. call term_wait(buf)
  500. call assert_equal('1', term_getline(buf, 1))
  501. call term_sendkeys(buf, "2")
  502. call term_wait(buf)
  503. call assert_equal('½', term_getline(buf, 1))
  504. call StopVimInTerminal(buf)
  505. endfunc
  506. func Test_digraph_set_function()
  507. new
  508. call digraph_set('aa', 'あ')
  509. call Put_Dig('aa')
  510. call assert_equal('あ', getline('$'))
  511. call digraph_set(' i', 'い')
  512. call Put_Dig(' i')
  513. call assert_equal('い', getline('$'))
  514. call digraph_set(' ', 'う')
  515. call Put_Dig(' ')
  516. call assert_equal('う', getline('$'))
  517. eval 'aa'->digraph_set('え')
  518. call Put_Dig('aa')
  519. call assert_equal('え', getline('$'))
  520. call assert_fails('call digraph_set("aaa", "あ")', 'E1214: Digraph must be just two characters: aaa')
  521. call assert_fails('call digraph_set("b", "あ")', 'E1214: Digraph must be just two characters: b')
  522. call assert_fails('call digraph_set("あ", "あ")', 'E1214: Digraph must be just two characters: あ')
  523. call assert_fails('call digraph_set("aa", "ああ")', 'E1215: Digraph must be one character: ああ')
  524. call assert_fails('call digraph_set("aa", "か" .. nr2char(0x3099))', 'E1215: Digraph must be one character: か' .. nr2char(0x3099))
  525. call assert_fails('call digraph_set(v:_null_string, "い")', 'E1214: Digraph must be just two characters')
  526. call assert_fails('call digraph_set("aa", 0z10)', 'E976: Using a Blob as a String')
  527. bwipe!
  528. endfunc
  529. func Test_digraph_get_function()
  530. " Built-in digraphs
  531. call assert_equal('∞', digraph_get('00'))
  532. " User-defined digraphs
  533. call digraph_set('aa', 'あ')
  534. call digraph_set(' i', 'い')
  535. call digraph_set(' ', 'う')
  536. call assert_equal('あ', digraph_get('aa'))
  537. call assert_equal('あ', 'aa'->digraph_get())
  538. call assert_equal('い', digraph_get(' i'))
  539. call assert_equal('う', digraph_get(' '))
  540. call assert_fails('call digraph_get("aaa")', 'E1214: Digraph must be just two characters: aaa')
  541. call assert_fails('call digraph_get("b")', 'E1214: Digraph must be just two characters: b')
  542. call assert_fails('call digraph_get(v:_null_string)', 'E1214: Digraph must be just two characters:')
  543. call assert_fails('call digraph_get(0z10)', 'E976: Using a Blob as a String')
  544. endfunc
  545. func Test_digraph_get_function_encode()
  546. throw 'Skipped: Nvim does not support setting encoding=japan'
  547. CheckFeature iconv
  548. let testcases = {
  549. \'00': '∞',
  550. \'aa': 'あ',
  551. \}
  552. for [key, ch] in items(testcases)
  553. call digraph_set(key, ch)
  554. set encoding=japan
  555. call assert_equal(iconv(ch, 'utf-8', 'japan'), digraph_get(key))
  556. set encoding=utf-8
  557. endfor
  558. endfunc
  559. func Test_digraph_setlist_function()
  560. call digraph_setlist([['aa', 'き'], ['bb', 'く']])
  561. call assert_equal('き', digraph_get('aa'))
  562. call assert_equal('く', digraph_get('bb'))
  563. call assert_fails('call digraph_setlist([[]])', 'E1216:')
  564. call assert_fails('call digraph_setlist([["aa", "b", "cc"]])', 'E1216:')
  565. call assert_fails('call digraph_setlist([["あ", "あ"]])', 'E1214: Digraph must be just two characters: あ')
  566. call assert_fails('call digraph_setlist([v:_null_list])', 'E1216:')
  567. call assert_fails('call digraph_setlist({})', 'E1216:')
  568. call assert_fails('call digraph_setlist([{}])', 'E1216:')
  569. call assert_true(digraph_setlist(v:_null_list))
  570. endfunc
  571. func Test_digraph_getlist_function()
  572. " Make sure user-defined digraphs are defined
  573. call digraph_setlist([['aa', 'き'], ['bb', 'く']])
  574. for pair in digraph_getlist(1)
  575. call assert_equal(pair[1], digraph_get(pair[0]))
  576. endfor
  577. " We don't know how many digraphs are registered before, so check the number
  578. " of digraphs returned.
  579. call assert_equal(digraph_getlist()->len(), digraph_getlist(0)->len())
  580. call assert_notequal(digraph_getlist()->len(), digraph_getlist(1)->len())
  581. call assert_fails('call digraph_getlist(0z12)', 'E974: Using a Blob as a Number')
  582. endfunc
  583. " vim: shiftwidth=2 sts=2 expandtab