1 Star 0 Fork 0

dglxlcl/vimspector

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
variables_compact.test.vim 32.59 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
let s:fn='../support/test/python/simple_python/main.py'
function! SetUp()
call vimspector#test#setup#SetUpWithMappings( 'HUMAN' )
let g:vimspector_variables_display_mode = 'compact'
let s:setup_func_line = FunctionBreakOnBrace() ? 17 : 18
endfunction
function! TearDown()
call vimspector#test#setup#TearDown()
endfunction
function! ConsoleBufferName()
let session_id = py3eval( '_vimspector_session.session_id' )
return 'vimspector.Console[' .. session_id .. ']'
endfunction
function! s:StartDebugging( ... )
if a:0 == 0
let config = #{
\ fn: s:fn,
\ line: 23,
\ col: 1,
\ launch: #{ configuration: 'run' }
\ }
else
let config = a:1
endif
execute 'edit' config.fn
call setpos( '.', [ 0, config.line, config.col ] )
call vimspector#ToggleBreakpoint()
call vimspector#LaunchWithSettings( config.launch )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer(
\ config.fn,
\ config.line,
\ config.col )
endfunction
function! Test_SimpleWatches()
call s:StartDebugging()
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 )
" Add a wtch
call vimspector#AddWatch( 't' )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 26, 1 )
" Delete a watch expression
call win_gotoid( g:vimspector_session_windows.watches )
call setpos( '.', [ 0, 3, 1 ] )
call feedkeys( "\<Del>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call assert_equal( 'python',
\ getbufvar(
\ winbufnr( g:vimspector_session_windows.watches ),
\ '&syntax' ) )
call vimspector#StepInto()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 13, 1 )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 14, 1 )
call vimspector#AddWatch( 'i' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: i',
\ ' *- Result: 0',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#AddWatch( 'i+1' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: i',
\ ' - Result: 0',
\ 'Expression: i+1',
\ ' *- Result: 1',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#AddWatch( 'i+2' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: i',
\ ' - Result: 0',
\ 'Expression: i+1',
\ ' - Result: 1',
\ 'Expression: i+2',
\ ' *- Result: 2',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
" Delete that middle watch
call win_gotoid( g:vimspector_session_windows.watches )
call setpos( '.', [ 0, 4, 1 ] )
call vimspector#DeleteWatch()
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: i',
\ ' - Result: 0',
\ 'Expression: i+2',
\ ' *- Result: 2',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 15, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: i',
\ ' - Result: 0',
\ 'Expression: i+2',
\ ' - Result: 2',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
" Delete the top watch
call win_gotoid( g:vimspector_session_windows.watches )
call setpos( '.', [ 0, 3, 1 ] )
call vimspector#DeleteWatch()
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 13, 1 )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 14, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: i+2',
\ ' *- Result: 3',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_ExpandVariables()
call SkipNeovim()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '- Scope: Locals',
\ ' *+ t: {...}',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
call assert_equal( 'cpp',
\ getbufvar(
\ winbufnr( g:vimspector_session_windows.variables ),
\ '&syntax' ) )
" Expand
call win_gotoid( g:vimspector_session_windows.variables )
call setpos( '.', [ 0, 2, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '- Scope: Locals',
\ ' \*- t: {...}',
\ ' \*- i: 0',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
" Step - stays expanded
call vimspector#StepOver()
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '- Scope: Locals',
\ ' - t: {...}',
\ ' \*- i: 1',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' + another_test:\( {...}\)\?',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
" Collapse
call win_gotoid( g:vimspector_session_windows.variables )
call setpos( '.', [ 0, 2, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '- Scope: Locals',
\ ' + t: {...}',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 28, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '- Scope: Locals',
\ ' + t: {...}',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
call win_gotoid( g:vimspector_session_windows.variables )
call setpos( '.', [ 0, 2, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '- Scope: Locals',
\ ' - t: {...}',
\ ' \*- i: 1',
\ ' \*- c: 99 ''c''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
" Collapse the 'inexpensive' scope and see that it stays collapsed
" Exapand - see that the changed value is highlighted
call win_gotoid( g:vimspector_session_windows.variables )
call setpos( '.', [ 0, 1, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '+ Scope: Locals',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
" Stays collapsed through step
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 30, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '+ Scope: Locals',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
" Cpptools keeps the same "Locals" scope, so it stays collapsed even through
" step-in
call vimspector#StepInto()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, s:setup_func_line, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '+ Scope: Locals',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_ExpandWatch()
call SkipNeovim()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call win_gotoid( g:vimspector_session_windows.watches )
call feedkeys( "it\<CR>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' *+ Result: {...}',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call assert_equal( 'cpp',
\ getbufvar(
\ winbufnr( g:vimspector_session_windows.watches ),
\ '&syntax' ) )
" Expand
call win_gotoid( g:vimspector_session_windows.watches )
call setpos( '.', [ 0, 3, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' \*- Result: {...}',
\ ' \*- i: 0',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
" Step - stays expanded
call vimspector#StepOver()
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' - Result: {...}',
\ ' \*- i: 1',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' + another_test:\( {...}\)\?',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
" Collapse
call win_gotoid( g:vimspector_session_windows.watches )
call setpos( '.', [ 0, 3, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' + Result: {...}',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 28, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' + Result: {...}',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call win_gotoid( g:vimspector_session_windows.watches )
call setpos( '.', [ 0, 3, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' - Result: {...}',
\ ' - i: 1',
\ ' - c: 99 ''c''',
\ ' - fffff: 0',
\ ' + another_test:\( {...}\)\?',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function Test_EvaluateConsole()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 27, 1 )
VimspectorEval t.i
call assert_equal( bufnr( ConsoleBufferName() ),
\ winbufnr( g:vimspector_session_windows.output ) )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '1'
\ ],
\ getbufline( bufnr( ConsoleBufferName() ), '$', '$' )
\ )
\ } )
let len = getbufinfo( ConsoleBufferName() )[ 0 ].linecount
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Evaluating: t.i',
\ '1'
\ ],
\ getbufline( bufnr( ConsoleBufferName() ), len-1, '$' )
\ )
\ } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer(
\ ConsoleBufferName(), len, v:null )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function Test_EvaluateInput()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 27, 1 )
VimspectorEval (int) printf("hello")
call assert_equal( bufnr( ConsoleBufferName() ),
\ winbufnr( g:vimspector_session_windows.output ) )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Evaluating: (int) printf("hello")',
\ '5'
\ ],
\ GetBufLine( bufnr( ConsoleBufferName() ), -1 )
\ )
\ } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer(
\ ConsoleBufferName(),
\ getbufinfo( ConsoleBufferName() )[ 0 ].linecount,
\ v:null )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function Test_EvaluatePromptConsole()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 27, 1 )
VimspectorShowOutput
call assert_equal( bufnr( ConsoleBufferName() ),
\ winbufnr( g:vimspector_session_windows.output ) )
call feedkeys( "it.i\<CR>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '1'
\ ],
\ getbufline( bufnr( ConsoleBufferName() ), '$', '$' )
\ )
\ } )
let len = getbufinfo( ConsoleBufferName() )[ 0 ].linecount
call WaitForAssert( {->
\ assert_equal(
\ [
\ '> t.i',
\ '',
\ '1'
\ ],
\ getbufline( bufnr( ConsoleBufferName() ), len-2, '$' )
\ )
\ } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer(
\ ConsoleBufferName(), len, v:null )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_EvaluateFailure()
call s:StartDebugging()
" Add a wtch
call vimspector#AddWatch( 'test' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Watches: ----',
\ 'Expression: test',
\ " *- Result: NameError: name 'test' is not defined",
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
VimspectorEval test
call assert_equal( bufnr( ConsoleBufferName() ),
\ winbufnr( g:vimspector_session_windows.output ) )
call WaitForAssert( {->
\ assert_equal(
\ [
\ "NameError: name 'test' is not defined"
\ ],
\ getbufline( bufnr( ConsoleBufferName() ), '$', '$' )
\ )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_VariableEval()
call SkipNeovim()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
" leader is ,
xmap <buffer> <Leader>d <Plug>VimspectorBalloonEval
nmap <buffer> <Leader>d <Plug>VimspectorBalloonEval
"evaluate the prev line
call setpos( '.', [ 0, 24, 8 ] )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 24, 8 )
call feedkeys( ',d', 'xt' )
call WaitForAssert( {->
\ AssertNotNull( g:vimspector_session_windows.eval )
\ } )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '{...}',
\ ' - i: 0',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' + another_test: ',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
"Close
call feedkeys( "\<Esc>", 'xt' )
call WaitForAssert( {->
\ AssertNull( g:vimspector_session_windows.eval )
\ } )
" test selection
call setpos( '.', [ 0, 24, 8 ] )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 24, 8 )
call feedkeys( 'viw,d', 'xt' )
call WaitForAssert( {->
\ AssertNotNull( g:vimspector_session_windows.eval )
\ } )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '{...}',
\ ' - i: 0',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' + another_test: ',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
"Close
call feedkeys( "\<Esc>", 'xt' )
call WaitForAssert( {->
\ AssertNull( g:vimspector_session_windows.eval )
\ } )
" Get back to normal mode
call feedkeys( "\<Esc>", 'xt' )
" Evaluation error
call setpos( '.', [ 0, 25, 1 ] )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 25, 1 )
call feedkeys( ',d', 'xt' )
call WaitForAssert( {->
\ AssertNotNull( g:vimspector_session_windows.eval )
\ } )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Evaluation error',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
"Close
call feedkeys( "\<Esc>", 'xt' )
call WaitForAssert( {->
\ AssertNull( g:vimspector_session_windows.eval )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_VariableEvalExpand()
call SkipNeovim()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
" leader is ,
xmap <buffer> <Leader>d <Plug>VimspectorBalloonEval
nmap <buffer> <Leader>d <Plug>VimspectorBalloonEval
"evaluate the prev line
call setpos( '.', [ 0, 24, 8 ] )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 24, 8 )
call feedkeys( ',d', 'xt' )
call WaitForAssert( {->
\ AssertNotNull( g:vimspector_session_windows.eval )
\ } )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '{...}',
\ ' - i: 0',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' + another_test: ',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
" Expand
call feedkeys( "jjjj\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '{...}',
\ ' - i: 0',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' - another_test: ',
\ ' - choo: 0 ''\\0\{1,3}''',
\ ' + ints: '
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
"Collapse
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '{...}',
\ ' - i: 0',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' + another_test: ',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
"Close
call feedkeys( "\<Esc>", 'xt' )
call WaitForAssert( {->
\ AssertNull( g:vimspector_session_windows.eval )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_SetVariableValue_Local()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call WaitForAssert( {->
\ assert_equal(
\ [
\ '- Scope: Locals',
\ ' *+ t: {...}',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
call assert_equal( 'cpp',
\ getbufvar(
\ winbufnr( g:vimspector_session_windows.variables ),
\ '&syntax' ) )
" Expand
call win_gotoid( g:vimspector_session_windows.variables )
call setpos( '.', [ 0, 2, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '- Scope: Locals',
\ ' \*- t: {...}',
\ ' \*- i: 0',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
call setpos( '.', [ 0, 3, 1 ] )
" We can't just fire the keys to the inpit prompt because we use inputsave()
" and inputrestore(), so mock that out and fire away.
py3 <<EOF
from unittest import mock
with mock.patch( 'vimspector.utils.InputSave' ):
vim.eval( 'feedkeys( "\<C-CR>\<C-u>100\<CR>", "xt" )' )
EOF
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '- Scope: Locals',
\ ' \*- t: {...}',
\ ' \*- i: 100',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
" Now set it via the more comforable scripting interface
call vimspector#SetVariableValue( '1234' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '- Scope: Locals',
\ ' \*- t: {...}',
\ ' \*- i: 1234',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
" Something fails
call vimspector#SetVariableValue( 'this is invalid' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '- Scope: Locals',
\ ' \*- t: {...}',
\ ' \*- i: 1234',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ '+ Scope: Registers',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.variables ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_SetVariableValue_Watch()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
" Make sure the Test t is initialised
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call win_gotoid( g:vimspector_session_windows.watches )
call feedkeys( "it\<CR>", 'xt' )
call WaitForAssert( {->
\ assert_equal(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' *+ Result: {...}',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call assert_equal( 'cpp',
\ getbufvar(
\ winbufnr( g:vimspector_session_windows.watches ),
\ '&syntax' ) )
" Expand
call win_gotoid( g:vimspector_session_windows.watches )
call setpos( '.', [ 0, 3, 1 ] )
call feedkeys( "\<CR>", 'xt' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' \*- Result: {...}',
\ ' \*- i: 0',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call setpos( '.', [ 0, 4, 1 ] )
" We can't just fire the keys to the inpit prompt because we use inputsave()
" and inputrestore(), so mock that out and fire away.
" Note: mapleder is ,
py3 <<EOF
from unittest import mock
with mock.patch( 'vimspector.utils.InputSave' ):
vim.eval( 'feedkeys( ",\<CR>\<C-u>100\<CR>", "xt" )' )
EOF
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' \*- Result: {...}',
\ ' \*- i: 100',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
" Now set it via the more comforable scripting interface
call vimspector#SetVariableValue( '1234' )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ 'Watches: ----',
\ 'Expression: t',
\ ' \*- Result: {...}',
\ ' \*- i: 1234',
\ ' \*- c: 0 ''\\0\{1,3}''',
\ ' \*- fffff: 0',
\ ' \*+ another_test:\( {...}\)\?',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.watches ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_SetVariableValue_Balloon()
call SkipNeovim()
let fn = 'testdata/cpp/simple/struct.cpp'
call s:StartDebugging( #{ fn: fn, line: 24, col: 1, launch: #{
\ configuration: 'run-to-breakpoint'
\ } } )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
" leader is ,
xmap <buffer> <Leader>d <Plug>VimspectorBalloonEval
nmap <buffer> <Leader>d <Plug>VimspectorBalloonEval
"evaluate the prev line
call setpos( '.', [ 0, 24, 8 ] )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 24, 8 )
call feedkeys( ',d', 'xt' )
call WaitForAssert( {->
\ AssertNotNull( g:vimspector_session_windows.eval )
\ } )
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '{...}',
\ ' - i: 0',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 0',
\ ' + another_test: ',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
" Move down to the ffff line
call feedkeys( 'jjj', 'xt' )
" We can't just fire the keys to the inpit prompt because we use inputsave()
" and inputrestore(), so mock that out and fire away.
" Note: mapleder is ,
py3 <<EOF
from unittest import mock
with mock.patch( 'vimspector.utils.InputSave' ):
vim.eval( 'feedkeys( "\<C-CR>\<C-u>100\<CR>", "xt" )' )
EOF
call WaitForAssert( {->
\ AssertMatchList(
\ [
\ '{...}',
\ ' - i: 0',
\ ' - c: 0 ''\\0\{1,3}''',
\ ' - fffff: 100',
\ ' + another_test: ',
\ ],
\ getbufline( winbufnr( g:vimspector_session_windows.eval ),
\ 1,
\ '$' )
\ )
\ } )
call vimspector#test#setup#Reset()
%bwipe!
endfunction
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dglxlcl/vimspector.git
git@gitee.com:dglxlcl/vimspector.git
dglxlcl
vimspector
vimspector
master

搜索帮助