summaryrefslogtreecommitdiff
path: root/src/testdir/test87.in
blob: b1763edc72c784f5e24699338b9d77432f3c8733 (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
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
Tests for various python features.     vim: set ft=vim :

STARTTEST
:so small.vim
:if !has('python3') | e! test.ok | wq! test.out | endif
:lang C
:py3 import vim
:fun Test()
:let l = []
:py3 l=vim.bindeval('l')
:py3 f=vim.bindeval('function("strlen")')
:" Extending List directly with different types
:py3 l+=[1, "as'd", [1, 2, f, {'a': 1}]]
:$put =string(l)
:$put =string(l[-1])
:try
:  $put =string(l[-4])
:catch
:  $put =v:exception[:13]
:endtry
:" List assignment
:py3 l[0]=0
:$put =string(l)
:py3 l[-2]=f
:$put =string(l)
:"
:" Extending Dictionary directly with different types
:let d = {}
:py3 d=vim.bindeval('d')
:py3 d['1']='asd'
:py3 d['b']=[1, 2, f]
:py3 d['-1']={'a': 1}
:let dkeys = []
:py3 dk=vim.bindeval('dkeys')
:py3 dkeys=d.keys()
:py3 dkeys.sort()
:py3 dk+=dkeys
:$put =string(dkeys)
:for [key, val] in sort(items(d))
:  $put =string(key) . ' : ' . string(val)
:  unlet key val
:endfor
:"
:" removing items with del
:py3 del l[2]
:$put =string(l)
:let l = range(8)
:py3 l=vim.bindeval('l')
:try
:   py3 del l[:3]
:   py3 del l[1:]
:catch
:   $put =v:exception
:endtry
:$put =string(l)
:"
:py3 del d['-1']
:$put =string(d)
:"
:" removing items out of range: silently skip items that don't exist
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:" The following two ranges delete nothing as they match empty list:
:py3 del l[2:1]
:$put =string(l)
:py3 del l[2:2]
:$put =string(l)
:py3 del l[2:3]
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 del l[2:4]
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 del l[2:5]
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 del l[2:6]
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:" The following two ranges delete nothing as they match empty list:
:py3 del l[-1:2]
:$put =string(l)
:py3 del l[-2:2]
:$put =string(l)
:py3 del l[-3:2]
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 del l[-4:2]
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 del l[-5:2]
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 del l[-6:2]
:$put =string(l)
:"
:" Slice assignment to a list
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 l[0:0]=['a']
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 l[1:2]=['b']
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 l[2:4]=['c']
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 l[4:4]=['d']
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 l[-1:2]=['e']
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 l[-10:2]=['f']
:$put =string(l)
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:py3 l[2:-10]=['g']
:$put =string(l)
:let l = []
:py3 l=vim.bindeval('l')
:py3 l[0:0]=['h']
:$put =string(l)
:"
:" Locked variables
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:lockvar! l
:py3 l[2]='i'
:$put =string(l)
:unlockvar! l
:"
:" Function calls
:function New(...)
:return ['NewStart']+a:000+['NewEnd']
:endfunction
:function DictNew(...) dict
:return ['DictNewStart']+a:000+['DictNewEnd', self]
:endfunction
:let l=[function('New'), function('DictNew')]
:py3 l=vim.bindeval('l')
:py3 l.extend(list(l[0](1, 2, 3)))
:$put =string(l)
:py3 l.extend(list(l[1](1, 2, 3, self={'a': 'b'})))
:$put =string(l)
:py3 l+=[l[0].name]
:$put =string(l)
:try
:   py3 l[1](1, 2, 3)
:catch
:   $put =v:exception[:13]
:endtry
:delfunction New
:try
:   py3 l[0](1, 2, 3)
:catch
:   $put =v:exception[:13]
:endtry
:if has('float')
:   let l=[0.0]
:   py3 l=vim.bindeval('l')
:   py3 l.extend([0.0])
:   $put =string(l)
:else
:   $put ='[0.0, 0.0]'
:endif
:let messages=[]
:py3 <<EOF
d=vim.bindeval('{}')
m=vim.bindeval('messages')
try:
    d['abc']
except Exception as e:
    m.extend([e.__class__.__name__])

try:
    d['abc']="\0"
except Exception as e:
    m.extend([e.__class__.__name__])

try:
    d['abc']=vim
except Exception as e:
    m.extend([e.__class__.__name__])

try:
    d['']=1
except Exception as e:
    m.extend([e.__class__.__name__])

try:
    d['a\0b']=1
except Exception as e:
    m.extend([e.__class__.__name__])

try:
    d[b'a\0b']=1
except Exception as e:
    m.extend([e.__class__.__name__])
EOF
:$put =messages
:unlet messages
:" locked and scope attributes
:let d={} | let dl={} | lockvar dl
:for s in split("d dl v: g:")
:    let name=tr(s, ':', 's')
:    execute 'py3 '.name.'=vim.bindeval("'.s.'")'
:    let toput=s.' : '.join(map(['locked', 'scope'], 'v:val.":".py3eval(name.".".v:val)'), ';')
:    $put =toput
:endfor
:silent! let d.abc=1
:silent! let dl.abc=1
:py3 d.locked=True
:py3 dl.locked=False
:silent! let d.def=1
:silent! let dl.def=1
:put ='d:'.string(d)
:put ='dl:'.string(dl)
:unlet d dl
:
:let l=[] | let ll=[] | lockvar ll
:for s in split("l ll")
:    let name=tr(s, ':', 's')
:    execute 'py3 '.name.'=vim.bindeval("'.s.'")'
:    let toput=s.' : locked:'.py3eval(name.'.locked')
:    $put =toput
:endfor
:silent! call extend(l, [0])
:silent! call extend(ll, [0])
:py3 l.locked=True
:py3 ll.locked=False
:silent! call extend(l, [1])
:silent! call extend(ll, [1])
:put ='l:'.string(l)
:put ='ll:'.string(ll)
:unlet l ll
:"
:" py3eval()
:let l=py3eval('[0, 1, 2]')
:$put =string(l)
:let d=py3eval('{"a": "b", "c": 1, "d": ["e"]}')
:$put =sort(items(d))
:if has('float')
:   let f=py3eval('0.0')
:   $put =string(f)
:else
:   $put ='0.0'
:endif
:" Invalid values:
:for e in ['"\0"', '{"\0": 1}', 'undefined_name', 'vim']
:   try
:      let v=py3eval(e)
:   catch
:      let toput=e.":\t".v:exception[:13]
:      $put =toput
:   endtry
:endfor
:"
:" threading
:let l = [0]
:py3 l=vim.bindeval('l')
:py3 <<EOF
import threading
import time

class T(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.t = 0
        self.running = True

    def run(self):
        while self.running:
            self.t += 1
            time.sleep(0.1)

t = T()
t.start()
EOF
:sleep 1
:py3 t.running = False
:py3 t.join()
:py3 l[0] = t.t > 8  # check if the background thread is working
:$put =string(l)
:"
:" settrace
:let l = []
:py3 l=vim.bindeval('l')
:py3 <<EOF
import sys

def traceit(frame, event, arg):
    global l
    if event == "line":
        l += [frame.f_lineno]
    return traceit

def trace_main():
    for i in range(5):
        pass
EOF
:py3 sys.settrace(traceit)
:py3 trace_main()
:py3 sys.settrace(None)
:$put =string(l)
:"
:" Vars
:let g:foo = 'bac'
:let w:abc = 'def'
:let b:baz = 'bar'
:let t:bar = 'jkl'
:try
:  throw "Abc"
:catch
:  put =py3eval('vim.vvars[''exception'']')
:endtry
:put =py3eval('vim.vars[''foo'']')
:put =py3eval('vim.current.window.vars[''abc'']')
:put =py3eval('vim.current.buffer.vars[''baz'']')
:put =py3eval('vim.current.tabpage.vars[''bar'']')
:"
:" Options
:" paste:          boolean, global
:" previewheight   number,  global
:" operatorfunc:   string,  global
:" number:         boolean, window-local
:" numberwidth:    number,  window-local
:" colorcolumn:    string,  window-local
:" statusline:     string,  window-local/global
:" autoindent:     boolean, buffer-local
:" shiftwidth:     number,  buffer-local
:" omnifunc:       string,  buffer-local
:" preserveindent: boolean, buffer-local/global
:" path:           string,  buffer-local/global
:let g:bufs=[bufnr('%')]
:new
:let g:bufs+=[bufnr('%')]
:vnew
:let g:bufs+=[bufnr('%')]
:wincmd j
:vnew
:let g:bufs+=[bufnr('%')]
:wincmd l
:fun RecVars(opt)
:  let gval =string(eval('&g:'.a:opt))
:  let wvals=join(map(range(1, 4),  'v:val.":".string(getwinvar(v:val, "&".a:opt))'))
:  let bvals=join(map(copy(g:bufs), 'v:val.":".string(getbufvar(v:val, "&".a:opt))'))
:  put ='  G: '.gval
:  put ='  W: '.wvals
:  put ='  B: '.wvals
:endfun
py3 << EOF
def e(s, g=globals(), l=locals()):
    try:
        exec(s, g, l)
    except Exception as e:
        vim.command('return ' + repr(e.__class__.__name__))

def ev(s, g=globals(), l=locals()):
    try:
        return eval(s, g, l)
    except Exception as e:
        vim.command('let exc=' + repr(e.__class__.__name__))
        return 0
EOF
:function E(s)
:   python3 e(vim.eval('a:s'))
:endfunction
:function Ev(s)
:   let r=py3eval('ev(vim.eval("a:s"))')
:   if exists('exc')
:       throw exc
:   endif
:   return r
:endfunction
:py3 gopts1=vim.options
:py3 wopts1=vim.windows[2].options
:py3 wopts2=vim.windows[0].options
:py3 wopts3=vim.windows[1].options
:py3 bopts1=vim.buffers[vim.bindeval("g:bufs")[2]].options
:py3 bopts2=vim.buffers[vim.bindeval("g:bufs")[1]].options
:py3 bopts3=vim.buffers[vim.bindeval("g:bufs")[0]].options
:let lst=[]
:let lst+=[['paste',          1,     0,     1,     2,      1,    1,      0    ]]
:let lst+=[['previewheight',  5,     1,     6,     'a',    0,    1,      0    ]]
:let lst+=[['operatorfunc',   'A',   'B',   'C',   2,      0,    1,      0    ]]
:let lst+=[['number',         0,     1,     1,     0,      1,    0,      1    ]]
:let lst+=[['numberwidth',    2,     3,     5,     -100,   0,    0,      1    ]]
:let lst+=[['colorcolumn',    '+1',  '+2',  '+3',  'abc',  0,    0,      1    ]]
:let lst+=[['statusline',     '1',   '2',   '4',   0,      0,    1,      1    ]]
:let lst+=[['autoindent',     0,     1,     1,     2,      1,    0,      2    ]]
:let lst+=[['shiftwidth',     0,     2,     1,     3,      0,    0,      2    ]]
:let lst+=[['omnifunc',       'A',   'B',   'C',   1,      0,    0,      2    ]]
:let lst+=[['preserveindent', 0,     1,     1,     2,      1,    1,      2    ]]
:let lst+=[['path',           '.,,', ',,',  '.',   0,      0,    1,      2    ]]
:for       [oname,            oval1, oval2, oval3, invval, bool, global, local] in lst
:   py3 oname=vim.eval('oname')
:   py3 oval1=vim.bindeval('oval1')
:   py3 oval2=vim.bindeval('oval2')
:   py3 oval3=vim.bindeval('oval3')
:   if invval is 0 || invval is 1
:       py3 invval=bool(vim.bindeval('invval'))
:   else
:       py3 invval=vim.bindeval('invval')
:   endif
:   if bool
:       py3 oval1=bool(oval1)
:       py3 oval2=bool(oval2)
:       py3 oval3=bool(oval3)
:   endif
:   put ='>>> '.oname
:   for v in ['gopts1', 'wopts1', 'bopts1']
:       try
:           put ='  p/'.v.': '.Ev('repr('.v.'['''.oname.'''])')
:       catch
:           put ='  p/'.v.'! '.v:exception
:       endtry
:       let r=E(v.'['''.oname.''']=invval')
:       if r isnot 0
:           put ='  inv: '.string(invval).'! '.r
:       endif
:       for vv in (v is# 'gopts1' ? [v] : [v, v[:-2].'2', v[:-2].'3'])
:           let val=substitute(vv, '^.opts', 'oval', '')
:           let r=E(vv.'['''.oname.''']='.val)
:           if r isnot 0
:               put ='  '.vv.'! '.r
:           endif
:       endfor
:   endfor
:   call RecVars(oname)
:   for v in ['wopts3', 'bopts3']
:       let r=E('del '.v.'["'.oname.'"]')
:       if r isnot 0
:           put ='  del '.v.'! '.r
:       endif
:   endfor
:   call RecVars(oname)
:endfor
:only
:for buf in g:bufs[1:]
:   execute 'bwipeout!' buf
:endfor
:"
:" Test buffer object
:vnew
:put ='First line'
:put ='Second line'
:put ='Third line'
:1 delete _
:py3 b=vim.current.buffer
:wincmd w
:mark a
:augroup BUFS
:   autocmd BufFilePost * python3 cb.append(vim.eval('expand("<abuf>")') + ':BufFilePost:' + vim.eval('bufnr("%")'))
:   autocmd BufFilePre * python3 cb.append(vim.eval('expand("<abuf>")') + ':BufFilePre:' + vim.eval('bufnr("%")'))
:augroup END
py3 << EOF
cb = vim.current.buffer
# Tests BufferAppend and BufferItem
cb.append(b[0])
# Tests BufferSlice and BufferAssSlice
cb.append('abc') # Will be overwritten
cb[-1:] = b[:-2]
# Test BufferLength and BufferAssSlice
cb.append('def') # Will not be overwritten
cb[len(cb):] = b[:]
# Test BufferAssItem and BufferMark
cb.append('ghi') # Will be overwritten
cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
# Test BufferRepr
cb.append(repr(cb) + repr(b))
# Modify foreign buffer
b.append('foo')
b[0]='bar'
b[0:0]=['baz']
vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
# Test assigning to name property
old_name = cb.name
cb.name = 'foo'
cb.append(cb.name[-11:])
b.name = 'bar'
cb.append(b.name[-11:])
cb.name = old_name
cb.append(cb.name[-17:])
# Test CheckBuffer
for _b in vim.buffers:
    if _b is not cb:
        vim.command('bwipeout! ' + str(_b.number))
del _b
cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
    try:
        exec(expr)
    except vim.error:
        pass
    else:
        # Usually a SEGV here
        # Should not happen in any case
        cb.append('No exception for ' + expr)
vim.command('cd .')
EOF
:"
:" Test vim.buffers object
:set hidden
:edit a
:buffer #
:edit b
:buffer #
:edit c
:buffer #
py3 << EOF
# Check GCing iterator that was not fully exhausted
i = iter(vim.buffers)
cb.append('i:' + str(next(i)))
# and also check creating more then one iterator at a time
i2 = iter(vim.buffers)
cb.append('i2:' + str(next(i2)))
cb.append('i:' + str(next(i)))
# The following should trigger GC and not cause any problems
del i
del i2
i3 = iter(vim.buffers)
cb.append('i3:' + str(next(i3)))
del i3

prevnum = 0
for b in vim.buffers:
    # Check buffer order
    if prevnum >= b.number:
        cb.append('!!! Buffer numbers not in strictly ascending order')
    # Check indexing: vim.buffers[number].number == number
    cb.append(str(b.number) + ':' + repr(vim.buffers[b.number]) + '=' + repr(b))
    prevnum = b.number

cb.append(str(len(vim.buffers)))

bnums = list(map(lambda b: b.number, vim.buffers))[1:]

# Test wiping out buffer with existing iterator
i4 = iter(vim.buffers)
cb.append('i4:' + str(next(i4)))
vim.command('bwipeout! ' + str(bnums.pop(0)))
try:
    next(i4)
except vim.error:
    pass
else:
    cb.append('!!!! No vim.error')
i4 = iter(vim.buffers)
vim.command('bwipeout! ' + str(bnums.pop(-1)))
vim.command('bwipeout! ' + str(bnums.pop(-1)))
cb.append('i4:' + str(next(i4)))
try:
    next(i4)
except StopIteration:
    cb.append('StopIteration')
EOF
:"
:" Test vim.{tabpage,window}list and vim.{tabpage,window} objects
:tabnew 0
:tabnew 1
:vnew a.1
:tabnew 2
:vnew a.2
:vnew b.2
:vnew c.2
py3 << EOF
cb.append('Number of tabs: ' + str(len(vim.tabpages)))
cb.append('Current tab pages:')

def W(w):
    if '(unknown)' in repr(w):
        return '<window object (unknown)>'
    else:
        return repr(w)

def Cursor(w, start=len(cb)):
    if w.buffer is cb:
        return repr((start - w.cursor[0], w.cursor[1]))
    else:
        return repr(w.cursor)

for t in vim.tabpages:
    cb.append('  ' + repr(t) + '(' + str(t.number) + ')' + ': ' + str(len(t.windows)) + ' windows, current is ' + W(t.window))
    cb.append('  Windows:')
    for w in t.windows:
        cb.append('    ' + W(w) + '(' + str(w.number) + ')' + ': displays buffer ' + repr(w.buffer) + '; cursor is at ' + Cursor(w))
        # Other values depend on the size of the terminal, so they are checked partly:
        for attr in ('height', 'row', 'width', 'col'):
            try:
                aval = getattr(w, attr)
                if type(aval) is not int:
                    raise TypeError
                if aval < 0:
                    raise ValueError
            except Exception as e:
                cb.append('!!!!!! Error while getting attribute ' + attr + ': ' + e.__class__.__name__)
        w.cursor = (len(w.buffer), 0)
cb.append('Number of windows in current tab page: ' + str(len(vim.windows)))
if list(vim.windows) != list(vim.current.tabpage.windows):
    cb.append('!!!!!! Windows differ')
EOF
:"
:" Test vim.current
py3 << EOF
def H(o):
    return repr(o)
cb.append('Current tab page: ' + repr(vim.current.tabpage))
cb.append('Current window: ' + repr(vim.current.window) + ': ' + H(vim.current.window) + ' is ' + H(vim.current.tabpage.window))
cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ ' is ' + H(vim.current.tabpage.window.buffer))
# Assigning: fails
try:
    vim.current.window = vim.tabpages[0].window
except ValueError:
    cb.append('ValueError at assigning foreign tab window')

for attr in ('window', 'tabpage', 'buffer'):
    try:
        setattr(vim.current, attr, None)
    except TypeError:
        cb.append('Type error at assigning None to vim.current.' + attr)

# Assigning: success
vim.current.tabpage = vim.tabpages[-2]
vim.current.buffer = cb
vim.current.window = vim.windows[0]
vim.current.window.cursor = (len(vim.current.buffer), 0)
cb.append('Current tab page: ' + repr(vim.current.tabpage))
cb.append('Current window: ' + repr(vim.current.window))
cb.append('Current buffer: ' + repr(vim.current.buffer))
cb.append('Current line: ' + repr(vim.current.line))
ws = list(vim.windows)
ts = list(vim.tabpages)
for b in vim.buffers:
    if b is not cb:
        vim.command('bwipeout! ' + str(b.number))
cb.append('w.valid: ' + repr([w.valid for w in ws]))
cb.append('t.valid: ' + repr([t.valid for t in ts]))
EOF
:tabonly!
:only!
:"
:" Test types
py3 << EOF
for expr, attr in (
    ('vim.vars',                         'Dictionary'),
    ('vim.options',                      'Options'),
    ('vim.bindeval("{}")',               'Dictionary'),
    ('vim.bindeval("[]")',               'List'),
    ('vim.bindeval("function(\'tr\')")', 'Function'),
    ('vim.current.buffer',               'Buffer'),
    ('vim.current.range',                'Range'),
    ('vim.current.window',               'Window'),
    ('vim.current.tabpage',              'TabPage'),
):
    cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr)))
EOF
:"
:" Test __dir__() method
py3 << EOF
for name, o in (
        ('current',    vim.current),
        ('buffer',     vim.current.buffer),
        ('window',     vim.current.window),
        ('tabpage',    vim.current.tabpage),
        ('range',      vim.current.range),
        ('dictionary', vim.bindeval('{}')),
        ('list',       vim.bindeval('[]')),
        ('function',   vim.bindeval('function("tr")')),
        ('output',     sys.stdout),
    ):
    cb.append(name + ':' + ','.join(dir(o)))
del name
del o
EOF
:"
:"
:" Test stdout/stderr
:redir => messages
:py sys.stdout.write('abc') ; sys.stdout.write('def')
:py sys.stderr.write('abc') ; sys.stderr.write('def')
:py sys.stdout.writelines(iter('abc'))
:py sys.stderr.writelines(iter('abc'))
:redir END
:$put =string(substitute(messages, '\d\+', '', 'g'))
:"
:" Test exceptions
:fun Exe(e)
:   execute a:e
:endfun
py3 << EOF
def ee(expr, g=globals(), l=locals()):
    try:
        exec(expr, g, l)
    except Exception as e:
        cb.append(repr((e.__class__, e)))
Exe = vim.bindeval('function("Exe")')
ee('vim.command("throw \'abc\'")')
ee('Exe("throw \'def\'")')
ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")')
ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")')
ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")')
ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")')
EOF
:endfun
:"
:call Test()
:"
:delfunc Test
:call garbagecollect(1)
:"
:/^start:/,$wq! test.out
:call getchar()
ENDTEST

start: