Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: initial bindkey tests



Please expand: the only specialist knowledge needed should be obvious
from the couple of test cases I've put in, which already cover a
multibyte case.  So anyone can have a go.

Mikael's Special Character also uncovered a bug that the string in ztpy
-r was being passed to the pattern code unmetafied.  I've made it metafy
the input string on the fly as it's read in.

Found another bug not yet fixed: binding a full multibyte character
(rather than just the first octet) to self-insert doesn't work.  This
isn't typically needed, but should work.

diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 02708a9..63ff757 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -614,14 +614,23 @@ ptyread(char *nam, Ptycmd cmd, char **args, int noblock, int mustmatch)
 		break;
 	}
 	if (cmd->read != -1 || (ret = read(cmd->fd, buf + used, 1)) == 1) {
+	    int readchar;
 	    if (cmd->read != -1) {
 		ret = 1;
-		buf[used] = (char) cmd->read;
+		readchar = cmd->read;
 		cmd->read = -1;
-	    }
+	    } else
+		readchar = STOUC(buf[used]);
+	    if (imeta(readchar)) {
+		buf[used++] = Meta;
+		buf[used++] = (char) (readchar ^ 32);
+	    } else
+		buf[used++] = (char) readchar;
 	    seen = 1;
-	    if (++used == blen) {
+	    if (used >= blen-1) {
 		if (!*args) {
+		    buf[used] = '\0';
+		    unmetafy(buf, &used);
 		    write_loop(1, buf, used);
 		    used = 0;
 		} else {
@@ -633,7 +642,8 @@ ptyread(char *nam, Ptycmd cmd, char **args, int noblock, int mustmatch)
 	buf[used] = '\0';
 
 	if (!prog) {
-	    if (ret <= 0 || (*args && buf[used - 1] == '\n'))
+	    if (ret <= 0 || (*args && buf[used - 1] == '\n' &&
+			     (used < 2 || buf[used-2] != Meta)))
 		break;
 	} else {
 	    if (ret < 0
@@ -666,9 +676,11 @@ ptyread(char *nam, Ptycmd cmd, char **args, int noblock, int mustmatch)
 	return 1;
     }
     if (*args)
-	setsparam(*args, ztrdup(metafy(buf, used, META_HREALLOC)));
-    else if (used)
+	setsparam(*args, ztrdup(buf));
+    else if (used) {
+	unmetafy(buf, &used);
 	write_loop(1, buf, used);
+    }
 
     if (seen && (!prog || matchok || !mustmatch))
 	return 0;
diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst
new file mode 100644
index 0000000..70c42f9
--- /dev/null
+++ b/Test/X03zlebindkey.ztst
@@ -0,0 +1,45 @@
+# Tests of the vi mode of ZLE
+
+%prep
+  mb_ok=
+  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
+      mb_ok=1
+      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
+
+  if [[ -z $mb_ok ]]; then
+    ZTST_skip="bindkey multibyte test skipped"
+  else
+    zpty_run 'alias unbind="bindkey -r ホ"'
+    zpty_run 'bindkey -s ホ bar'
+    zletest 'ホ'
+    zpty_run unbind
+    zletest 'ホ'
+  fi
+0:bindkey -s multibyte characters
+>BUFFER: bar
+>CURSOR: 3
+>BUFFER: ホ
+>CURSOR: 1
diff --git a/Test/comptest b/Test/comptest
index f10739a..166d0b4 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -27,7 +27,7 @@ comptestinit () {
   }
 
   comptesteval \
-"export LC_ALL=C" \
+"export LC_ALL=${ZSH_TEST_LANG:-C}" \
 "emulate -R zsh" \
 "export ZDOTDIR=$ZTST_testdir" \
 "module_path=( $module_path )" \



Messages sorted by: Reverse Date, Date, Thread, Author