summary refs log tree commit diff
path: root/Test/X03zlebindkey.ztst
blob: 298d7df5d0a2db8e9b19ddb82a810f9768bee657 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Tests of the bindkey command.
# This concentrates on the command itself and also resolving keystrokes
# into bindings.  The latter is particularly tricky with multibyte sequences.

%prep
  ZSH_TEST_LANG=
  langs=(en_{US,GB}.{UTF-,utf}8 en.UTF-8
	 $(locale -a 2>/dev/null | egrep 'utf8|UTF-8'))
  for LANG in $langs; do
    if [[ é = ? ]]; then
      ZSH_TEST_LANG=$LANG
      break;
    fi
  done
  if [[ $OSTYPE = cygwin ]]; then
    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
  elif ( zmodload zsh/zpty 2>/dev/null ); then
    . $ZTST_srcdir/comptest
    comptestinit -z $ZTST_testdir/../Src/zsh
  else
    ZTST_unimplemented="the zsh/zpty module is not available"
  fi

%test

  zpty_run 'bindkey -s "\C-xy" foo'
  zletest $'\C-xy'
  zpty_run 'bindkey -r "\C-xy"'
0:bindkey -s
>BUFFER: foo
>CURSOR: 3

  zpty_run 'bindkey -s "\C-xy" foo'
  zpty_run 'bindkey -s "\C-x\C-y" bar'
  zletest $'\C-xy\C-x\C-y'
  zpty_run 'bindkey -r "\C-xy"'
  zpty_run 'bindkey -r "\C-x\C-y"'
0:bindkey with multiple definitions associated with prefix
>BUFFER: foobar
>CURSOR: 6

  bindkey -s '\C-xy' bar
  bindkey '\C-xy'
  bindkey -r '\C-xy'
  bindkey '\C-xy'
0:bindkey output
>"^Xy" "bar"
>"^Xy" undefined-key

# As we're only looking at definitions here, we don't
# bother using the pseudo-terminal; just test in the normal fashion.
  bindkey -e
  bindkey -s '\C-xy' foo
  bindkey -N testmap emacs
  bindkey -M testmap '\C-xy'
  bindkey -s -M testmap '\C-xy' bar
  bindkey -M testmap '\C-xy'
  bindkey '\C-xy'
  bindkey -A testmap main
  bindkey '\C-xy'
  bindkey -A emacs main
  bindkey '\C-xy'
0:creating keymaps from existing keymaps
>"^Xy" "foo"
>"^Xy" "bar"
>"^Xy" "foo"
>"^Xy" "bar"
>"^Xy" "foo"

# Depends on the keymap created in the previous test.
  bindkey -l
  bindkey -D testmap
  print Deleted...
  bindkey -l
0:deleting keymaps
>.safe
>command
>emacs
>isearch
>main
>testmap
>vicmd
>viins
>viopp
>visual
>Deleted...
>.safe
>command
>emacs
>isearch
>main
>vicmd
>viins
>viopp
>visual

# This \M... style display of 8-bit characters is a bit
# dated in multibyte mode, but no one's complained...
  if [[ -z $ZSH_TEST_LANG ]]; then
    ZTST_skip="multibyte not available for bindkey test"
  else
    bindkey | grep '\\M.*self-insert'
  fi
0:in multibyte mode all bytes with bit 7 set start self-insert
>"\M-^@"-"\M-^?" self-insert

  if [[ -z $ZSH_TEST_LANG ]]; then
    ZTST_skip="multibyte not available for bindkey test"
  else
    zpty_run 'alias unbind="bindkey -r ホ"'
    zpty_run 'bindkey -s ホ bar'
    zletest 'ホ'
    zpty_run unbind
    zletest 'ホ'
    zpty_run 'bindkey ホ self-insert'
    zletest 'ホ'
    zpty_run unbind
    zletest 'ホ'
  fi
0:bindkey -s multibyte characters
>BUFFER: bar
>CURSOR: 3
>BUFFER: ホ
>CURSOR: 1
>BUFFER: ホ
>CURSOR: 1
>BUFFER: ホ
>CURSOR: 1

  zpty_run 'bindkey " " magic-space'
  setopt interactivecomments
  zletest 'echo $(( x ) x ) y'
  zletest 'echo $(( ##x ) ##x ) y'
  unsetopt interactivecomments
  zletest 'echo $(( x ) x ) y'
  zletest 'echo $(( ##x ) ##x ) y'
0:history expansion of failed command substitution using magic-space binding
>BUFFER: echo $(( x ) x ) y
>CURSOR: 18
>BUFFER: echo $(( ##x ) ##x ) y
>CURSOR: 22
>BUFFER: echo $(( x ) x ) y
>CURSOR: 18
>BUFFER: echo $(( ##x ) ##x ) y
>CURSOR: 22