Bram Moolenaar | 22e4215 | 2016-04-03 14:02:02 +0200 | [diff] [blame] | 1 | " Tests for regexp in latin1 encoding |
| 2 | set encoding=latin1 |
| 3 | scriptencoding latin1 |
| 4 | |
| 5 | func s:equivalence_test() |
| 6 | 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ñ oòóôõöø p q r s t uùúûü v w x yýÿ z" |
| 7 | let groups = split(str) |
| 8 | for group1 in groups |
| 9 | for c in split(group1, '\zs') |
| 10 | " next statement confirms that equivalence class matches every |
| 11 | " character in group |
| 12 | call assert_match('^[[=' . c . '=]]*$', group1) |
| 13 | for group2 in groups |
| 14 | if group2 != group1 |
| 15 | " next statement converts that equivalence class doesn't match |
| 16 | " a character in any other group |
| 17 | call assert_equal(-1, match(group2, '[[=' . c . '=]]')) |
| 18 | endif |
| 19 | endfor |
| 20 | endfor |
| 21 | endfor |
| 22 | endfunc |
| 23 | |
| 24 | func Test_equivalence_re1() |
| 25 | set re=1 |
| 26 | call s:equivalence_test() |
| 27 | endfunc |
| 28 | |
| 29 | func Test_equivalence_re2() |
| 30 | set re=2 |
| 31 | call s:equivalence_test() |
| 32 | endfunc |
Bram Moolenaar | f5a3944 | 2016-08-16 21:04:41 +0200 | [diff] [blame] | 33 | |
| 34 | func Test_recursive_substitute() |
| 35 | new |
| 36 | s/^/\=execute("s#^##gn") |
| 37 | " check we are now not in the sandbox |
| 38 | call setwinvar(1, 'myvar', 1) |
| 39 | bwipe! |
| 40 | endfunc |
Bram Moolenaar | d563883 | 2016-09-09 17:59:50 +0200 | [diff] [blame] | 41 | |
| 42 | func Test_nested_backrefs() |
| 43 | " Check example in change.txt. |
| 44 | new |
| 45 | for re in range(0, 2) |
| 46 | exe 'set re=' . re |
| 47 | call setline(1, 'aa ab x') |
| 48 | 1s/\(\(a[a-d] \)*\)\(x\)/-\1- -\2- -\3-/ |
| 49 | call assert_equal('-aa ab - -ab - -x-', getline(1)) |
| 50 | |
| 51 | call assert_equal('-aa ab - -ab - -x-', substitute('aa ab x', '\(\(a[a-d] \)*\)\(x\)', '-\1- -\2- -\3-', '')) |
| 52 | endfor |
| 53 | bwipe! |
| 54 | set re=0 |
| 55 | endfunc |
Bram Moolenaar | 16b3578 | 2016-09-09 20:29:50 +0200 | [diff] [blame] | 56 | |
| 57 | func Test_eow_with_optional() |
| 58 | let expected = ['abc def', 'abc', 'def', '', '', '', '', '', '', ''] |
| 59 | for re in range(0, 2) |
| 60 | exe 'set re=' . re |
| 61 | let actual = matchlist('abc def', '\(abc\>\)\?\s*\(def\)') |
| 62 | call assert_equal(expected, actual) |
| 63 | endfor |
| 64 | endfunc |
Bram Moolenaar | 1ef9bbe | 2017-06-17 20:08:20 +0200 | [diff] [blame^] | 65 | |
| 66 | func Test_backref() |
| 67 | new |
| 68 | call setline(1, ['one', 'two', 'three', 'four', 'five']) |
| 69 | call assert_equal(3, search('\%#=1\(e\)\1')) |
| 70 | call assert_equal(3, search('\%#=2\(e\)\1')) |
| 71 | call assert_fails('call search("\\%#=1\\(e\\1\\)")', 'E65:') |
| 72 | call assert_fails('call search("\\%#=2\\(e\\1\\)")', 'E65:') |
| 73 | bwipe! |
| 74 | endfunc |