1" Test for textobjects
2
3if !has('textobjects')
4  finish
5endif
6
7set belloff=all
8func CpoM(line, useM, expected)
9  new
10
11  if a:useM
12    set cpoptions+=M
13  else
14    set cpoptions-=M
15  endif
16
17  call setline(1, a:line)
18
19  call setreg('"', '')
20  normal! ggfrmavi)y
21  call assert_equal(getreg('"'), a:expected[0])
22
23  call setreg('"', '')
24  normal! `afbmavi)y
25  call assert_equal(getreg('"'), a:expected[1])
26
27  call setreg('"', '')
28  normal! `afgmavi)y
29  call assert_equal(getreg('"'), a:expected[2])
30
31  q!
32endfunc
33
34func Test_inner_block_without_cpo_M()
35  call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
36endfunc
37
38func Test_inner_block_with_cpo_M_left_backslash()
39  call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
40endfunc
41
42func Test_inner_block_with_cpo_M_right_backslash()
43  call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
44endfunc
45
46func Test_quote_selection_selection_exclusive()
47  new
48  call setline(1, "a 'bcde' f")
49  set selection=exclusive
50  exe "norm! fdvhi'y"
51  call assert_equal('bcde', @")
52  set selection&vim
53  bw!
54endfunc
55
56" Tests for string and html text objects
57func Test_string_html_objects()
58  enew!
59
60  let t = '"wo\"rd\\" foo'
61  put =t
62  normal! da"
63  call assert_equal('foo', getline('.'))
64
65  let t = "'foo' 'bar' 'piep'"
66  put =t
67  normal! 0va'a'rx
68  call assert_equal("xxxxxxxxxxxx'piep'", getline('.'))
69
70  let t = "bla bla `quote` blah"
71  put =t
72  normal! 02f`da`
73  call assert_equal("bla bla blah", getline('.'))
74
75  let t = 'out " in "noXno"'
76  put =t
77  normal! 0fXdi"
78  call assert_equal('out " in ""', getline('.'))
79
80  let t = "\"'\" 'blah' rep 'buh'"
81  put =t
82  normal! 03f'vi'ry
83  call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'))
84
85  set quoteescape=+*-
86  let t = "bla `s*`d-`+++`l**` b`la"
87  put =t
88  normal! di`
89  call assert_equal("bla `` b`la", getline('.'))
90
91  let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
92  put =t
93  normal! $F"va"oha"i"rz
94  call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'))
95
96  let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
97  put =t
98  normal! fXdit
99  call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'))
100
101  let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
102  put =t
103  normal! 0fXdit
104  call assert_equal('-<b></b>-', getline('.'))
105
106  let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
107  put =t
108  normal! fXdat
109  call assert_equal('-<b>asdfasdf</b>-', getline('.'))
110
111  let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
112  put =t
113  normal! 0fXdat
114  call assert_equal('--', getline('.'))
115
116  let t = "-<b>\ninnertext object\n</b>"
117  put =t
118  normal! dit
119  call assert_equal('-<b></b>', getline('.'))
120
121  set quoteescape&
122  enew!
123endfunc
124
125" Tests for match() and matchstr()
126func Test_match()
127  call assert_equal("b", matchstr("abcd", ".", 0, 2))
128  call assert_equal("bc", matchstr("abcd", "..", 0, 2))
129  call assert_equal("c", matchstr("abcd", ".", 2, 0))
130  call assert_equal("a", matchstr("abcd", ".", 0, -1))
131  call assert_equal(-1, match("abcd", ".", 0, 5))
132  call assert_equal(0 , match("abcd", ".", 0, -1))
133  call assert_equal(0 , match('abc', '.', 0, 1))
134  call assert_equal(1 , match('abc', '.', 0, 2))
135  call assert_equal(2 , match('abc', '.', 0, 3))
136  call assert_equal(-1, match('abc', '.', 0, 4))
137  call assert_equal(1 , match('abc', '.', 1, 1))
138  call assert_equal(2 , match('abc', '.', 2, 1))
139  call assert_equal(-1, match('abc', '.', 3, 1))
140  call assert_equal(3 , match('abc', '$', 0, 1))
141  call assert_equal(-1, match('abc', '$', 0, 2))
142  call assert_equal(3 , match('abc', '$', 1, 1))
143  call assert_equal(3 , match('abc', '$', 2, 1))
144  call assert_equal(3 , match('abc', '$', 3, 1))
145  call assert_equal(-1, match('abc', '$', 4, 1))
146  call assert_equal(0 , match('abc', '\zs', 0, 1))
147  call assert_equal(1 , match('abc', '\zs', 0, 2))
148  call assert_equal(2 , match('abc', '\zs', 0, 3))
149  call assert_equal(3 , match('abc', '\zs', 0, 4))
150  call assert_equal(-1, match('abc', '\zs', 0, 5))
151  call assert_equal(1 , match('abc', '\zs', 1, 1))
152  call assert_equal(2 , match('abc', '\zs', 2, 1))
153  call assert_equal(3 , match('abc', '\zs', 3, 1))
154  call assert_equal(-1, match('abc', '\zs', 4, 1))
155endfunc
156