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

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

[elpa] externals/pyim 5bba27b 5/5: 添加 pyim-dhashcache-update-ishortcode


From: ELPA Syncer
Subject: [elpa] externals/pyim 5bba27b 5/5: 添加 pyim-dhashcache-update-ishortcode2word-1
Date: Sun, 12 Dec 2021 22:57:40 -0500 (EST)

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

    添加 pyim-dhashcache-update-ishortcode2word-1
    
        * tests/pyim-tests.el 
(pyim-tests-pyim-dhashcache-update-shortcode2word): New test.
    
        * pyim-dhashcache.el (pyim-dhashcache-update-ishortcode2word-1): New 
function.
        (pyim-dhashcache-update-ishortcode2word): Use 
pyim-dhashcache-update-ishortcode2word-1.
---
 pyim-dhashcache.el  | 48 ++++++++++++++++++++++++++----------------------
 tests/pyim-tests.el | 22 ++++++++++++++++++++++
 2 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index fe90ebf..d81041c 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -99,31 +99,35 @@
         (require 'pyim-dhashcache)
         (pyim-dcache-set-variable 'pyim-dhashcache-icode2word)
         (pyim-dcache-set-variable 'pyim-dhashcache-iword2count)
-        (setq pyim-dhashcache-ishortcode2word
-              (make-hash-table :test #'equal))
-        (maphash
-         (lambda (key value)
-           (when (and (> (length key) 0)
-                      (not (string-match-p "[^a-z-]" key)))
-             (let* ((newkey (mapconcat
-                             (lambda (x)
-                               (substring x 0 1))
-                             (split-string key "-") "-")))
-               (puthash newkey
-                        (delete-dups
-                         `(,@value
-                           ,@(gethash newkey pyim-dhashcache-ishortcode2word)))
-                        pyim-dhashcache-ishortcode2word))))
-         pyim-dhashcache-icode2word)
-        (maphash
-         (lambda (key value)
-           (puthash key (pyim-dhashcache-sort-words value)
-                    pyim-dhashcache-ishortcode2word))
-         pyim-dhashcache-ishortcode2word)
-        (pyim-dcache-save-variable 'pyim-dhashcache-ishortcode2word))
+        (pyim-dhashcache-update-ishortcode2word-1))
      (lambda (_)
        (pyim-dcache-set-variable 'pyim-dhashcache-ishortcode2word t)))))
 
+(defun pyim-dhashcache-update-ishortcode2word-1 ()
+  "`pyim-dhashcache-update-ishortcode2word' 内部函数."
+  (setq pyim-dhashcache-ishortcode2word
+        (make-hash-table :test #'equal))
+  (maphash
+   (lambda (key value)
+     (when (and (> (length key) 0)
+                (not (string-match-p "[^a-z-]" key)))
+       (let* ((newkey (mapconcat
+                       (lambda (x)
+                         (substring x 0 1))
+                       (split-string key "-") "-")))
+         (puthash newkey
+                  (delete-dups
+                   `(,@(gethash newkey pyim-dhashcache-ishortcode2word)
+                     ,@value))
+                  pyim-dhashcache-ishortcode2word))))
+   pyim-dhashcache-icode2word)
+  (maphash
+   (lambda (key value)
+     (puthash key (pyim-dhashcache-sort-words value)
+              pyim-dhashcache-ishortcode2word))
+   pyim-dhashcache-ishortcode2word)
+  (pyim-dcache-save-variable 'pyim-dhashcache-ishortcode2word))
+
 (defun pyim-dhashcache-update-shortcode2word (&optional force)
   "使用 `pyim-dhashcache-code2word' 中的词条,创建简写 code 词库缓存并加载.
 
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 8741f01..79d3280 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -670,6 +670,28 @@ zuo-zuo-you-mang 作作有芒")
                      #("㐂" 0 1 (:comment "b"))
                      #("𧝣" 0 1 (:comment "e")))))))
 
+(ert-deftest pyim-tests-pyim-dhashcache-update-ishortcode2word ()
+  (let ((pyim-dcache-directory (file-name-as-directory (make-temp-name 
"pyim-dcache-")))
+        (pyim-dhashcache-icode2word (make-hash-table :test #'equal))
+        (pyim-dhashcache-iword2count (make-hash-table :test #'equal))
+        (pyim-dhashcache-ishortcode2word (make-hash-table :test #'equal))
+        output)
+
+    (puthash "ni" '("你" "呢") pyim-dhashcache-icode2word)
+    (puthash "ni-hao" '("你好" "呢耗") pyim-dhashcache-icode2word)
+    (puthash "ni-huai" '("你坏") pyim-dhashcache-icode2word)
+
+    (pyim-dhashcache-update-ishortcode2word-1)
+
+    (with-temp-buffer
+      (insert-file-contents (concat pyim-dcache-directory 
"pyim-dhashcache-ishortcode2word"))
+      (setq output (read (current-buffer))))
+
+    (should (equal (gethash "n-h" output)
+                   '("你好" "呢耗" "你坏")))
+    (should (equal (gethash "n" output)
+                   '("你" "呢")))))
+
 ;; ** pyim-dregcache 相关单元测试
 (ert-deftest pyim-tests-pyim-general ()
   (let ((pyim-dcache-backend 'pyim-dregcache))



reply via email to

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