about summary refs log tree commit diff
path: root/Test/X05zleincarg.ztst
blob: cd9817c827fc5923655cdb7ed777533795a6e6ef (plain) (blame)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# Tests the incarg ZLE widget

%prep
  ZSH_TEST_LANG=$(ZTST_find_UTF8)
  if ( zmodload zsh/zpty 2>/dev/null ); then
    . $ZTST_srcdir/comptest
    comptestinit -v -z $ZTST_testdir/../Src/zsh
  else
    ZTST_unimplemented="the zsh/zpty module is not available"
  fi
  zpty_run '
    autoload -Uz incarg
    for name in {,vim-,vim-backward-}{,sync-}{inc,dec}arg; do
      zle -N "$name" incarg
    done
    bindkey -v "^N" incarg
    bindkey -v "^P" decarg
    bindkey -v "^F" sync-incarg
    bindkey -v "^B" sync-decarg
    bindkey -a "^N" vim-incarg
    bindkey -a "^P" vim-decarg
    bindkey -a "^F" vim-sync-incarg
    bindkey -a "^B" vim-sync-decarg
    bindkey -a "^E" vim-backward-incarg
    bindkey -a "^Y" vim-backward-decarg
    unset TMUX_PANE ITERM_SESSION_ID
    tmux() {
      echo "$TMUX_PANE"
    }
  '

%test

# Basic increment & decrement

  zletest $'0\C-n'
0:incarg increments an integer
>BUFFER: 1
>CURSOR: 1

  zletest $'0\C-p'
0:decarg decrements an integer
>BUFFER: -1
>CURSOR: 2

  zletest $'echo 0\e0\C-n'
0:vim-incarg increments an integer
>BUFFER: echo 1
>CURSOR: 5

  zletest $'echo 0\e0\C-p'
0:vim-decarg decrements an integer
>BUFFER: echo -1
>CURSOR: 6

  zletest $'echo 0 foo\e\C-e'
0:vim-backward-incarg increments an integer
>BUFFER: echo 1 foo
>CURSOR: 5

  zletest $'echo 0 foo\e\C-y'
0:vim-backward-decarg decrements an integer
>BUFFER: echo -1 foo
>CURSOR: 6

# sync- variants

  zletest $'0\C-f'
0:sync-incarg does nothing on unsupported terminals
>BUFFER: 0
>CURSOR: 1

  zpty_run 'TMUX_PANE=0'
  zletest $'0\C-f'
  zpty_run 'unset TMUX_PANE'
0:sync-incarg does nothing on tmux in pane 0
>BUFFER: 0
>CURSOR: 1

  zpty_run 'TMUX_PANE=1'
  zletest $'0\C-f'
  zpty_run 'unset TMUX_PANE'
0:sync-incarg increments by 1 on tmux in pane 1
>BUFFER: 1
>CURSOR: 1

  zpty_run 'TMUX_PANE=2'
  zletest $'0\C-f'
  zpty_run 'unset TMUX_PANE'
0:sync-incarg increments by 2 on tmux in pane 2
>BUFFER: 2
>CURSOR: 1

  zpty_run 'ITERM_SESSION_ID=w0t0p0:00000000-0000-0000-0000-000000000000'
  zletest $'0\C-f'
  zpty_run 'unset ITERM_SESSION_ID'
0:sync-incarg does nothing on tmux in pane 0
>BUFFER: 0
>CURSOR: 1

  zpty_run 'ITERM_SESSION_ID=w0t0p1:00000000-0000-0000-0000-000000000000'
  zletest $'0\C-f'
  zpty_run 'unset ITERM_SESSION_ID'
0:sync-incarg increments by 1 on tmux in pane 1
>BUFFER: 1
>CURSOR: 1

  zpty_run 'ITERM_SESSION_ID=w0t0p2:00000000-0000-0000-0000-000000000000'
  zletest $'0\C-f'
  zpty_run 'unset ITERM_SESSION_ID'
0:sync-incarg increments by 2 on tmux in pane 2
>BUFFER: 2
>CURSOR: 1

  zpty_run 'TMUX_PANE=1'
  zpty_run 'ITERM_SESSION_ID=w0t0p2:00000000-0000-0000-0000-000000000000'
  zletest $'0\C-f'
  zpty_run 'unset TMUX_PANE ITERM_SESSION_ID'
0:sync-incarg prioritizes tmux pane number over iTerm2's
>BUFFER: 1
>CURSOR: 1

  zletest $'0\e2\C-n'
0:incarg changes the incremented amount based on the numeric argument
>BUFFER: 2
>CURSOR: 0

  zpty_run 'incarg=3'
  zletest $'0\e\C-n'
  zpty_run 'unset incarg'
0:incarg changes the default incremented amount based on the incarg variable
>BUFFER: 3
>CURSOR: 0

  zpty_run 'incarg=3'
  zletest $'0\e2\C-n'
  zpty_run 'unset incarg'
0:incarg prioritizes the numeric argument over the incarg variable
>BUFFER: 2
>CURSOR: 0

  zpty_run 'TMUX_PANE=2'
  zletest $'0\e2\C-f'
  zpty_run 'unset TMUX_PANE'
0:The sync- variants of incarg takes the numeric argument into account
>BUFFER: 4
>CURSOR: 0

# Leading zeros

  zletest $'000\C-n'
0:incarg preserves leading zeros of decimal integers
>BUFFER: 001
>CURSOR: 3

  zletest $'-001\C-n\C-n'
0:incarg preserves leading zeros when the digit turns from negative to positive
>BUFFER: 001
>CURSOR: 3

  zletest $'001\C-p\C-p'
0:incarg preserves leading zeros when the digit turns from positive to negative
>BUFFER: -001
>CURSOR: 4

  zletest $'001\e1000\C-n'
0:incarg works when the result has more number of digits than the original
>BUFFER: 1001
>CURSOR: 3

  zletest $'001\e2000\C-p'
0:decargs works on integers with leading zeros when the result has more digits than the original
>BUFFER: -1999
>CURSOR: 4

  zletest $'-000\C-n'
0:incarg produces the correct number of zeros when incrementing integers starting with -0
>BUFFER: 001
>CURSOR: 3

  zletest $'-000\C-p'
0:decarg produces the correct number of zeros when incrementing integers starting with -0
>BUFFER: -001
>CURSOR: 4

  zpty_run 'incarg=0'
  zletest $'-000\C-n'
  zpty_run 'unset incarg'
0:incarg removes the sign when the target integer starts with -0 and the increment amount is 0
>BUFFER: 000
>CURSOR: 3

  zletest $'-0\C-n'
0:incarg turns -0 into 1
>BUFFER: 1
>CURSOR: 1

  zletest $'-0\C-p'
0:decarg turns -0 into -1
>BUFFER: -1
>CURSOR: 2

  zpty_run 'incarg=0'
  zletest $'-0\C-n'
  zpty_run 'unset incarg'
0:incarg turns -0 into 0 when the increment amount is 0
>BUFFER: 0
>CURSOR: 1

# Binaries

  zletest $'0b11\C-n'
0:incarg can increment a binary integer
>BUFFER: 0b100
>CURSOR: 5

  zletest $'0B11\C-n'
0:incarg can increment a binary integer with an upper case prefix
>BUFFER: 0B100
>CURSOR: 5

  zletest $'0b100\C-p'
0:decarg can decrement a binary integer
>BUFFER: 0b11
>CURSOR: 4

  zletest $'0b0011\C-n'
0:incarg can preserve leading zeros of binaries
>BUFFER: 0b0100
>CURSOR: 6

  zletest $'0b001\e8\C-n'
0:incarg works on binaries when the result has more zeros than the original
>BUFFER: 0b1001
>CURSOR: 5

  zletest $'0b0\C-p'
0:decarg fails to produce a negative binary value
>BUFFER: 0b0
>CURSOR: 3

# Octals

  zletest $'0o7\C-n'
0:incarg can increment an octal integer
>BUFFER: 0o10
>CURSOR: 4

  zletest $'0O7\C-n'
0:incarg can increment an octal integer with an upper case prefix
>BUFFER: 0O10
>CURSOR: 4

  zletest $'0o10\C-p'
0:decarg can decrement an octal integer
>BUFFER: 0o7
>CURSOR: 3

  zletest $'0o0\C-p'
0:decarg fails to produce a negative octal value
>BUFFER: 0o0
>CURSOR: 3

# Hexadecimals

  zletest $'0x9\C-n'
0:incarg can increment a hexadecimal integer
>BUFFER: 0xa
>CURSOR: 3

  zletest $'0X9\C-n'
0:incarg can increment a hexadecimal integer with an upper case prefix
>BUFFER: 0XA
>CURSOR: 3

  zletest $'0xf\C-n'
0:incarg can increment a hexadecimal integer with no numeric digit
>BUFFER: 0x10
>CURSOR: 4

  zletest $'0x10\C-p'
0:decarg can decrement a hexadecimal integer
>BUFFER: 0xf
>CURSOR: 3

  zletest $'0x0\C-p'
0:decarg fails to produce a negative hexadecimal value
>BUFFER: 0x0
>CURSOR: 3

  zletest $'0x0b1\C-n'
0:incarg interprets integers starting with 0x0b as a hexadecimal
>BUFFER: 0x0b2
>CURSOR: 5

  zletest $'0x0b1\e\C-e'
0:vim-backward-incarg interprets integers starting with 0x0b as a hexadecimal
>BUFFER: 0x0b2
>CURSOR: 4

# Cursor position - incarg

  zletest $'echo 012ab\eF i\C-n'
0:incarg does nothing when the cursor is placed just to the left of an integer
>BUFFER: echo 012ab
>CURSOR: 4

  zletest $'echo 012ab\eF0i\C-n'
0:incarg works when the cursor is placed at the leftmost digit of an integer
>BUFFER: echo 013ab
>CURSOR: 8

  zletest $'echo 012ab\eF1i\C-n'
0:incarg works when the cursor is placed at the inner digit of an integer
>BUFFER: echo 013ab
>CURSOR: 8

  zletest $'echo 012ab\eF2i\C-n'
0:incarg works when the cursor is placed at the rightmost digit of an integer
>BUFFER: echo 013ab
>CURSOR: 8

  zletest $'echo 012ab\eFai\C-n'
0:incarg works when the cursor is placed just to the right of an integer
>BUFFER: echo 013ab
>CURSOR: 8

  zletest $'echo 012ab\ei\C-n'
0:incarg does nothing when the cursor is placed more than a single letter away to the right
>BUFFER: echo 012ab
>CURSOR: 9

  zletest $'10x9\e0\C-n'
0:incarg turns [0-9]0x[0-9a-f] into [0-9]1x[0-9a-f] when the cursor is at the left of x
>BUFFER: 11x9
>CURSOR: 1

  zletest $'10x9\eFx\C-n'
0:incarg takes [0-9]0x[0-9a-f] and increments the hexadecimal part when the cursor is on x
>BUFFER: 10xa
>CURSOR: 3

  zletest $'10x9\e\C-n'
0:incarg takes [0-9]0x[0-9a-f] and increments the hexadecimal part when the cursor is at the right of x
>BUFFER: 10xa
>CURSOR: 3

  zletest $'10b1\e0\C-n'
0:incarg turns [0-9]0b[01] into [0-9]1b[01] when the cursor is at the left of b
>BUFFER: 11b1
>CURSOR: 1

  zletest $'10b1\eFb\C-n'
0:incarg takes [0-9]0b[01] and increments the binary part when the cursor is on b
>BUFFER: 10b10
>CURSOR: 4

  zletest $'10b1\e\C-n'
0:incarg takes [0-9]0b[01] and increments binary part when the cursor is at the right of b
>BUFFER: 10b10
>CURSOR: 4

  zletest $'10o7\e0\C-n'
0:incarg turns [0-9]0o[0-7] into [0-9]1o[0-7] when the cursor is at the left of o
>BUFFER: 11o7
>CURSOR: 1

  zletest $'10o7\eFo\C-n'
0:incarg takes [0-9]0o[0-7] and increments the octal part when the cursor is on o
>BUFFER: 10o10
>CURSOR: 4

  zletest $'10o7\e\C-n'
0:incarg takes [0-9]0o[0-7] and increments the octal part when the cursor is at the right of o
>BUFFER: 10o10
>CURSOR: 4

  zletest $'0b0x9\eF0\C-n'
0:incarg takes 0b0x[0-9a-f] and increments the binary part when the cursor is at the left of x
>BUFFER: 0b1x9
>CURSOR: 2

  zletest $'0b0x9\eFx\C-n'
0:incarg takes 0b0x[0-9a-f] and increments the hexadecimal part when the cursor is on x
>BUFFER: 0b0xa
>CURSOR: 4

  zletest $'0b0x9\e\C-n'
0:incarg takes 0b0x[0-9a-f] and increments the hexadecimal part when the cursor is at the right of x
>BUFFER: 0b0xa
>CURSOR: 4

# Cursor position - vim-incarg

  zletest $'echo 012ab\eF \C-n'
0:vim-incarg works when the cursor is placed to the left of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\eF0\C-n'
0:vim-incarg works when the cursor is placed at the leftmost digit of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\eF1\C-n'
0:vim-incarg works when the cursor is placed at the inner digit of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\eF2\C-n'
0:incarg works when the cursor is placed at the rightmost digit of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\eFa\C-n'
0:vim-incarg does nothing when the cursor is placed to the right of an integer
>BUFFER: echo 012ab
>CURSOR: 8

  zletest $'echo 012ab\ei\C-n'
0:vim-incarg does nothing when the cursor is placed more than a single letter away to the right
>BUFFER: echo 012ab
>CURSOR: 9

# Cursor position - vim-backward-incarg

  zletest $'echo 012ab\eF \C-e'
0:vim-backward-incarg does nothing when the cursor is placed just to the left of an integer
>BUFFER: echo 012ab
>CURSOR: 4

  zletest $'echo 012ab\eF0\C-e'
0:vim-backward-incarg works when the cursor is placed at the leftmost digit of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\eF1\C-e'
0:vim-backward-incarg works when the cursor is placed at the inner digit of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\eF2\C-e'
0:vim-backward-incarg works when the cursor is placed at the rightmost digit of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\eFa\C-e'
0:vim-backward-incarg works when the cursor is placed just to the right of an integer
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'echo 012ab\e\C-e'
0:vim-backward-incarg works when the cursor is placed more than a single letter away to the right
>BUFFER: echo 013ab
>CURSOR: 7

  zletest $'10x9\eFx\C-e'
0:vim-backward-incarg will take [0-9]0x[0-9a-f] and increment the hexadecimal part when the cursor is on x
>BUFFER: 10xa
>CURSOR: 3

  zletest $'10x9\e\C-e'
0:vim-backward-incarg will take [0-9]0x[0-9a-f] and increment the hexadecimal part when the cursor is on the right of x
>BUFFER: 10xa
>CURSOR: 3

  zletest $'10b1\e0\C-e'
0:vim-backward-incarg will turn [0-9]0b[01] into [0-9]1b[01] when the cursor is at the left of b
>BUFFER: 11b1
>CURSOR: 1

  zletest $'10b1\eFb\C-e'
0:vim-backward-incarg will take [0-9]0b[01] and increment the binary part when the cursor is on b
>BUFFER: 10b10
>CURSOR: 4

  zletest $'10b1\e\C-e'
0:vim-backward-incarg will take [0-9]0b[01] and increment the binary part when the cursor is on the right of b
>BUFFER: 10b10
>CURSOR: 4

  zletest $'10o7\e0\C-e'
0:vim-backward-incarg will turn [0-9]0o[0-7] into [0-9]1o[0-7] when the cursor is at the left of o
>BUFFER: 11o7
>CURSOR: 1

  zletest $'10o7\eFo\C-e'
0:vim-backward-incarg will take [0-9]0o[0-7] and increment the octal part when the cursor is on o
>BUFFER: 10o10
>CURSOR: 4

  zletest $'10o7\e\C-e'
0:vim-backward-incarg will take [0-9]0o[0-7] and increment the octal part when the cursor is at the right of o
>BUFFER: 10o10
>CURSOR: 4

  zletest $'0b0x9\eF0\C-e'
0:vim-backward-incarg will take 0b0x[0-9a-f] and increment the binary 0b0 when the cursor is on the left of x
>BUFFER: 0b1x9
>CURSOR: 2

  zletest $'0b0x9\eFx\C-e'
0:vim-backward-incarg will take 0b0x[0-9a-f] and increment the hexadecimal part when the cursor is on x
>BUFFER: 0b0xa
>CURSOR: 4

  zletest $'0b0x9\e\C-e'
0:vim-backward-incarg will take 0b0x[0-9a-f] and increment the hexadecimal part when the cursor is at the right of x
>BUFFER: 0b0xa
>CURSOR: 4

# Repeats

  zletest $'echo 0\e0\C-n.'
0:vim-incarg is compatible with the repeat command
>BUFFER: echo 2
>CURSOR: 5

  zletest $'echo 0\e0\C-p.'
0:vim-decarg is compatible with the repeat command
>BUFFER: echo -2
>CURSOR: 6

  zletest $'echo 0 foo\e\C-e.'
0:vim-backward-incarg is compatible with the repeat command
>BUFFER: echo 2 foo
>CURSOR: 5

  zletest $'echo 0\e010\C-n.'
0:Repeats of vim-incarg takes the numeric argument into account
>BUFFER: echo 20
>CURSOR: 6

  zletest $'echo 0 foo\e10\C-e.'
0:Repeats of vim-backward-incarg takes the numeric argument into account
>BUFFER: echo 20 foo
>CURSOR: 6

  zpty_run 'TMUX_PANE=0'
  zletest $'echo 0\e0\C-f.'
  zpty_run 'unset TMUX_PANE'
0:Repeats of vim-sync-incarg work in pane 0
>BUFFER: echo 0
>CURSOR: 5

  zpty_run 'TMUX_PANE=1'
  zletest $'echo 0\e0\C-f.'
  zpty_run 'unset TMUX_PANE'
0:Repeats of vim-sync-incarg work in pane 1
>BUFFER: echo 2
>CURSOR: 5

  zpty_run 'TMUX_PANE=2'
  zletest $'echo 0\e0\C-f.'
  zpty_run 'unset TMUX_PANE'
0:Repeats of vim-sync-incarg work in pane 2
>BUFFER: echo 4
>CURSOR: 5

%clean

  zmodload -ui zsh/zpty