File: region-type.vim

package info (click to toggle)
vim-textobj-user 0.7.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 208 kB
  • sloc: makefile: 2
file content (133 lines) | stat: -rw-r--r-- 2,922 bytes parent folder | download | duplicates (2)
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
call textobj#user#plugin('single', {
\   'default': {
\     'pattern': 'foo\_.*bar',
\     'select': 'asd',
\   },
\   'char': {
\     'pattern': 'foo\_.*bar',
\     'region-type': 'v',
\     'select': 'asc',
\   },
\   'line': {
\     'pattern': 'foo\_.*bar',
\     'region-type': 'V',
\     'select': 'asl',
\   },
\   'block': {
\     'pattern': 'foo\_.*bar',
\     'region-type': "\<C-v>",
\     'select': 'asb',
\   },
\ })

call textobj#user#plugin('paired', {
\   'default': {
\     'pattern': ['foo', 'bar'],
\     'select-a': 'apd',
\     'select-i': 'ipd',
\   },
\   'char': {
\     'pattern': ['foo', 'bar'],
\     'region-type': 'v',
\     'select-a': 'apc',
\     'select-i': 'ipc',
\   },
\   'line': {
\     'pattern': ['^.*foo.*\n', '^.*bar.*\n'],
\     'region-type': 'V',
\     'select-a': 'apl',
\     'select-i': 'ipl',
\   },
\   'block': {
\     'pattern': ['foo', 'bar'],
\     'region-type': "\<C-v>",
\     'select-a': 'apb',
\     'select-i': 'ipb',
\   },
\ })

function! TheLastRegion()
  return [visualmode(), [line("'<"), col("'<")], [line("'>"), col("'>")]]
endfunction

describe 'Single-pattern text object'
  before
    new
    0 put =[
    \   '___foo___',
    \   '_________',
    \   '___bar___',
    \ ]
  end

  after
    close!
  end

  it 'is characterwise by default'
    execute 'normal' "2Gvasd\<Esc>"
    Expect TheLastRegion() ==# ['v', [1, 4], [3, 6]]
  end

  it 'can be customized to be characterwise'
    execute 'normal' "2Gvasc\<Esc>"
    Expect TheLastRegion() ==# ['v', [1, 4], [3, 6]]
  end

  it 'can be customized to be linewise'
    execute 'normal' "2Gvasl\<Esc>"
    Expect TheLastRegion() ==# ['V', [1, 1], [3, 10]]
  end

  it 'can be customized to be blockwise'
    execute 'normal' "2Gvasb\<Esc>"
    Expect TheLastRegion() ==# ["\<C-v>", [1, 4], [3, 6]]
  end
end

describe 'Paired-pattern text object'
  before
    new
    0 put =[
    \   '___foo___',
    \   '_________',
    \   '___bar___',
    \ ]
  end

  after
    close!
  end

  it 'is characterwise by default'
    execute 'normal' "2Gvapd\<Esc>"
    Expect TheLastRegion() ==# ['v', [1, 4], [3, 6]]

    execute 'normal' "2Gvipd\<Esc>"
    Expect TheLastRegion() ==# ['v', [1, 7], [3, 3]]
  end

  it 'can be customized to be characterwise'
    execute 'normal' "2Gvapc\<Esc>"
    Expect TheLastRegion() ==# ['v', [1, 4], [3, 6]]

    execute 'normal' "2Gvipc\<Esc>"
    Expect TheLastRegion() ==# ['v', [1, 7], [3, 3]]
  end

  it 'can be customized to be linewise'
    execute 'normal' "2Gvapl\<Esc>"
    Expect TheLastRegion() ==# ['V', [1, 1], [3, 10]]

    execute 'normal' "2Gvipl\<Esc>"
    Expect TheLastRegion() ==# ['V', [2, 1], [2, 10]]
  end

  it 'can be customized to be blockwise'
    execute 'normal' "2Gvapb\<Esc>"
    Expect TheLastRegion() ==# ["\<C-v>", [1, 4], [3, 6]]

    execute 'normal' "2Gvipb\<Esc>"
    Expect TheLastRegion() ==# ["\<C-v>", [1, 7], [3, 3]]
  end
end