neovim/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua
Björn Linse d9acfbd471 options: mark nonfunctional &termencoding option as hidden. #2631
Remove related dead code and references in the docs.

Helped-By: Michael Reed <m.reed@mykolab.com>
Helped-By: Shougo Matsushita <Shougo.Matsu@gmail.com>
2015-05-17 18:39:25 +02:00

148 lines
5.8 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Tests for regexp with multi-byte encoding and various magic settings.
-- Test matchstr() with a count and multi-byte chars.
--
-- This test contains both "test44" and "test99" from the old test suite.
local helpers = require('test.functional.helpers')
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
-- Runs the test protocol with the given 'regexpengine' setting. In the old test
-- suite the test protocol was duplicated in test44 and test99, the only
-- difference being the 'regexpengine' setting. We've extracted it here.
local function run_test_with_regexpengine(regexpengine)
insert([[
1 a aa abb abbccc
2 d dd dee deefff
3 g gg ghh ghhiii
4 j jj jkk jkklll
5 m mm mnn mnnooo
6 x ^aa$ x
7 (a)(b) abbaa
8 axx [ab]xx
9 หม่x อมx
a อมx หม่x
b ã<>¡ã«ãƒ¨ã<C2A8>¯
c x ¬â¬x
d 天使x
e ü<C3BC>…™¸y
f ü<C3BC>Š¯<C5A0>z
g aå•·bb
h AÀÃ<E282AC>ÃÃÄÅĀÄÄ„Ç<E2809E>ǞǠẢ Bá¸á¸† CÇĆĈĊČ DÄŽÄ<C5BD>ḊḎá¸<C3A1>ˆÃ‰ÃŠÃÄÄ”ÄĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÃŒÃ<C592>ÃŽÃ<C5BD>ĨĪĬĮİÇ<C2B0>Ỉ´ KĶǨḰḴ LĹĻĽĿÅ<C2BF>Ḻ MḾṀ NÃŃŅŇṄṈÓÔÕÃØŌŎÅ<C5BD>Æ ÇǪǬỎ PṔṠQ RÅ”ÅŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÃÜŨŪŬŮŰŲƯǓỦ Vá¹¼ WŴẀáºáº„Ẇ XẊẌ YÃ<59>ŶŸẎỲỶỸ ZŹŻŽƵáº<C3A1>Ẕ
i aàáâãäåÄ<C2A5>ăąǎǟǡả bḃḇ cçćĉÄÄ<E280B9><64>Äá¸á¸<C3A1>ḠeèéêëēĕėęÄẻẽ fḟ gÄ<67>ğġģǥǧǵḡ hĥħḣḧḩẠiìíîïĩīĭįÇ<C2AF>ỉ jĵǰ kķǩḱḵ lĺļľŀÅḻ mḿá¹<C3A1> nñńņňʼnṅṉ oòóôõöøÅ<C2B8>Å<EFBFBD>ÅÆ¡ÇÇ«Ç­á»<C3A1> pṕṗ q rŕŗřṙṟ sÅÅ<E280BA>şšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vá¹½ wŵáº<C3A1>ẃẅẇẘ xáºáº<C3A1> yýÿŷáº<C3A1>ẙỳỷỹ zźżžƶáºáº•
j 0123â<33>¤x
k combinations]])
execute('set encoding=utf-8')
execute('set re=' .. regexpengine)
-- Lines 1-8. Exercise regexp search with various magic settings. On each
-- line the character on which the cursor is expected to land is deleted.
feed('/^1<cr>')
feed([[/a*b\{2}c\+/e<cr>x]])
feed([[/\Md\*e\{2}f\+/e<cr>x]])
execute('set nomagic')
feed([[/g\*h\{2}i\+/e<cr>x]])
feed([[/\mj*k\{2}l\+/e<cr>x]])
feed([[/\vm*n{2}o+/e<cr>x]])
feed([[/\V^aa$<cr>x]])
execute('set magic')
feed([[/\v(a)(b)\2\1\1/e<cr>x]])
feed([[/\V[ab]\(\[xy]\)\1<cr>x]])
-- Line 9. Search for multi-byte character without combining character.
feed('/ม<cr>x')
-- Line a. Search for multi-byte character with combining character.
feed('/ม่<cr>x')
-- Line b. Find word by change of word class.
-- (The "<" character in this test step seemed to confuse our "feed" test
-- helper, which is why we've resorted to "execute" here.)
execute([[/ã<>¡\<カヨ\>ã<>¯]])
feed('x')
-- Lines c-i. Test \%u, [\u], and friends.
feed([[/\%u20ac<cr>x]])
feed([[/[\u4f7f\u5929]\+<cr>x]])
feed([[/\%U12345678<cr>x]])
feed([[/[\U1234abcd\u1234\uabcd]<cr>x]])
feed([[/\%d21879b<cr>x]])
feed('/ [[=A=]]* [[=B=]]* [[=C=]]* [[=D=]]* [[=E=]]* [[=F=]]* ' ..
'[[=G=]]* [[=H=]]* [[=I=]]* [[=J=]]* [[=K=]]* [[=L=]]* [[=M=]]* ' ..
'[[=N=]]* [[=O=]]* [[=P=]]* [[=Q=]]* [[=R=]]* [[=S=]]* [[=T=]]* ' ..
'[[=U=]]* [[=V=]]* [[=W=]]* [[=X=]]* [[=Y=]]* [[=Z=]]*/e<cr>x')
feed('/ [[=a=]]* [[=b=]]* [[=c=]]* [[=d=]]* [[=e=]]* [[=f=]]* ' ..
'[[=g=]]* [[=h=]]* [[=i=]]* [[=j=]]* [[=k=]]* [[=l=]]* [[=m=]]* ' ..
'[[=n=]]* [[=o=]]* [[=p=]]* [[=q=]]* [[=r=]]* [[=s=]]* [[=t=]]* ' ..
'[[=u=]]* [[=v=]]* [[=w=]]* [[=x=]]* [[=y=]]* [[=z=]]*/e<cr>x')
-- Line j. Test backwards search from a multi-byte character.
feed('/x<cr>x')
feed('?.<cr>x')
-- Line k. Test substitution with combining characters by executing register
-- contents.
execute([[let @w=':%s#comb[i]nations#Å“Ì„á¹£Ì<C2A3>m̥̄ᾱ̆Ì<E280A0>#g']])
execute('@w')
-- Additional tests. Test matchstr() with multi-byte characters.
feed('G')
execute([[put =matchstr(\"×<>××ד\", \".\", 0, 2)]]) -- ×
execute([[put =matchstr(\"×<>××ד\", \"..\", 0, 2)]]) -- ××
execute([[put =matchstr(\"×<>××ד\", \".\", 0, 0)]]) -- ×<>
execute([[put =matchstr(\"×<>××ד\", \".\", 4, -1)]]) -- ×
-- Test that a search with "/e" offset wraps around at the end of the buffer.
execute('new')
execute([[$put =['dog(a', 'cat('] ]])
feed('/(/e+<cr>')
feed('"ayn')
execute('bd!')
execute([[$put ='']])
feed('G"ap')
-- Assert buffer contents.
expect([[
1 a aa abb abbcc
2 d dd dee deeff
3 g gg ghh ghhii
4 j jj jkk jkkll
5 m mm mnn mnnoo
6 x aa$ x
7 (a)(b) abba
8 axx ab]xx
9 หม่x อx
a อมx หx
b ã«ãƒ¨ã<C2A8>¯
c x ¬x
d 使x
e y
f z
g abb
h AÀÃ<E282AC>ÃÃÄÅĀÄÄ„Ç<E2809E>ǞǠẢ Bá¸á¸† CÇĆĈĊČ DÄŽÄ<C5BD>ḊḎá¸<C3A1>ˆÃ‰ÃŠÃÄÄ”ÄĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÃŒÃ<C592>ÃŽÃ<C5BD>ĨĪĬĮİÇ<C2B0>Ỉ´ KĶǨḰḴ LĹĻĽĿÅ<C2BF>Ḻ MḾṀ NÃŃŅŇṄṈÓÔÕÃØŌŎÅ<C5BD>Æ ÇǪǬỎ PṔṠQ RÅ”ÅŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÃÜŨŪŬŮŰŲƯǓỦ Vá¹¼ WŴẀáºáº„Ẇ XẊẌ YÃ<59>ŶŸẎỲỶỸ ZŹŻŽƵáº<C3A1>
i aàáâãäåÄ<C2A5>ăąǎǟǡả bḃḇ cçćĉÄÄ<E280B9><64>Äá¸á¸<C3A1>ḠeèéêëēĕėęÄẻẽ fḟ gÄ<67>ğġģǥǧǵḡ hĥħḣḧḩẠiìíîïĩīĭįÇ<C2AF>ỉ jĵǰ kķǩḱḵ lĺļľŀÅḻ mḿá¹<C3A1> nñńņňʼnṅṉ oòóôõöøÅ<C2B8>Å<EFBFBD>ÅÆ¡ÇÇ«Ç­á»<C3A1> pṕṗ q rŕŗřṙṟ sÅÅ<E280BA>şšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vá¹½ wŵáº<C3A1>ẃẅẇẘ xáºáº<C3A1> yýÿŷáº<C3A1>ẙỳỷỹ zźżžƶáº
j 012â<32>¤
k Å“Ì„á¹£Ì<C2A3>m̥̄ᾱ̆Ì<E280A0>
×
××
×<>
×
a
cat(]])
end
describe('multi-byte regexp search with magic settings', function()
before_each(clear)
it('is working with regexpengine=1', function()
-- The old test44.
run_test_with_regexpengine(1)
end)
it('is working with regexpengine=2', function()
-- The old test99.
run_test_with_regexpengine(2)
end)
end)