summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_textobjects.vim
blob: 684f197f5f5d50907c4f0c47b2f09680240973e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
" Test for textobjects

if !has('textobjects')
  finish
endif

func CpoM(line, useM, expected)
  new

  if a:useM
    set cpoptions+=M
  else
    set cpoptions-=M
  endif

  call setline(1, a:line)

  call setreg('"', '')
  normal! ggfrmavi)y
  call assert_equal(getreg('"'), a:expected[0])

  call setreg('"', '')
  normal! `afbmavi)y
  call assert_equal(getreg('"'), a:expected[1])

  call setreg('"', '')
  normal! `afgmavi)y
  call assert_equal(getreg('"'), a:expected[2])

  q!
endfunc

func Test_inner_block_without_cpo_M()
  call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
endfunc

func Test_inner_block_with_cpo_M_left_backslash()
  call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
endfunc

func Test_inner_block_with_cpo_M_right_backslash()
  call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
endfunc

func Test_quote_selection_selection_exclusive()
  new
  call setline(1, "a 'bcde' f")
  set selection=exclusive
  exe "norm! fdvhi'y"
  call assert_equal('bcde', @")
  set selection&vim
  bw!
endfunc

" Tests for string and html text objects
func Test_string_html_objects()
  enew!

  let t = '"wo\"rd\\" foo'
  put =t
  normal! da"
  call assert_equal('foo', getline('.'))

  let t = "'foo' 'bar' 'piep'"
  put =t
  normal! 0va'a'rx
  call assert_equal("xxxxxxxxxxxx'piep'", getline('.'))

  let t = "bla bla `quote` blah"
  put =t
  normal! 02f`da`
  call assert_equal("bla bla blah", getline('.'))

  let t = 'out " in "noXno"'
  put =t
  normal! 0fXdi"
  call assert_equal('out " in ""', getline('.'))

  let t = "\"'\" 'blah' rep 'buh'"
  put =t
  normal! 03f'vi'ry
  call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'))

  set quoteescape=+*-
  let t = "bla `s*`d-`+++`l**` b`la"
  put =t
  normal! di`
  call assert_equal("bla `` b`la", getline('.'))

  let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
  put =t
  normal! $F"va"oha"i"rz
  call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'))

  let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
  put =t
  normal! fXdit
  call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'))

  let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
  put =t
  normal! 0fXdit
  call assert_equal('-<b></b>-', getline('.'))

  let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
  put =t
  normal! fXdat
  call assert_equal('-<b>asdfasdf</b>-', getline('.'))

  let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
  put =t
  normal! 0fXdat
  call assert_equal('--', getline('.'))

  let t = "-<b>\ninnertext object\n</b>"
  put =t
  normal! dit
  call assert_equal('-<b></b>', getline('.'))

  set quoteescape&
  enew!
endfunc

" Tests for match() and matchstr()
func Test_match()
  call assert_equal("b", matchstr("abcd", ".", 0, 2))
  call assert_equal("bc", matchstr("abcd", "..", 0, 2))
  call assert_equal("c", matchstr("abcd", ".", 2, 0))
  call assert_equal("a", matchstr("abcd", ".", 0, -1))
  call assert_equal(-1, match("abcd", ".", 0, 5))
  call assert_equal(0 , match("abcd", ".", 0, -1))
  call assert_equal(0 , match('abc', '.', 0, 1))
  call assert_equal(1 , match('abc', '.', 0, 2))
  call assert_equal(2 , match('abc', '.', 0, 3))
  call assert_equal(-1, match('abc', '.', 0, 4))
  call assert_equal(1 , match('abc', '.', 1, 1))
  call assert_equal(2 , match('abc', '.', 2, 1))
  call assert_equal(-1, match('abc', '.', 3, 1))
  call assert_equal(3 , match('abc', '$', 0, 1))
  call assert_equal(-1, match('abc', '$', 0, 2))
  call assert_equal(3 , match('abc', '$', 1, 1))
  call assert_equal(3 , match('abc', '$', 2, 1))
  call assert_equal(3 , match('abc', '$', 3, 1))
  call assert_equal(-1, match('abc', '$', 4, 1))
  call assert_equal(0 , match('abc', '\zs', 0, 1))
  call assert_equal(1 , match('abc', '\zs', 0, 2))
  call assert_equal(2 , match('abc', '\zs', 0, 3))
  call assert_equal(3 , match('abc', '\zs', 0, 4))
  call assert_equal(-1, match('abc', '\zs', 0, 5))
  call assert_equal(1 , match('abc', '\zs', 1, 1))
  call assert_equal(2 , match('abc', '\zs', 2, 1))
  call assert_equal(3 , match('abc', '\zs', 3, 1))
  call assert_equal(-1, match('abc', '\zs', 4, 1))
endfunc