diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-12-10 04:43:34 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-01-04 03:18:30 +0100 |
commit | f4d326cf101bd83716a281c9802d6995f92ce0b5 (patch) | |
tree | 2a419847b6ff0b79e71499228a6cc22e1806128c /test/functional/ex_cmds/ctrl_c_spec.lua | |
parent | 15259c4b84c4de8aa7a7535c0195db3fd47d363e (diff) | |
download | rneovim-f4d326cf101bd83716a281c9802d6995f92ce0b5.tar.gz rneovim-f4d326cf101bd83716a281c9802d6995f92ce0b5.tar.bz2 rneovim-f4d326cf101bd83716a281c9802d6995f92ce0b5.zip |
test: ctrl_c_spec
- Improve test reliability by only checking for a line with the string
we are interested in ("Interrupt").
- Try to avoid OOM by loading an existing big file instead of looping to
create one.
Diffstat (limited to 'test/functional/ex_cmds/ctrl_c_spec.lua')
-rw-r--r-- | test/functional/ex_cmds/ctrl_c_spec.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua new file mode 100644 index 0000000000..5867bd6ee0 --- /dev/null +++ b/test/functional/ex_cmds/ctrl_c_spec.lua @@ -0,0 +1,56 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear, feed, source = helpers.clear, helpers.feed, helpers.source +local execute = helpers.execute + +if helpers.pending_win32(pending) then return end + +describe("CTRL-C (mapped)", function() + before_each(function() + clear() + end) + + it("interrupts :global", function() + source([[ + set nomore nohlsearch undolevels=-1 + nnoremap <C-C> <NOP> + ]]) + + execute("silent edit! test/functional/fixtures/bigfile.txt") + local screen = Screen.new(52, 6) + screen:attach() + screen:set_default_attr_ids({ + [0] = {foreground = Screen.colors.White, + background = Screen.colors.Red}, + [1] = {bold = true, + foreground = Screen.colors.SeaGreen} + }) + + screen:expect([[ + ^0000;<control>;Cc;0;BN;;;;;N;NULL;;;; | + 0001;<control>;Cc;0;BN;;;;;N;START OF HEADING;;;; | + 0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; | + 0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; | + 0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;;;| + | + ]]) + + local function test_ctrl_c(ms) + feed(":global/^/p<CR>") + helpers.sleep(ms) + feed("<C-C>") + screen:expect([[Interrupt]], nil, nil, nil, true) + end + + -- The test is time-sensitive. Try different sleep values. + local ms_values = {1, 10, 100} + for i, ms in ipairs(ms_values) do + if i < #ms_values then + local status, _ = pcall(test_ctrl_c, ms) + if status then break end + else -- Call the last attempt directly. + test_ctrl_c(ms) + end + end + end) +end) |