Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ubaldot committed Nov 9, 2024
1 parent 22d4fd1 commit 80ee271
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 76 deletions.
1 change: 1 addition & 0 deletions ftplugin/julia.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ if g:replica_enable_highlight
endif

# # Why <buffer>? Read here: https://vi.stackexchange.com/questions/8056/for-an-autocmd-in-a-ftplugin-should-i-use-pattern-matching-or-buffer
ftcommands_mappings.FtCommandsMappings()
2 changes: 2 additions & 0 deletions ftplugin/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ endif

# # Why <buffer>? Read here:
# https://vi.stackexchange.com/questions/8056/for-an-autocmd-in-a-ftplugin-should-i-use-pattern-matching-or-buffer
#
ftcommands_mappings.FtCommandsMappings()
136 changes: 69 additions & 67 deletions lib/ftcommands_mappings.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,77 @@ import autoload "../lib/repl.vim"
# Mappings
# ------------
# TODO: make imap and tmap to work.
noremap <unique> <script> <Plug>ReplicaConsoleToggle
\ <ScriptCmd>repl.ConsoleToggle()<cr>
tnoremap <unique> <script> <Plug>ReplicaConsoleToggle
\ <ScriptCmd>repl.ConsoleToggle()<cr>
noremap <unique> <script> <Plug>ReplicaSendLines
\ <ScriptCmd>repl.SendLines(line('.'), line('.'))<cr>
noremap <unique> <script> <Plug>ReplicaSendFile
\ <ScriptCmd>repl.SendFile()<cr>
noremap <unique> <script> <Plug>ReplicaSendCell
\ <ScriptCmd>repl.SendCell()<cr>
if g:replica_use_default_mapping == true
if !hasmapto('<Plug>ReplicaConsoleToggle') || empty(mapcheck("<F2>", "nt"))
nnoremap <silent> <F2> <Plug>ReplicaConsoleToggle
# imap <silent> <F2> <Plug>ReplicaConsoleToggle<cr>
tnoremap <F2> <silent> <c-w><Plug>ReplicaConsoleToggle
endif

if !hasmapto('<Plug>ReplicaSendLines') || empty(mapcheck("<F9>", "nx"))
nnoremap <silent> <unique> <F9> <Plug>ReplicaSendLines
# imap <silent> <unique> <F9> <Plug>ReplicaSendLines<cr>
xnoremap <silent> <unique> <F9> :ReplicaSendLines<cr>j
endif

if !hasmapto('<Plug>ReplicaSendFile') || empty(mapcheck("<F5>", "n"))
nnoremap <silent> <F5> <Plug>ReplicaSendFile
# imap <silent> <F5> <Plug>ReplicaSendFile<cr>
endif

if !hasmapto('<Plug>ReplicaSendCell') || empty(mapcheck("<c-enter>", "n"))
nnoremap <silent> <c-enter> <Plug>ReplicaSendCell
# imap <silent> <c-enter> <Plug>ReplicaSendCell<cr>j
endif
endif
export def FtCommandsMappings()
noremap <Plug>ReplicaConsoleToggle
\ <ScriptCmd>repl.ConsoleToggle()<cr>
tnoremap <Plug>ReplicaConsoleToggle
\ <ScriptCmd>repl.ConsoleToggle()<cr>
noremap <Plug>ReplicaSendLines
\ <ScriptCmd>repl.SendLines(line('.'), line('.'))<cr>
noremap <Plug>ReplicaSendFile
\ <ScriptCmd>repl.SendFile()<cr>
noremap <Plug>ReplicaSendCell
\ <ScriptCmd>repl.SendCell()<cr>
if g:replica_use_default_mapping == true
if !hasmapto('<Plug>ReplicaConsoleToggle') || empty(mapcheck("<F2>", "nt"))
nnoremap <silent> <F2> <Plug>ReplicaConsoleToggle
# imap <silent> <F2> <Plug>ReplicaConsoleToggle<cr>
tnoremap <F2> <silent> <c-w><Plug>ReplicaConsoleToggle
endif

if !hasmapto('<Plug>ReplicaSendLines') || empty(mapcheck("<F9>", "nx"))
nnoremap <silent> <F9> <Plug>ReplicaSendLines
# imap <silent> <F9> <Plug>ReplicaSendLines<cr>
xnoremap <silent> <F9> :ReplicaSendLines<cr>j
endif

if !hasmapto('<Plug>ReplicaSendFile') || empty(mapcheck("<F5>", "n"))
nnoremap <silent> <F5> <Plug>ReplicaSendFile
# imap <silent> <F5> <Plug>ReplicaSendFile<cr>
endif

if !hasmapto('<Plug>ReplicaSendCell') || empty(mapcheck("<c-enter>", "n"))
nnoremap <silent> <c-enter> <Plug>ReplicaSendCell
# imap <silent> <c-enter> <Plug>ReplicaSendCell<cr>j
endif
endif


# -----------------------------
# Commands
# -----------------------------
if !exists(":ReplicaConsoleToggle")
command -buffer ReplicaConsoleToggle silent repl.ConsoleToggle()
endif

if !exists(":ReplicaConsoleRestart" )
command -buffer ReplicaConsoleRestart silent repl.ConsoleShutoff() |
\ repl.ConsoleToggle()
endif

if !exists(":ReplicaConsoleShutoff")
command -buffer ReplicaConsoleShutoff repl.ConsoleShutoff()
endif

if !exists(":ReplicaSendLines")
command -buffer -range ReplicaSendLines
\ silent repl.SendLines(<line1>, <line2>)
endif

if !exists(":ReplicaSendCell")
command -buffer ReplicaSendCell silent repl.SendCell()
endif

if !exists(":ReplicaSendFile")
command -buffer -nargs=? -complete=file ReplicaSendFile
\ silent repl.SendFile(<f-args>)
endif

if !exists(":ReplicaRemoveCells")
command -buffer ReplicaRemoveCells repl.RemoveCells()
endif
if !exists(":ReplicaConsoleToggle")
command -buffer ReplicaConsoleToggle silent repl.ConsoleToggle()
endif

if !exists(":ReplicaConsoleRestart" )
command -buffer ReplicaConsoleRestart silent repl.ConsoleShutoff() |
\ repl.ConsoleToggle()
endif

if !exists(":ReplicaConsoleShutoff")
command -buffer ReplicaConsoleShutoff repl.ConsoleShutoff()
endif

if !exists(":ReplicaSendLines")
command -buffer -range ReplicaSendLines
\ silent repl.SendLines(<line1>, <line2>)
endif

if !exists(":ReplicaSendCell")
command -buffer ReplicaSendCell silent repl.SendCell()
endif

if !exists(":ReplicaSendFile")
command -buffer -nargs=? -complete=file ReplicaSendFile
\ silent repl.SendFile(<f-args>)
endif

if !exists(":ReplicaRemoveCells")
command -buffer ReplicaRemoveCells repl.RemoveCells()
endif
enddef
18 changes: 9 additions & 9 deletions test/test_replica.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def g:Test_replica_basic()
exe $"edit {src_name}"

# Start console
ReplicaConsoleToggle
exe ":ReplicaConsoleToggle"
WaitForAssert(() => assert_equal(2, winnr('$')))
# TODO: Check how to remove the sleep
# It must be very generous otherwise the CI tests won't pass.
Expand All @@ -58,7 +58,7 @@ def g:Test_replica_basic()
var prompts_lines = {2: 4, 3: 7, 4: 9}

for [prompt, line] in items(prompts_lines)
ReplicaSendCell
exe ":ReplicaSendCell"
sleep 2
redraw!
expected_prompt = prompt
Expand All @@ -73,7 +73,7 @@ def g:Test_replica_basic()
prompts_lines = {5: 2, 6: 3}

for [prompt, line] in items(prompts_lines)
ReplicaSendLine
exe ":ReplicaSendLine"
sleep 1
redraw!
expected_prompt = prompt
Expand All @@ -84,20 +84,20 @@ def g:Test_replica_basic()
endfor

# Double Toggle
ReplicaConsoleToggle
exe ":ReplicaConsoleToggle"
WaitForAssert(() => assert_equal(1, winnr('$')))
WaitForAssert(() => assert_true(bufexists('IPYTHON')))
ReplicaConsoleToggle
exe ":ReplicaConsoleToggle"
WaitForAssert(() => assert_equal(2, winnr('$')))
WaitForAssert(() => assert_true(lastline =~# expected_prompt))
WaitForAssert(() => assert_true(bufexists('IPYTHON')))

# Remove cells
ReplicaRemoveCells
exe ":ReplicaRemoveCells"
WaitForAssert(() => assert_equal(search(g:replica_cells_delimiters.python, 'cnw'), 0))

# Restart kernel
ReplicaConsoleRestart
exe ":ReplicaConsoleRestart"
sleep 5
redraw!
bufnr = term_list()[0]
Expand All @@ -108,7 +108,7 @@ def g:Test_replica_basic()
WaitForAssert(() => assert_true(lastline =~# expected_prompt))

# ReplicaSendFile
ReplicaSendFile
exe ":ReplicaSendFile"
sleep 3
redraw!
term_cursor = term_getcursor(bufnr)
Expand All @@ -120,7 +120,7 @@ def g:Test_replica_basic()
WaitForAssert(() => assert_true(lastline =~# expected_prompt))

# Shutoff
ReplicaConsoleShutoff
exe ":ReplicaConsoleShutoff"
WaitForAssert(() => assert_false(bufexists('IPYTHON')))
WaitForAssert(() => assert_equal(1, winnr('$')))

Expand Down

0 comments on commit 80ee271

Please # to comment.