annotate src/testdir/test_regexp_latin.vim @ 10170:4acacf4081ce v7.4.2355

commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 9 20:29:50 2016 +0200 patch 7.4.2355 Problem: Regexp fails to match when using "\>\)\?". (Ramel) Solution: When a state is already in the list, but addstate_here() is used and the existing state comes later, add the new state anyway.
author Christian Brabandt <cb@256bit.org>
date Fri, 09 Sep 2016 20:30:07 +0200
parents 3c37899baa8d
children 14b6b79d685b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8825
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for regexp in latin1 encoding
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 set encoding=latin1
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 scriptencoding latin1
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 func s:equivalence_test()
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
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"
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let groups = split(str)
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 for group1 in groups
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 for c in split(group1, '\zs')
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 " next statement confirms that equivalence class matches every
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 " character in group
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call assert_match('^[[=' . c . '=]]*$', group1)
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 for group2 in groups
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 if group2 != group1
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 " next statement converts that equivalence class doesn't match
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 " a character in any other group
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_equal(-1, match(group2, '[[=' . c . '=]]'))
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 endif
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endfor
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 endfor
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 endfor
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endfunc
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 func Test_equivalence_re1()
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 set re=1
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 call s:equivalence_test()
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 endfunc
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 func Test_equivalence_re2()
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 set re=2
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call s:equivalence_test()
318eaa6fa973 commit https://github.com/vim/vim/commit/22e421549d54147d003f6444de007cb1d73f1d27
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunc
9890
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
33
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
34 func Test_recursive_substitute()
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
35 new
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
36 s/^/\=execute("s#^##gn")
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
37 " check we are now not in the sandbox
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
38 call setwinvar(1, 'myvar', 1)
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
39 bwipe!
064effd222a3 commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents: 8825
diff changeset
40 endfunc
10168
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
41
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
42 func Test_nested_backrefs()
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
43 " Check example in change.txt.
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
44 new
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
45 for re in range(0, 2)
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
46 exe 'set re=' . re
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
47 call setline(1, 'aa ab x')
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
48 1s/\(\(a[a-d] \)*\)\(x\)/-\1- -\2- -\3-/
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
49 call assert_equal('-aa ab - -ab - -x-', getline(1))
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
50
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
51 call assert_equal('-aa ab - -ab - -x-', substitute('aa ab x', '\(\(a[a-d] \)*\)\(x\)', '-\1- -\2- -\3-', ''))
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
52 endfor
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
53 bwipe!
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
54 set re=0
3c37899baa8d commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
55 endfunc
10170
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
56
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
57 func Test_eow_with_optional()
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
58 let expected = ['abc def', 'abc', 'def', '', '', '', '', '', '', '']
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
59 for re in range(0, 2)
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
60 exe 'set re=' . re
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
61 let actual = matchlist('abc def', '\(abc\>\)\?\s*\(def\)')
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
62 call assert_equal(expected, actual)
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
63 endfor
4acacf4081ce commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents: 10168
diff changeset
64 endfunc