emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/pyim c69397761f 1/2: Simplify pyim-autoselector-xingma


From: ELPA Syncer
Subject: [elpa] externals/pyim c69397761f 1/2: Simplify pyim-autoselector-xingma
Date: Sat, 4 Jun 2022 19:57:47 -0400 (EDT)

branch: externals/pyim
commit c69397761fedafc2cb40fa411142a8722c7da374
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Simplify pyim-autoselector-xingma
    
            * pyim-autoselector.el (pyim-autoselector-xingma-1): New function.
            (pyim-autoselector-xingma): Simplify.
    
            * tests/pyim-tests.el (pyim-tests-pyim-autoselecter-xingma-1): New 
tests.
---
 pyim-autoselector.el | 39 ++++++++++++++++++++++-----------------
 tests/pyim-tests.el  | 20 +++++++++++++++++++-
 2 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/pyim-autoselector.el b/pyim-autoselector.el
index 74d183d7b1..3c13d38031 100644
--- a/pyim-autoselector.el
+++ b/pyim-autoselector.el
@@ -41,27 +41,32 @@
 比如:五笔等型码输入法,重码率很低,90%以上的情况都是选择第一个词
 条,自动选择可以减少按空格强制选词的机会。"
   (let* ((scheme (pyim-scheme-current))
-         (n (pyim-scheme-xingma-code-split-length scheme))
+         (split-length (pyim-scheme-xingma-code-split-length scheme))
          (entered (pyim-process-get-entered 'point-before))
          (candidates (pyim-process-get-candidates))
          (last-candidates (pyim-process-get-last-candidates)))
     (when (pyim-scheme-xingma-p scheme)
-      (cond
-       ((and (= (length entered) n)
-             (= (length candidates) 1)
-             ;; 如果没有候选词,pyim 默认将用户输入当做候选词,这时不能自动上屏,
-             ;; 因为这种情况往往是用户输入有误,自动上屏之后,调整输入就变得麻烦了。
-             (not (equal entered (car candidates))))
-        '(:select current))
-       ((and (> (length entered) n)
-             (equal (substring entered 0 n)
-                    (car last-candidates)))
-        ;; 自动清除错误输入模式,类似微软五笔:敲第五个字母的时候,前面四个字母自
-        ;; 动清除。
-        '(:select last :replace-with ""))
-       ((> (length entered) n)
-        '(:select last))
-       (t nil)))))
+      (pyim-autoselector-xingma-1
+       split-length entered candidates last-candidates))))
+
+(defun pyim-autoselector-xingma-1 (split-length entered candidates 
last-candidates)
+  "`pyim-autoselector-xingma' 内部使用的函数。"
+  (cond
+   ((and (= (length entered) split-length)
+         (= (length candidates) 1)
+         ;; 如果没有候选词,pyim 默认将用户输入当做候选词,这时不能自动上屏,
+         ;; 因为这种情况往往是用户输入有误,自动上屏之后,调整输入就变得麻烦了。
+         (not (equal entered (car candidates))))
+    '(:select current))
+   ((and (> (length entered) split-length)
+         (equal (substring entered 0 split-length)
+                (car last-candidates)))
+    ;; 自动清除错误输入模式,类似微软五笔:敲第五个字母的时候,前面四个字母自
+    ;; 动清除。
+    '(:select last :replace-with ""))
+   ((> (length entered) split-length)
+    '(:select last))
+   (t nil)))
 
 (cl-pushnew #'pyim-autoselector-xingma pyim-process-autoselector)
 
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 7c11fca835..dcf094f7c2 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -26,7 +26,7 @@
 
 ;;; Commentary:
 ;; pyim test case.
-;; 1.  TODO   pyim-autoselector.el
+;; 1.  [50%]  pyim-autoselector.el
 ;; 2.  [90%]  pyim-candidates.el
 ;; 3.  [95%]  pyim-cloudim.el
 ;; 4.  DONE   pyim-codes.el
@@ -1569,7 +1569,25 @@ Transfer-Encoding: chunked
     (should (equal (pyim-preview-string scheme)
                    "花花草草"))))
 
+;; ** pyim-autoselecter 相关单元测试
+(ert-deftest pyim-tests-pyim-autoselecter-xingma-1 ()
+  (should-not (apply #'pyim-autoselector-xingma-1
+                     '(4 "aaaa" ("工" "藏匿" "花花草草" "工工" "㠭") ("工"))))
+
+  (should (equal (apply #'pyim-autoselector-xingma-1
+                        '(4 "aaaab" ("工" "藏匿" "花花草草" "工工" "㠭") ("工")))
+                 '(:select last)))
+
+  ;; 自动清除错误输入模式,类似微软五笔:敲第五个字母的时候,前面四个字母自动清除
+  (should (equal (apply #'pyim-autoselector-xingma-1
+                        '(4 "xxxxa" ("工" "戈") ("xxxx")))
+                 '(:select last :replace-with "")))
+
+  (should (equal (apply #'pyim-autoselector-xingma-1
+                        '(4 "aaaa" ("工") ("工")))
+                 '(:select current))))
 
 (ert-run-tests-batch-and-exit)
+
 ;; * Footer
 ;;; pyim-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]