xref: /vim-8.2.3635/src/testdir/test_sound.vim (revision 4c295027)
1" Tests for the sound feature
2
3source shared.vim
4
5if !has('sound')
6  throw 'Skipped: sound feature not available'
7endif
8
9func PlayCallback(id, result)
10  let g:id = a:id
11  let g:result = a:result
12endfunc
13
14func Test_play_event()
15  if has('win32')
16    throw 'Skipped: Playing event with callback is not supported on Windows'
17  endif
18  let g:id = 0
19  let id = 'bell'->sound_playevent('PlayCallback')
20  if id == 0
21    throw 'Skipped: bell event not available'
22  endif
23  " Stop it quickly, avoid annoying the user.
24  sleep 20m
25  eval id->sound_stop()
26  call WaitForAssert({-> assert_equal(id, g:id)})
27  call assert_equal(1, g:result)  " sound was aborted
28endfunc
29
30func Test_play_silent()
31  let fname = fnamemodify('silent.wav', '%p')
32
33  " play without callback
34  let id1 = sound_playfile(fname)
35  if id1 == 0
36    throw 'Skipped: playing a sound is not working'
37  endif
38
39  " play until the end
40  let id2 = fname->sound_playfile('PlayCallback')
41  call assert_true(id2 > 0)
42  call WaitForAssert({-> assert_equal(id2, g:id)})
43  call assert_equal(0, g:result)
44
45  let id2 = sound_playfile(fname, 'PlayCallback')
46  call assert_true(id2 > 0)
47  sleep 20m
48  call sound_clear()
49  call WaitForAssert({-> assert_equal(id2, g:id)})
50  call assert_equal(1, g:result)  " sound was aborted
51
52  " recursive use was causing a crash
53  func PlayAgain(id, fname)
54    let g:id = a:id
55    let g:id_again = sound_playfile(a:fname)
56  endfunc
57
58  let id3 = sound_playfile(fname, {id, res -> PlayAgain(id, fname)})
59  call assert_true(id3 > 0)
60  sleep 50m
61  call sound_clear()
62  call WaitForAssert({-> assert_true(g:id > 0)})
63endfunc
64
65" vim: shiftwidth=2 sts=2 expandtab
66