095_regexp_multibyte_spec.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. -- Test for regexp patterns with multi-byte support, using utf-8.
  2. -- See test_regexp_latin.vim for the non-multi-byte tests.
  3. -- A pattern that gives the expected result produces OK, so that we know it was
  4. -- actually tried.
  5. local helpers = require('test.functional.helpers')(after_each)
  6. local insert, source = helpers.insert, helpers.source
  7. local clear, expect = helpers.clear, helpers.expect
  8. describe('regex with multi-byte', function()
  9. setup(clear)
  10. it('is working', function()
  11. insert([[
  12. Results of test95:]])
  13. source([=[
  14. set nomore
  15. let tl = []
  16. call add(tl, [2, '[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna'])
  17. call add(tl, [2, '[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes
  18. call add(tl, [2, '[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos'])
  19. call add(tl, [2, ' [^ ]\+', 'start มabcdม ', ' มabcdม'])
  20. call add(tl, [2, '[ม[:alpha:][=a=]]\+', '879 aiaãมâมaiuvna ', 'aiaãมâมaiuvna'])
  21. call add(tl, [2, '\p\+', 'ìa', 'ìa'])
  22. call add(tl, [2, '\p*', 'aあ', 'aあ'])
  23. call add(tl, [2, '\i\+', '&*¨xx ', 'xx'])
  24. call add(tl, [2, '\f\+', '&*Ÿfname ', 'fname'])
  25. call add(tl, [2, '.ม', 'xม่x yมy', 'yม'])
  26. call add(tl, [2, '.ม่', 'xม่x yมy', 'xม่'])
  27. call add(tl, [2, "\u05b9", " x\u05b9 ", "x\u05b9"])
  28. call add(tl, [2, ".\u05b9", " x\u05b9 ", "x\u05b9"])
  29. call add(tl, [2, "\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
  30. call add(tl, [2, ".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
  31. call add(tl, [2, "\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
  32. call add(tl, [2, ".\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
  33. call add(tl, [2, "\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
  34. call add(tl, [2, ".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
  35. call add(tl, [2, "\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
  36. call add(tl, [2, ".\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
  37. call add(tl, [1, "\u05b9\u05bb", " y\u05b9 x\u05b9\u05bb ", "x\u05b9\u05bb"])
  38. call add(tl, [2, ".\u05b9\u05bb", " y\u05bb x\u05b9\u05bb ", "x\u05b9\u05bb"])
  39. call add(tl, [2, "a", "ca\u0300t"])
  40. call add(tl, [2, "ca", "ca\u0300t"])
  41. call add(tl, [2, "a\u0300", "ca\u0300t", "a\u0300"])
  42. call add(tl, [2, 'a\%C', "ca\u0300t", "a\u0300"])
  43. call add(tl, [2, 'ca\%C', "ca\u0300t", "ca\u0300"])
  44. call add(tl, [2, 'ca\%Ct', "ca\u0300t", "ca\u0300t"])
  45. call add(tl, [2, 'ú\Z', 'x'])
  46. call add(tl, [2, 'יהוה\Z', 'יהוה', 'יהוה'])
  47. call add(tl, [2, 'יְהוָה\Z', 'יהוה', 'יהוה'])
  48. call add(tl, [2, 'יהוה\Z', 'יְהוָה', 'יְהוָה'])
  49. call add(tl, [2, 'יְהוָה\Z', 'יְהוָה', 'יְהוָה'])
  50. call add(tl, [2, 'יְ\Z', 'וְיַ', 'יַ'])
  51. call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
  52. call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"])
  53. call add(tl, [2, "ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
  54. call add(tl, [2, "ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"])
  55. call add(tl, [2, "\u05b9\\Z", "xyz"])
  56. call add(tl, [2, "\\Z\u05b9", "xyz"])
  57. call add(tl, [2, "\u05b9\\Z", "xy\u05b9z", "y\u05b9"])
  58. call add(tl, [2, "\\Z\u05b9", "xy\u05b9z", "y\u05b9"])
  59. call add(tl, [1, "\u05b9\\+\\Z", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"])
  60. call add(tl, [1, "\\Z\u05b9\\+", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"])
  61. call add(tl, [2, '[^[=a=]]\+', 'ddaãâbcd', 'dd'])
  62. for t in tl
  63. let re = t[0]
  64. let pat = t[1]
  65. let text = t[2]
  66. let matchidx = 3
  67. for engine in [0, 1, 2]
  68. if engine == 2 && re == 0 || engine == 1 && re == 1
  69. continue
  70. endif
  71. let &regexpengine = engine
  72. try
  73. let l = matchlist(text, pat)
  74. catch
  75. $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"'
  76. endtry
  77. if len(l) == 0 && len(t) > matchidx
  78. $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"'
  79. elseif len(l) > 0 && len(t) == matchidx
  80. $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match'
  81. elseif len(t) > matchidx && l[0] != t[matchidx]
  82. $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"'
  83. else
  84. $put ='OK ' . engine . ' - ' . pat
  85. endif
  86. if len(l) > 0
  87. for i in range(1, 9)
  88. if len(t) <= matchidx + i
  89. let e = ''
  90. else
  91. let e = t[matchidx + i]
  92. endif
  93. if l[i] != e
  94. $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"'
  95. endif
  96. endfor
  97. unlet i
  98. endif
  99. endfor
  100. endfor
  101. unlet t tl e l
  102. set regexpengine=1 ambiwidth=single
  103. $put ='eng 1 ambi single: ' . match(\"\u00EC\", '\p')
  104. set regexpengine=1 ambiwidth=double
  105. $put ='eng 1 ambi double: ' . match(\"\u00EC\", '\p')
  106. set regexpengine=2 ambiwidth=single
  107. $put ='eng 2 ambi single: ' . match(\"\u00EC\", '\p')
  108. set regexpengine=2 ambiwidth=double
  109. $put ='eng 2 ambi double: ' . match(\"\u00EC\", '\p')
  110. ]=])
  111. -- Assert buffer contents.
  112. expect([=[
  113. Results of test95:
  114. OK 0 - [[:alpha:][=a=]]\+
  115. OK 1 - [[:alpha:][=a=]]\+
  116. OK 2 - [[:alpha:][=a=]]\+
  117. OK 0 - [[=a=]]\+
  118. OK 1 - [[=a=]]\+
  119. OK 2 - [[=a=]]\+
  120. OK 0 - [^ม ]\+
  121. OK 1 - [^ม ]\+
  122. OK 2 - [^ม ]\+
  123. OK 0 - [^ ]\+
  124. OK 1 - [^ ]\+
  125. OK 2 - [^ ]\+
  126. OK 0 - [ม[:alpha:][=a=]]\+
  127. OK 1 - [ม[:alpha:][=a=]]\+
  128. OK 2 - [ม[:alpha:][=a=]]\+
  129. OK 0 - \p\+
  130. OK 1 - \p\+
  131. OK 2 - \p\+
  132. OK 0 - \p*
  133. OK 1 - \p*
  134. OK 2 - \p*
  135. OK 0 - \i\+
  136. OK 1 - \i\+
  137. OK 2 - \i\+
  138. OK 0 - \f\+
  139. OK 1 - \f\+
  140. OK 2 - \f\+
  141. OK 0 - .ม
  142. OK 1 - .ม
  143. OK 2 - .ม
  144. OK 0 - .ม่
  145. OK 1 - .ม่
  146. OK 2 - .ม่
  147. OK 0 - ֹ
  148. OK 1 - ֹ
  149. OK 2 - ֹ
  150. OK 0 - .ֹ
  151. OK 1 - .ֹ
  152. OK 2 - .ֹ
  153. OK 0 - ֹֻ
  154. OK 1 - ֹֻ
  155. OK 2 - ֹֻ
  156. OK 0 - .ֹֻ
  157. OK 1 - .ֹֻ
  158. OK 2 - .ֹֻ
  159. OK 0 - ֹֻ
  160. OK 1 - ֹֻ
  161. OK 2 - ֹֻ
  162. OK 0 - .ֹֻ
  163. OK 1 - .ֹֻ
  164. OK 2 - .ֹֻ
  165. OK 0 - ֹ
  166. OK 1 - ֹ
  167. OK 2 - ֹ
  168. OK 0 - .ֹ
  169. OK 1 - .ֹ
  170. OK 2 - .ֹ
  171. OK 0 - ֹ
  172. OK 1 - ֹ
  173. OK 2 - ֹ
  174. OK 0 - .ֹ
  175. OK 1 - .ֹ
  176. OK 2 - .ֹ
  177. OK 0 - ֹֻ
  178. OK 2 - ֹֻ
  179. OK 0 - .ֹֻ
  180. OK 1 - .ֹֻ
  181. OK 2 - .ֹֻ
  182. OK 0 - a
  183. OK 1 - a
  184. OK 2 - a
  185. OK 0 - ca
  186. OK 1 - ca
  187. OK 2 - ca
  188. OK 0 - à
  189. OK 1 - à
  190. OK 2 - à
  191. OK 0 - a\%C
  192. OK 1 - a\%C
  193. OK 2 - a\%C
  194. OK 0 - ca\%C
  195. OK 1 - ca\%C
  196. OK 2 - ca\%C
  197. OK 0 - ca\%Ct
  198. OK 1 - ca\%Ct
  199. OK 2 - ca\%Ct
  200. OK 0 - ú\Z
  201. OK 1 - ú\Z
  202. OK 2 - ú\Z
  203. OK 0 - יהוה\Z
  204. OK 1 - יהוה\Z
  205. OK 2 - יהוה\Z
  206. OK 0 - יְהוָה\Z
  207. OK 1 - יְהוָה\Z
  208. OK 2 - יְהוָה\Z
  209. OK 0 - יהוה\Z
  210. OK 1 - יהוה\Z
  211. OK 2 - יהוה\Z
  212. OK 0 - יְהוָה\Z
  213. OK 1 - יְהוָה\Z
  214. OK 2 - יְהוָה\Z
  215. OK 0 - יְ\Z
  216. OK 1 - יְ\Z
  217. OK 2 - יְ\Z
  218. OK 0 - ק‍ֹx\Z
  219. OK 1 - ק‍ֹx\Z
  220. OK 2 - ק‍ֹx\Z
  221. OK 0 - ק‍ֹx\Z
  222. OK 1 - ק‍ֹx\Z
  223. OK 2 - ק‍ֹx\Z
  224. OK 0 - ק‍x\Z
  225. OK 1 - ק‍x\Z
  226. OK 2 - ק‍x\Z
  227. OK 0 - ק‍x\Z
  228. OK 1 - ק‍x\Z
  229. OK 2 - ק‍x\Z
  230. OK 0 - ֹ\Z
  231. OK 1 - ֹ\Z
  232. OK 2 - ֹ\Z
  233. OK 0 - \Zֹ
  234. OK 1 - \Zֹ
  235. OK 2 - \Zֹ
  236. OK 0 - ֹ\Z
  237. OK 1 - ֹ\Z
  238. OK 2 - ֹ\Z
  239. OK 0 - \Zֹ
  240. OK 1 - \Zֹ
  241. OK 2 - \Zֹ
  242. OK 0 - ֹ\+\Z
  243. OK 2 - ֹ\+\Z
  244. OK 0 - \Zֹ\+
  245. OK 2 - \Zֹ\+
  246. OK 0 - [^[=a=]]\+
  247. OK 1 - [^[=a=]]\+
  248. OK 2 - [^[=a=]]\+
  249. eng 1 ambi single: 0
  250. eng 1 ambi double: 0
  251. eng 2 ambi single: 0
  252. eng 2 ambi double: 0]=])
  253. end)
  254. end)