blob: cef24367757dbec578c39d88693fd79552d979b3 [file] [log] [blame]
Bram Moolenaar22e42152016-04-03 14:02:02 +02001" Tests for regexp in utf8 encoding
2if !has('multi_byte')
3 finish
4endif
5set encoding=utf-8
6scriptencoding utf-8
7
8func s:equivalence_test()
9 let str = "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ŹŻŽƵẐẔ aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ f gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ v wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑẕ"
10 let groups = split(str)
11 for group1 in groups
12 for c in split(group1, '\zs')
13 " next statement confirms that equivalence class matches every
14 " character in group
15 call assert_match('^[[=' . c . '=]]*$', group1)
16 for group2 in groups
17 if group2 != group1
18 " next statement converts that equivalence class doesn't match
19 " character in any other group
20 call assert_equal(-1, match(group2, '[[=' . c . '=]]'))
21 endif
22 endfor
23 endfor
24 endfor
25endfunc
26
27func Test_equivalence_re1()
28 set re=1
29 call s:equivalence_test()
30endfunc
31
32func Test_equivalence_re2()
33 set re=2
34 call s:equivalence_test()
35endfunc
Bram Moolenaaraf98a492016-04-24 14:40:12 +020036
37func s:classes_test()
38 call assert_equal('Motörhead', matchstr('Motörhead', '[[:print:]]\+'))
39
40 let alphachars = ''
41 let lowerchars = ''
42 let upperchars = ''
43 let alnumchars = ''
44 let printchars = ''
45 let punctchars = ''
46 let xdigitchars = ''
47 let i = 1
48 while i <= 255
49 let c = nr2char(i)
50 if c =~ '[[:alpha:]]'
51 let alphachars .= c
52 endif
53 if c =~ '[[:lower:]]'
54 let lowerchars .= c
55 endif
56 if c =~ '[[:upper:]]'
57 let upperchars .= c
58 endif
59 if c =~ '[[:alnum:]]'
60 let alnumchars .= c
61 endif
62 if c =~ '[[:print:]]'
63 let printchars .= c
64 endif
65 if c =~ '[[:punct:]]'
66 let punctchars .= c
67 endif
68 if c =~ '[[:xdigit:]]'
69 let xdigitchars .= c
70 endif
71 let i += 1
72 endwhile
73
74 call assert_equal('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', alphachars)
75 call assert_equal('abcdefghijklmnopqrstuvwxyzµßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', lowerchars)
76 call assert_equal('ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ', upperchars)
77 call assert_equal('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', alnumchars)
78 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ', printchars)
79 call assert_equal('!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~', punctchars)
80 call assert_equal('0123456789ABCDEFabcdef', xdigitchars)
81endfunc
82
83func Test_classes_re1()
84 set re=1
85 call s:classes_test()
86endfunc
87
88func Test_classes_re2()
89 set re=2
90 call s:classes_test()
91endfunc