Editing
Idea: some kind of automation to test vim / emacs
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Would be nice to be able to say "opening vim, pressing v$y should copy the first line onto the clipboard." Then I can make changes and still see that it works... One way to do this is to use tmux. But let's start by just modeling this in python. def test_editor(executable: emacs | vim, keystrokes=""): ... or <pre> def test_vimrc(keystrokes, input_text, expected_text, config): vim_session = open_vim(config) vim_buffer = prepare_buffer(vim_session, input_text) assembled_vim_command = "i" + input_text + "<esc>" + keystrokes result = run_keystrokes(vim_buffer, assembled_vim_command) assert result == expected_text def test_default_vimrc(keystrokes, input_text, expected_text): test_vimrc(keystrokes, input_text, expected_text, open("~/.vimrc").read()) test_vimrc(keystrokes="-", input_text="1\n2", output_text="2\n1", config="nnoremap - ddp") </pre> A more involved example: def test_trim_whitespace_on_save(): config = """ augroup trimwhitespace autocmd! autocmd BufWritePre * call TrimWhitespace() augroup END """ test_my_vimrc(keystrokes="o<cr>", input_text="just a line", output_text="just a line", config=config) It would be useful to have some canned source files: sample_python = """ def main(): print("hello world") if __name__ == "__main__": main() """ Maybe they could even have some syntactic issue that a vim editing session would fix. But more realistically, I'd want to even assert that the view is the same. Fortunately, commandline editors produce VT100 escape sequences which can be spooled then played to display a buffer. Ideally, even different editors would produce the same final escape sequence paint result; this would require totally removing any modeline etc. Or at least making the modeline completely editor-independent. A workflow to make a test could be thus: start recording. Open editor, do keystrokes, stop recording. Save the inputs and final rendering of the editor to a file. Then whenever anything changes, playing the same inputs would produce a different rendering. This allows making tests easily, since you don't have to write code for all the interactions, and test end-to-end. Cool!
Summary:
Please note that all contributions to razwiki are considered to be released under the Creative Commons Zero (Public Domain) (see
Razwiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Dark mode
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
People Razzi Follows
Tools
What links here
Related changes
Special pages
Page information