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

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

[elpa] externals/pyim 46f03c9 3/5: Add tests


From: ELPA Syncer
Subject: [elpa] externals/pyim 46f03c9 3/5: Add tests
Date: Wed, 8 Dec 2021 00:57:31 -0500 (EST)

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

    Add tests
---
 tests/pyim-tests.el | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)

diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 2d663be..70c4b3b 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -49,6 +49,130 @@
       (should (not toggle-input-method-active))
       (call-interactively #'toggle-input-method))))
 
+(ert-deftest pyim-test-pyim-permutate-list ()
+  (should (equal (pyim-permutate-list '((a b) (c d e) (f)))
+                 '((a c f)
+                   (a d f)
+                   (a e f)
+                   (b c f)
+                   (b d f)
+                   (b e f))))
+  (should (equal (pyim-permutate-list nil) t))
+  (should (equal (pyim-permutate-list '((a))) '((a)))))
+
+(ert-deftest pyim-test-pyim-zip ()
+  (should (equal (pyim-zip '((a b "d") nil (1 d) (f) nil))
+                 '(a 1 f b d "d")))
+  (should (equal (pyim-zip nil) nil)))
+
+(ert-deftest pyim-test-pyim-subconcat ()
+  (should (equal (pyim-subconcat '("a" "b" "c" "d"))
+                 '("abcd" "abc" "ab")))
+  (should (equal (pyim-subconcat '("a" "b" "c" "d") "-")
+                 '("a-b-c-d" "a-b-c" "a-b")))
+  (should (equal (pyim-subconcat nil) nil)))
+
+(ert-deftest pyim-test-pyim-cstring-partition ()
+  (should (equal (pyim-cstring-partition "你好 hello 你好")
+                 '("你好" " hello " "你好")))
+  (should (equal (pyim-cstring-partition "你好 hello 你好" t)
+                 '("你" "好" " hello " "你" "好")))
+  (should (equal (pyim-cstring-partition "你好")
+                 '("你好")))
+  (should (equal (pyim-cstring-partition "你好" t)
+                 '("你" "好")))
+  (should (equal (pyim-cstring-partition "hello")
+                 '("hello")))
+  (should (equal (pyim-cstring-partition "hello" t)
+                 '("hello"))))
+
+(ert-deftest pyim-test-pyim-cstring-substrings ()
+  (should (equal (pyim-cstring-substrings "我爱北京")
+                 '(("我爱北京" 0 4)
+                   ("我爱北" 0 3)
+                   ("我爱" 0 2)
+                   ("爱北京" 1 4)
+                   ("爱北" 1 3)
+                   ("北京" 2 4))))
+  (should (equal (pyim-cstring-substrings "我爱北京" 3)
+                 '(("我爱北" 0 3)
+                   ("我爱" 0 2)
+                   ("爱北京" 1 4)
+                   ("爱北" 1 3)
+                   ("北京" 2 4))))
+  (let* ((str "我爱北京")
+         (alist (pyim-cstring-substrings "我爱北京" 2))
+         (key (car (nth 1 alist)))
+         (pos (cdr (nth 1 alist))))
+    (should (equal (substring str (car pos) (cadr pos)) key))))
+
+(ert-deftest pyim-test-pyim-cstring-split ()
+  (let ((pyim-dhashcache-code2word (make-hash-table :test #'equal))
+        (str "我爱北京天安门"))
+
+    ;; Create code2word dcache.
+    (puthash "wo-ai" (list "我爱") pyim-dhashcache-code2word)
+    (puthash "bei-jing" (list "北京") pyim-dhashcache-code2word)
+    (puthash "tian-an" (list "天安") pyim-dhashcache-code2word)
+    (puthash "an-men" (list "安门") pyim-dhashcache-code2word)
+    (puthash "tian-an-men" (list "天安门") pyim-dhashcache-code2word)
+
+    ;; pyim-cstring-split-to-list
+    (should (equal (pyim-cstring-split-to-list str)
+                   '(("安门" 5 7) ("天安" 4 6) ("天安门" 4 7)
+                     ("北京" 2 4) ("我爱" 0 2))))
+    (should (equal (pyim-cstring-split-to-list str 2)
+                   '(("安门" 5 7) ("天安" 4 6)
+                     ("北京" 2 4) ("我爱" 0 2))))
+    (should (equal (pyim-cstring-split-to-list str 2)
+                   '(("安门" 5 7) ("天安" 4 6)
+                     ("北京" 2 4) ("我爱" 0 2))))
+    (should (equal (pyim-cstring-split-to-list str nil t)
+                   '(("天安门" 4 7) ("北京" 2 4) ("我爱" 0 2))))
+    (should (equal (pyim-cstring-split-to-list str nil t t)
+                   '(("安门" 5 7) ("北京" 2 4) ("我爱" 0 2))))
+    (should (equal (pyim-cstring-split-to-string "我爱北京天安门")
+                   "我爱 北京 天安门"))
+    (should (equal (pyim-cstring-split-to-string "haha我爱北京天安门haha")
+                   "haha 我爱 北京 天安门 haha"))
+    (should (equal (pyim-cstring-split-to-string "haha我爱北京天安门haha" nil "-")
+                   "haha-我爱-北京-天安门-haha"))
+    (should (equal (pyim-cstring-split-to-string "haha 我爱北京天安门 haha" nil "-")
+                   "haha -我爱-北京-天安门- haha"))
+
+    ;; pyim-cstring-split-to-string
+    (should (equal (pyim-cstring-split-to-string "我爱北京天安门" t)
+                   "我爱 北京 天 安门"))
+    (should (equal (pyim-cstring-split-to-string "我爱北京天安门" nil "-")
+                   "我爱-北京-天安门"))
+    (should (equal (pyim-cstring-split-to-string "我爱北京天安门" nil "-" 2)
+                   "我爱-北京-天安-门"))))
+
+(ert-deftest pyim-test-pyim-cstring-to-pinyin ()
+  (let ((pyim-dhashcache-code2word (make-hash-table :test #'equal))
+        (str "银行很行"))
+    ;; Create code2word dcache.
+    (puthash "yin-hang-hen-xing" (list "银行很行") pyim-dhashcache-code2word)
+    ;; pyim-cstring-split-to-list
+    (should (equal (pyim-cstring-to-pinyin "银行很行")
+                   (concat "yinxinghenxing yinxinghenheng yinxinghenhang "
+                           "yinhenghenxing yinhenghenheng yinhenghenhang "
+                           "yinhanghenxing yinhanghenheng yinhanghenhang")))
+    (should (equal (pyim-cstring-to-pinyin "银行很行" t)
+                   "yxhx yxhh yxhh yhhx yhhh yhhh yhhx yhhh yhhh"))
+    (should (equal (pyim-cstring-to-pinyin "银行很行" nil "-")
+                   (concat "yin-xing-hen-xing yin-xing-hen-heng 
yin-xing-hen-hang "
+                           "yin-heng-hen-xing yin-heng-hen-heng 
yin-heng-hen-hang "
+                           "yin-hang-hen-xing yin-hang-hen-heng 
yin-hang-hen-hang")))
+    (should (equal (pyim-cstring-to-pinyin "银行很行" nil "-" t)
+                   '("yin-xing-hen-xing" "yin-xing-hen-heng" 
"yin-xing-hen-hang"
+                     "yin-heng-hen-xing" "yin-heng-hen-heng" 
"yin-heng-hen-hang"
+                     "yin-hang-hen-xing" "yin-hang-hen-heng" 
"yin-hang-hen-hang")))
+    (should (equal (pyim-cstring-to-pinyin "银行很行" nil "-" t t)
+                   '("yin-xing-hen-xing")))
+    (should (equal (pyim-cstring-to-pinyin "银行很行" nil "-" nil nil t)
+                   "yin-hang-hen-xing"))))
+
 (ert-deftest pyim-test-dregcache-backend ()
   (let* ((pyim-dcache-backend 'pyim-dregcache)
          words)



reply via email to

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