zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: initial bindkey tests
Date: Thu, 10 Dec 2015 17:42:35 +0000	[thread overview]
Message-ID: <20151210174235.36114d7f@pwslap01u.europe.root.pri> (raw)

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 )" \


                 reply	other threads:[~2015-12-10 17:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151210174235.36114d7f@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).