annotate src/testdir/test_prompt_buffer.vim @ 14019:dc67449d648c v8.1.0027

patch 8.1.0027: difficult to make a plugin that feeds a line to a job commit https://github.com/vim/vim/commit/f273245f6433d5d43a5671306b520a3230c35787 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 3 14:47:35 2018 +0200 patch 8.1.0027: difficult to make a plugin that feeds a line to a job Problem: Difficult to make a plugin that feeds a line to a job. Solution: Add the nitial code for the "prompt" buftype.
author Christian Brabandt <cb@256bit.org>
date Sun, 03 Jun 2018 15:00:07 +0200
parents
children 945d343d3024
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for setting 'buftype' to "prompt"
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !has('channel')
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 source shared.vim
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 source screendump.vim
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 func Test_prompt_basic()
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 " We need to use a terminal window to be able to feed keys without leaving
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " Insert mode.
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 if !has('terminal')
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_report('no terminal')
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 return
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 endif
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call writefile([
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 \ 'func TextEntered(text)',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 \ ' if a:text == "exit"',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 \ ' stopinsert',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 \ ' close',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 \ ' else',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 \ ' " Add the output above the current prompt.',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 \ ' call append(line("$") - 1, "Command: \"" . a:text . "\"")',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 \ ' " Reset &modified to allow the buffer to be closed.',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 \ ' set nomodified',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 \ ' call timer_start(20, {id -> TimerFunc(a:text)})',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 \ ' endif',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 \ 'endfunc',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 \ '',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 \ 'func TimerFunc(text)',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 \ ' " Add the output above the current prompt.',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 \ ' call append(line("$") - 1, "Result: \"" . a:text . "\"")',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 \ 'endfunc',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 \ '',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 \ 'call setline(1, "other buffer")',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 \ 'new',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 \ 'set buftype=prompt',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 \ 'startinsert',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 \ ], 'Xpromptscript')
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 let buf = RunVimInTerminal('-S Xpromptscript', {})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call term_sendkeys(buf, "hello\<CR>")
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 call term_sendkeys(buf, "exit\<CR>")
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call StopVimInTerminal(buf)
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call delete('Xpromptscript')
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 endfunc