[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 4b459fb22c 26/26: Refactor
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 4b459fb22c 26/26: Refactor |
Date: |
Sun, 26 Jun 2022 10:57:53 -0400 (EDT) |
branch: externals/pyim
commit 4b459fb22cba2cbb4b7c1d1a4fd0811b7953ed82
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Refactor
---
pyim-liberime.el | 2 +-
pyim-page.el | 54 ++++++++++++------------
pyim-preview.el | 8 ++--
pyim-process.el | 88 +++++++++++++++++++++++----------------
pyim.el | 11 ++---
tests/pyim-tests.el | 118 ++++++++++++++++++++++++++++++++++++++++++++++++----
6 files changed, 197 insertions(+), 84 deletions(-)
diff --git a/pyim-liberime.el b/pyim-liberime.el
index fec2326add..64257b60a7 100644
--- a/pyim-liberime.el
+++ b/pyim-liberime.el
@@ -184,7 +184,7 @@
(defvar pyim-liberime-word-log nil)
(cl-defmethod pyim-process-select-word ((_scheme pyim-scheme-rime))
"从选词框中选择当前词条,然后删除该词条对应拼音。"
- (pyim-process-outcome-handle 'candidate)
+ (pyim-process-outcome-handle 'word)
(let* ((entered (pyim-entered-get 'point-before))
(word (string-remove-prefix
(or (pyim-outcome-get 1) "") (pyim-outcome-get)))
diff --git a/pyim-page.el b/pyim-page.el
index 041f773dd9..49b4adedc6 100644
--- a/pyim-page.el
+++ b/pyim-page.el
@@ -151,9 +151,8 @@ page 的概念,比如,上面的 “nihao” 的 *待选词列表* 就可以
第4页 柅 猊 郳 輗 坭 惄 堄 儗 伲
第5页 祢 慝
-`pyim-process-get-candidate-position' 的返回值以及
-`pyim-page-length' 的设定值(默认设置为9),共同决定了 pyim 需要
-显示哪一页,比如:
+`pyim-process-word-position' 的返回值以及 `pyim-page-length' 的设
+定值(默认设置为9),共同决定了 pyim 需要显示哪一页,比如:
第1页 你好 倪皓 泥 你 呢 拟 逆 腻 妮
第2页 怩 溺 尼 禰 齯 麑 鲵 蜺 衵
@@ -161,7 +160,7 @@ page 的概念,比如,上面的 “nihao” 的 *待选词列表* 就可以
第4页 柅 猊 郳 輗 坭 惄 堄 儗 伲
第5页 祢 慝
-假设当前选择的词条为 \"睨\", 那么 `pyim-process-get-candidate-position'
+假设当前选择的词条为 \"睨\", 那么 `pyim-process-word-position'
的返回值为 A 所在的位置。那么:
1. 函数 `pyim-page--current-page' 返回值为3, 说明当前 page 为第3页。
@@ -173,19 +172,19 @@ page 的概念,比如,上面的 “nihao” 的 *待选词列表* 就可以
(\"薿\" \"旎\" \"睨\" \"铌\" \"昵\" \"匿\" \"倪\" \"霓\" \"暱\")
这个 sublist 的起点为 `pyim-page--start' 的返回值,终点为
-`pyim-page--end' 的返回值。并保存到一个 hashtable 的 :candidates
-关键字对应的位置,这个 hastable 最终会做为参数传递给
-`pyim-page-style' 相关的函数,用于生成用于在选词框中显示的字符串。"
- (let* ((candidate-showed (pyim-page--get-showed-candidates))
- (positon (pyim-page--get-selected-word-position))
+`pyim-page--end' 的返回值。并保存到一个 plist 的 :candidates 对应
+的位置,这个 plist 最终会做为参数传递给 `pyim-page-style' 相关的
+函数,用于生成用于在选词框中显示的字符串。"
+ (let* ((candidates-showed (pyim-page--get-showed-candidates))
+ (position (pyim-page--word-position-in-current-page))
(tooltip (pyim-page--get-valid-tooltip))
(style (pyim-page--get-page-style tooltip))
(page-info
(list :scheme (pyim-scheme-current)
:current-page (pyim-page--current-page)
:total-page (pyim-page--total-page)
- :candidates candidate-showed
- :position positon
+ :candidates candidates-showed
+ :position position
:hightlight-current hightlight-current
:assistant-enable (pyim-scheme-assistant-status))))
;; Show page.
@@ -206,17 +205,15 @@ page 的概念,比如,上面的 “nihao” 的 *待选词列表* 就可以
(concat x comment)
x)))
(cl-subseq (pyim-process-get-candidates)
- (1- (pyim-page--start))
+ (pyim-page--start)
(pyim-page--end))))
-(defun pyim-page--start (&optional candidate-position)
+(defun pyim-page--start (&optional position)
"计算当前所在页的第一个词条的位置.
细节信息请参考 `pyim-page--refresh' 的 docstring."
- (let ((pos (min (pyim-process-candidates-length)
- (or candidate-position
- (pyim-process-get-candidate-position)))))
- (1+ (* (/ (1- pos) pyim-page-length) pyim-page-length))))
+ (* (/ (pyim-process-word-position position) pyim-page-length)
+ pyim-page-length))
(defun pyim-page--end ()
"计算当前所在页的最后一个词条的位置,
@@ -224,17 +221,16 @@ page 的概念,比如,上面的 “nihao” 的 *待选词列表* 就可以
细节信息请参考 `pyim-page--refresh' 的 docstring."
(let* ((whole (pyim-process-candidates-length))
(len pyim-page-length)
- (pos (pyim-process-get-candidate-position))
- (last (* (/ (+ (1- pos) len) len) len)))
+ (pos (pyim-process-word-position))
+ (last (* (/ (+ pos len) len) len)))
(if (< last whole)
last
whole)))
-(defun pyim-page--get-selected-word-position ()
- "获取当前选择的词条在 candidates 中的位置。"
- (- (min (pyim-process-get-candidate-position)
- (pyim-process-candidates-length))
- (1- (pyim-page--start))))
+(defun pyim-page--word-position-in-current-page ()
+ "获取当前选择的词条在在当前 page 中的位置。"
+ (- (pyim-process-word-position)
+ (pyim-page--start)))
(defun pyim-page--get-valid-tooltip ()
"根据当前环境,获取一个可用的 tooltip."
@@ -272,13 +268,17 @@ page 的概念,比如,上面的 “nihao” 的 *待选词列表* 就可以
"计算当前选择的词条在第几页面.
细节信息请参考 `pyim-page--refresh' 的 docstring."
- (1+ (/ (1- (pyim-process-get-candidate-position)) pyim-page-length)))
+ (1+ (/ (pyim-process-word-position) pyim-page-length)))
(defun pyim-page--total-page ()
"计算 page 总共有多少页.
细节信息请参考 `pyim-page--refresh' 的 docstring."
- (1+ (/ (1- (pyim-process-candidates-length)) pyim-page-length)))
+ (let* ((length (pyim-process-candidates-length))
+ (n (/ length pyim-page-length)))
+ (if (> length (* n pyim-page-length))
+ (1+ n)
+ n)))
(cl-defgeneric pyim-page-show (string position tooltip)
"在 POSITION 位置,使用 TOOLTIP 显示字符串 STRING.
@@ -553,7 +553,7 @@ pyim-page 的核心的功能,为此增加代码的复杂度和测试的难度
;; 高亮当前选择的词条,用于 `pyim-page-next-word'
(push
(if (and hightlight-current
- (= i position))
+ (= i (+ position 1)))
(format "%d%s" i
(propertize
(format "[%s]" str)
diff --git a/pyim-preview.el b/pyim-preview.el
index 7ee3ca85c9..e2e8603abb 100644
--- a/pyim-preview.el
+++ b/pyim-preview.el
@@ -95,8 +95,8 @@ pyim 会使用 Emacs overlay 机制在 *待输入buffer* 光标处高亮显示
(cl-defmethod pyim-preview-string (_scheme)
"获得 preview 字符串。"
(let* ((candidates (pyim-process-get-candidates))
- (pos (1- (min (pyim-process-get-candidate-position)
- (length candidates))))
+ (pos (min (pyim-process-word-position)
+ (1- (length candidates))))
(preview (concat (pyim-process-get-outcome)
(nth pos candidates))))
(pyim-process-subword-and-magic-convert preview)))
@@ -104,8 +104,8 @@ pyim 会使用 Emacs overlay 机制在 *待输入buffer* 光标处高亮显示
(cl-defmethod pyim-preview-string ((_scheme pyim-scheme-quanpin))
"获得 preview 字符串,适用于全拼输入法。"
(let* ((candidates (pyim-process-get-candidates))
- (pos (1- (min (pyim-process-get-candidate-position)
- (length candidates))))
+ (pos (min (pyim-process-word-position)
+ (1- (length candidates))))
(preview (concat (pyim-process-get-outcome)
(nth pos candidates)))
(rest (mapconcat
diff --git a/pyim-process.el b/pyim-process.el
index 9f1fc697ca..e5c67148fa 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -183,7 +183,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
(defvar pyim-process--candidates-last nil
"上一轮备选词条列表,这个变量主要用于 autoselector 机制.")
-(defvar pyim-process--candidate-position nil
+(defvar pyim-process--word-position nil
"当前选择的词条在 `pyim-candidates’ 中的位置.
细节信息请参考 `pyim-page--refresh' 的 docstring.")
@@ -199,7 +199,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
pyim-process--translating
pyim-process--imobjs
pyim-process--candidates
- pyim-process--candidate-position))
+ pyim-process--word-position))
;; ** 其它包调用的小函数
(defun pyim-process-toggle-input-ascii ()
@@ -229,12 +229,6 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
(defun pyim-process-update-last-candidates ()
(setq pyim-process--candidates-last pyim-process--candidates))
-(defun pyim-process-get-candidate-position ()
- pyim-process--candidate-position)
-
-(defun pyim-process-candidates-length ()
- (length pyim-process--candidates))
-
(defun pyim-process-select-subword-p ()
pyim-outcome-subword-info)
@@ -468,7 +462,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
(or (delete-dups (pyim-candidates-create pyim-process--imobjs
scheme))
(list entered-to-translate)))
(unless (eq (pyim-process--auto-select) 'auto-select-success)
- (pyim-process-plan-to-select-word 1)
+ (pyim-process-plan-to-select-word 0)
(pyim-process-ui-refresh)
(pyim-process--run-delay)))))
@@ -533,7 +527,7 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
(if (and str (stringp str))
(list str)
candidates)))
- (pyim-process-outcome-handle 'candidate)
+ (pyim-process-outcome-handle 'word)
(pyim-process-create-word (pyim-process-get-outcome) t))
;; autoselector 机制已经触发的时候,如果发现 entered buffer 中
;; point 后面还有未处理的输入,就将其转到下一轮处理,这种情况
@@ -634,25 +628,38 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
(pyim-process-ui-refresh)))))))
;; ** 预选词条相关
-(defun pyim-process-plan-to-select-word (word-position-in-candidates)
- (setq pyim-process--candidate-position
- word-position-in-candidates))
+(defun pyim-process-plan-to-select-word (word-position)
+ "预选 candidates 列表中 WORD-POSITION 位置的词条。"
+ (setq pyim-process--word-position word-position))
+
+(defun pyim-process-word-position (&optional position)
+ "返回已选词条的位置。"
+ (min (- (pyim-process-candidates-length) 1)
+ (if (integerp position)
+ position
+ pyim-process--word-position)))
+
+(defun pyim-process-candidates-length ()
+ "返回候选词条列表长度。"
+ (length pyim-process--candidates))
(defun pyim-process-next-word-position (n)
- (let* ((new (+ (pyim-process-get-candidate-position) n))
- (len (pyim-process-candidates-length))
- (pos (if (>= len new)
- (if (> new 0) new len)
- 1)))
+ "返回已选词条后面地 N 个词条对应的位置。"
+ (let* ((new (+ (pyim-process-word-position) n))
+ (max (1- (pyim-process-candidates-length)))
+ (pos (if (>= max new)
+ (if (< new 0) max new)
+ 0)))
pos))
;; ** 选词相关
-(cl-defgeneric pyim-process-select-word (scheme))
+(cl-defgeneric pyim-process-select-word (scheme)
+ "按照 SCHEME 对应的规则,对预选词条进行选词操作。")
(cl-defmethod pyim-process-select-word ((_scheme pyim-scheme-quanpin))
- "从选词框中选择当前词条,然后删除该词条对应拼音。"
+ "按照全拼规则,对预选词条进行选词操作。"
(pyim-process--create-code-criteria)
- (pyim-process-outcome-handle 'candidate)
+ (pyim-process-outcome-handle 'word)
(let* ((imobj (pyim-process-get-first-imobj))
(length-selected-word
;; 获取 *这一次* 选择词条的长度, 在“多次选择词条才能上屏”的情况下,
@@ -723,8 +730,8 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
(car pyim-process--imobjs))
(cl-defmethod pyim-process-select-word ((_scheme pyim-scheme-xingma))
- "从选词框中选择当前词条,然后删除该词条对应编码。"
- (pyim-process-outcome-handle 'candidate)
+ "按照形码规则,对预选词条进行选词操作。"
+ (pyim-process-outcome-handle 'word)
(if (pyim-process-with-entered-buffer
(and (> (point) 1)
(< (point) (point-max))))
@@ -740,18 +747,30 @@ imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
;; pyim 使用这个 hook 来处理联想词。
(run-hooks 'pyim-select-finish-hook)))
+(defun pyim-process-select-word-without-save ()
+ "选择词条但不保存词条。"
+ (pyim-process-outcome-handle 'word)
+ (pyim-process-terminate))
+
(defun pyim-process-select-last-char ()
+ "选择上一个输入的字符。"
(pyim-process-outcome-handle 'last-char)
(pyim-process-terminate))
(defun pyim-process-select-word-and-last-char ()
- (pyim-process-outcome-handle 'candidate-and-last-char)
+ "选择预选词条和上一次输入的字符。"
+ (pyim-process-outcome-handle 'word-and-last-char)
(pyim-process-terminate))
(defun pyim-process-select-nothing ()
+ "什么也补选。"
(pyim-process-outcome-handle "")
(pyim-process-terminate))
+(defun pyim-process-select-entered ()
+ (pyim-process-outcome-handle 'entered)
+ (pyim-process-terminate))
+
;; ** 造词相关
(defun pyim-process-create-word (word &optional prepend wordcount-handler
criteria)
"将中文词条 WORD 添加编码后,保存到用户选择过的词生成的缓存中。
@@ -843,23 +862,20 @@ BUG:拼音无法有效地处理多音字。"
(concat (pyim-outcome-get)
(pyim-process-outcome-handle-char last-command-event))
pyim-outcome-history))
- ((eq type 'candidate)
- (let ((candidate
- (nth (1- pyim-process--candidate-position)
- pyim-process--candidates)))
+ ((eq type 'word)
+ (let ((word (nth (1- pyim-process--word-position)
+ pyim-process--candidates)))
(push
- (concat (pyim-outcome-get) candidate)
+ (concat (pyim-outcome-get) word)
pyim-outcome-history)))
- ((eq type 'candidate-and-last-char)
- (let ((candidate
- (nth (1- pyim-process--candidate-position)
- pyim-process--candidates)))
+ ((eq type 'word-and-last-char)
+ (let ((word (nth (1- pyim-process--word-position)
+ pyim-process--candidates)))
(push
- (concat (pyim-outcome-get)
- candidate
+ (concat (pyim-outcome-get) word
(pyim-process-outcome-handle-char last-command-event))
pyim-outcome-history)))
- ((eq type 'pyim-entered)
+ ((eq type 'entered)
(push (pyim-entered-get 'point-before) pyim-outcome-history))
(t (error "Pyim: invalid outcome"))))
diff --git a/pyim.el b/pyim.el
index 9910246419..b515bee21b 100644
--- a/pyim.el
+++ b/pyim.el
@@ -457,9 +457,8 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
不需要保存到个人词库。"
(interactive)
(if (pyim-process-get-candidates)
- (pyim-process-outcome-handle 'candidate)
- (pyim-process-select-last-char))
- (pyim-process-terminate))
+ (pyim-process-select-word-without-save)
+ (pyim-process-select-last-char)))
(defun pyim-select-word ()
"从选词框中选择当前词条,然后删除该词条对应拼音。"
@@ -500,15 +499,13 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
(defun pyim-quit-clear ()
"取消当前输入的命令."
(interactive)
- (pyim-process-outcome-handle "")
- (pyim-process-terminate))
+ (pyim-process-select-nothing))
;; ** 字母上屏功能
(defun pyim-quit-no-clear ()
"字母上屏命令."
(interactive)
- (pyim-process-outcome-handle 'pyim-entered)
- (pyim-process-terminate))
+ (pyim-process-select-entered))
;; ** 中英文输入模式切换
(defalias 'pyim-toggle-input-ascii #'pyim-process-toggle-input-ascii)
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 67fc7aaab2..21315b9d51 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -1705,7 +1705,72 @@ Transfer-Encoding: chunked
;; TODO
)
-;; ** pyim-probe 相关单元测试
+;; ** pyim-page 相关单元测试
+(ert-deftest pyim-tests-pyim-page--start ()
+ (let ((pyim-process--candidates
+ '("你" "妮" "拟"
+ "你" "尼" "呢"
+ "泥" "妮" "拟"
+ "逆" "倪"))
+ (pyim-page-length 3))
+
+ (should (equal (pyim-page--start 2) 0))
+ (should (equal (pyim-page--start 7) 6))
+ (should (equal (pyim-page--start 6) 6))
+ (should (equal (pyim-page--start 5) 3))))
+
+(ert-deftest pyim-tests-pyim-page--end ()
+ (let ((pyim-process--candidates
+ '("你" "妮" "拟"
+ "你" "尼" "呢"
+ "泥" "妮" "拟"
+ "逆" "倪"))
+ (pyim-page-length 3))
+
+ (let ((pyim-process--word-position 0))
+ (should (eq (pyim-page--end) 3)))
+ (let ((pyim-process--word-position 1))
+ (should (eq (pyim-page--end) 3)))
+ (let ((pyim-process--word-position 1))
+ (should (eq (pyim-page--end) 3)))
+ (let ((pyim-process--word-position 2))
+ (should (eq (pyim-page--end) 3)))
+ (let ((pyim-process--word-position 3))
+ (should (eq (pyim-page--end) 6)))
+ (let ((pyim-process--word-position 9))
+ (should (eq (pyim-page--end) 11)))))
+
+(ert-deftest pyim-tests-pyim-page--current-page ()
+ (let ((pyim-process--candidates
+ '("你" "妮" "拟"
+ "你" "尼" "呢"
+ "泥" "妮" "拟"
+ "逆" "倪"))
+ (pyim-page-length 3))
+
+ (let ((pyim-process--word-position 0))
+ (should (equal (pyim-page--current-page) 1)))
+ (let ((pyim-process--word-position 2))
+ (should (equal (pyim-page--current-page) 1)))
+ (let ((pyim-process--word-position 3))
+ (should (equal (pyim-page--current-page) 2)))))
+
+(ert-deftest pyim-tests-pyim-page--total-page ()
+ (let ((pyim-process--candidates
+ '("你" "妮" "拟"
+ "你" "尼" "呢"
+ "泥" "妮" "拟"
+ "逆" "倪"))
+ (pyim-page-length 3))
+ (should (equal (pyim-page--total-page) 4)))
+
+ (let ((pyim-process--candidates
+ '("你" "妮" "拟"
+ "你" "尼" "呢"
+ "泥" "妮" "拟"))
+ (pyim-page-length 3))
+ (should (equal (pyim-page--total-page) 3))))
+
(ert-deftest pyim-tests-pyim-page--add-default-page-face ()
(let ((string (pyim-page--add-default-page-face
(concat "aaa\n"
@@ -1746,7 +1811,7 @@ abc 这是")))
:current-page 1
:total-page 26
:candidates '("你好" "尼耗" "您耗" "您好" "你")
- :position 3
+ :position 2
:hightlight-current 'hightlight-current
:assistant-enable nil)))
@@ -1773,18 +1838,18 @@ abc 这是")))
(ert-deftest pyim-tests-pyim-page-menu-create ()
(should
(equal (pyim-page-menu-create '("你好" "尼耗" "您耗" "您好" "你") 0 nil t)
- #("1.你好 2.尼耗 3.您耗 4.您好 5.你 " 13 17 (face pyim-page-selection))))
+ #("1[你好]2.尼耗 3.您耗 4.您好 5.你 " 1 5 (face pyim-page-selection))))
(should
(equal (pyim-page-menu-create '("你好" "尼耗" "您耗" "您好" "你") 1 nil t)
- #("1[你好]2.尼耗 3.您耗 4.您好 5.你 " 1 5 (face pyim-page-selection))))
+ #("1.你好 2[尼耗]3.您耗 4.您好 5.你 " 6 10 (face pyim-page-selection))))
(should
- (equal (pyim-page-menu-create '("你好" "尼耗" "您耗" "您好" "你") 3 nil t)
+ (equal (pyim-page-menu-create '("你好" "尼耗" "您耗" "您好" "你") 2 nil t)
#("1.你好 2.尼耗 3[您耗]4.您好 5.你 " 11 15 (face pyim-page-selection)))))
;; ** pyim-preview 相关单元测试
(ert-deftest pyim-tests-pyim-preview-string ()
(let ((pyim-process--candidates '("世界" "时节" "使节" "视界" ))
- (pyim-process--candidate-position 1)
+ (pyim-process--word-position 0)
(pyim-outcome-history '("你好"))
(pyim-process--imobjs '((("sh" "i" "sh" "i") ("j" "ie" "j" "ie"))))
(scheme (pyim-scheme-get 'quanpin)))
@@ -1792,7 +1857,7 @@ abc 这是")))
"你好世界")))
(let ((pyim-process--candidates '("世界" "时节" "使节" "视界" ))
- (pyim-process--candidate-position 2)
+ (pyim-process--word-position 1)
(pyim-outcome-history nil)
(pyim-process--imobjs '((("sh" "i" "sh" "i") ("j" "ie" "j" "ie"))))
(scheme (pyim-scheme-get 'quanpin)))
@@ -1800,7 +1865,7 @@ abc 这是")))
"时节")))
(let ((pyim-process--candidates '("这是" "蛰是" "这时" "真实" "这使" "这事" "这" "者" "着"
"折" "哲" "浙" "遮"))
- (pyim-process--candidate-position 10)
+ (pyim-process--word-position 9)
(pyim-outcome-history nil)
(pyim-process--imobjs '((("zh" "e" "zh" "e") ("sh" "i" "sh" "i"))))
(scheme (pyim-scheme-get 'quanpin)))
@@ -1808,7 +1873,7 @@ abc 这是")))
"折shi")))
(let ((pyim-process--candidates '("工" "藏匿" "工工" "花花草草" "㠭"))
- (pyim-process--candidate-position 4)
+ (pyim-process--word-position 3)
(pyim-outcome-history nil)
(pyim-process--imobjs '(("aaaa")))
(scheme (pyim-scheme-get 'wubi)))
@@ -2070,6 +2135,41 @@ abc 这是")))
'("a" "b" "c") '("d" "e" "f" "a" "b"))
'("d" "a" "b" "c" "e" "f"))))
+(ert-deftest pyim-tests-pyim-process-word-position ()
+ (let ((pyim-process--candidates
+ '("你" "妮" "拟"
+ "你" "尼" "呢"
+ "泥" "妮" "拟"
+ "逆" "倪")))
+
+ (let ((pyim-process--word-position 3))
+ (should (equal (pyim-process-word-position) 3)))
+ (let ((pyim-process--word-position 10))
+ (should (equal (pyim-process-word-position) 10)))
+ (let ((pyim-process--word-position 11))
+ (should (equal (pyim-process-word-position) 10)))
+
+ (should (equal (pyim-process-word-position 0) 0))
+ (should (equal (pyim-process-word-position 10) 10))
+ (should (equal (pyim-process-word-position 11) 10))))
+
+(ert-deftest pyim-tests-pyim-process-next-word-position ()
+ (let ((pyim-process--candidates
+ '("你" "妮" "拟" "你" "尼" "呢" "泥" "妮" "拟" "逆" "倪"))
+ ;;; 0 1 2 3 4 5 6 7 8 9 10
+ (pyim-process--word-position 3))
+
+ (should (equal (pyim-process-next-word-position 1) 4))
+ (should (equal (pyim-process-next-word-position 7) 10))
+
+ (should (equal (pyim-process-next-word-position 8) 0))
+
+ (should (equal (pyim-process-next-word-position -1) 2))
+ (should (equal (pyim-process-next-word-position -3) 0))
+
+ (should (equal (pyim-process-next-word-position -4) 10))))
+
+
(ert-run-tests-batch-and-exit)
;; * Footer
- [elpa] externals/pyim 74fdade342 16/26: Add ignore-errors in pyim-process-with-entered-buffer., (continued)
- [elpa] externals/pyim 74fdade342 16/26: Add ignore-errors in pyim-process-with-entered-buffer., ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 7e80507f17 25/26: pyim-process-next-word-position, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 009c56fd15 21/26: Update comment., ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 1ec45c77bb 08/26: Simplify pyim-select-word-simple, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim e7c8d3782a 14/26: Use pyim-process-select-last-char in pyim-page.el, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 862776bf21 24/26: Add pyim-process-plan-to-select-next-word, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 2f9cfb058a 17/26: Add pyim-process-select-nothing, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim d7952b08ef 03/26: Add pyim-page-plan-to-select-word, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 95a4d01768 09/26: Simplify pyim-select-word, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 011b87a78f 15/26: Add pyim-process-without-entered-p, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 4b459fb22c 26/26: Refactor,
ELPA Syncer <=
- [elpa] externals/pyim 8690bd940d 18/26: pyim-process-translating-p -> pyim-process--translating-p, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim c44e5d00db 11/26: pyim-process-create-code-criteria -> pyim-process--create-code-criteria, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim d69083f029 20/26: Move pyim-select-finish-hook to pyim-process.el, ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 9139d75f26 22/26: pyim-process-run use pyim-process-plan-to-select-word., ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 7ea1d2abe2 23/26: Move pyim-process-create-word., ELPA Syncer, 2022/06/26
- [elpa] externals/pyim 0ed0f00435 19/26: Add comment, ELPA Syncer, 2022/06/26