1" Tests for the sound feature 2 3if !has('sound') 4 throw 'Skipped: sound feature not available' 5endif 6 7func PlayCallback(id, result) 8 let g:id = a:id 9 let g:result = a:result 10endfunc 11 12func Test_play_event() 13 if has('win32') 14 throw 'Skipped: Playing event with callback is not supported on Windows' 15 endif 16 let id = 'bell'->sound_playevent('PlayCallback') 17 if id == 0 18 throw 'Skipped: bell event not available' 19 endif 20 " Stop it quickly, avoid annoying the user. 21 sleep 20m 22 eval id->sound_stop() 23 sleep 30m 24 call assert_equal(id, g:id) 25 call assert_equal(1, g:result) " sound was aborted 26endfunc 27 28func Test_play_silent() 29 let fname = fnamemodify('silent.wav', '%p') 30 31 " play without callback 32 let id1 = sound_playfile(fname) 33 if id1 == 0 34 throw 'Skipped: playing a sound is not working' 35 endif 36 37 " play until the end 38 let id2 = fname->sound_playfile('PlayCallback') 39 call assert_true(id2 > 0) 40 sleep 500m 41 call assert_equal(id2, g:id) 42 call assert_equal(0, g:result) 43 44 let id2 = sound_playfile(fname, 'PlayCallback') 45 call assert_true(id2 > 0) 46 sleep 20m 47 call sound_clear() 48 sleep 30m 49 call assert_equal(id2, g:id) 50 call assert_equal(1, g:result) 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 sleep 30m 63 call assert_true(g:id_again > 0) 64endfunc 65