-
Notifications
You must be signed in to change notification settings - Fork 2
/
pinyin-isearch-pinyin-tests.el
131 lines (107 loc) · 6.85 KB
/
pinyin-isearch-pinyin-tests.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
;;; pinyin-isearch-pinyin-tests.el --- Tests for pinyin-isearch pinyin mode -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Free Software Foundation, Inc
;; Author: Anoncheg1
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; to run: emacs -batch -l ert -l pinyin-isearch.el -l pinyin-isearch-pinyin-tests.el -f ert-run-tests-batch-and-exit 2> out.log
;; eval-buffer
;; M-x ert RET t RET
;;; Code:
(require 'ert)
(require 'pinyin-isearch-pinyin)
(defvar pinyin-isearch-strict nil)
(pinyin-isearch-pinyin-load) ; activate pinyin-isearch-pinyin
(ert-deftest pinyin-isearch-pinyin--get_vowel_from_sisheng ()
(with-temp-buffer
(should (equal (pinyin-isearch-pinyin--get_vowel_from_sisheng "zuō") "o"))
(should (equal (pinyin-isearch-pinyin--get_vowel_from_sisheng "nüē") "ue"))
)
)
(ert-deftest pinyin-isearch-pinyin--vowels-to-regex ()
(with-temp-buffer
(should (equal (pinyin-isearch-pinyin--vowels-to-regex '("u" "o")) "\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)"))
(should (equal (pinyin-isearch-pinyin--vowels-to-regex '("u")) "[ūúǔùǖǘǚǜ]"))
(should (equal (pinyin-isearch-pinyin--vowels-to-regex '("u" "ue")) "\\([ūúǔùǖǘǚǜ]\\s-*e\\|ü[ēéěè]\\)"))
)
)
(ert-deftest pinyin--get-position-first-syllable ()
(with-temp-buffer
(should (equal (pinyin-isearch-pinyin--get-position-first-syllable "zuom") '(3 "u" "o")))
(should (equal (pinyin-isearch-pinyin--get-position-first-syllable "svssvv") '(nil)))
(should (equal (pinyin-isearch-pinyin--get-position-first-syllable "zux") '(2 "u")))
(should (equal (pinyin-isearch-pinyin--get-position-first-syllable "zu") '(2 "u")))
(should (equal (pinyin-isearch-pinyin--get-position-first-syllable "nue") '(3 "u" "ue")))
(should (equal (pinyin-isearch-pinyin--get-position-first-syllable "pin") '(2 "i")))
(should (equal (pinyin-isearch-pinyin--get-position-first-syllable "jiaoshenme") '(3 "i" "a")))
)
)
(ert-deftest pinyin-isearch-pinyin--make-syllable-to-regex ()
(with-temp-buffer
(should (equal (pinyin-isearch-pinyin--make-syllable-to-regex "zuo" '(3 "u" "o")) "z\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)"))
(should (equal (pinyin-isearch-pinyin--make-syllable-to-regex "zu" '(2 "u")) "z[ūúǔùǖǘǚǜ]"))
(should (equal (pinyin-isearch-pinyin--make-syllable-to-regex "nue" '(3 "u" "ue")) "n\\([ūúǔùǖǘǚǜ]\\s-*e\\|ü[ēéěè]\\)"))
(should (equal (pinyin-isearch-pinyin--make-syllable-to-regex "nue" '(nil)) "nue"))
)
)
(ert-deftest pinyin-brute-replace ()
(with-temp-buffer
(should (equal (pinyin-isearch-pinyin--brute-replace "zuss") "z\\s-*[ūúǔùǖǘǚǜ]\\s-*s\\s-*s"))
(should (equal (pinyin-isearch-pinyin--brute-replace "zuss" :normal t) "z\\s-*[uūúǔùǖǘǚǜ]\\s-*s\\s-*s"))
(should (equal (pinyin-isearch-pinyin--brute-replace "zenme") "z\\s-*[ēéěè]\\s-*n\\s-*m\\s-*[ēéěè]"))
(should (equal (pinyin-isearch-pinyin--brute-replace "zenme" :normal t) "z\\s-*[eēéěè]\\s-*n\\s-*m\\s-*[eēéěè]"))
(should (equal (pinyin-isearch-pinyin--brute-replace "oshenme" :normal t) "[oōóǒò]\\s-*s\\s-*h\\s-*[eēéěè]\\s-*n\\s-*m\\s-*[eēéěè]"))
)
)
(ert-deftest pinyin-isearch-pinyin-regexp-function ()
(with-temp-buffer
;; (pinyin-isearch-mode)
(should (equal (pinyin-isearch-pinyin-regexp-function "") ""))
(should (equal (pinyin-isearch-pinyin-regexp-function "n") "n"))
(should (equal (pinyin-isearch-pinyin-regexp-function "nu") "n[ūúǔùǖǘǚǜ]"))
(should (equal (pinyin-isearch-pinyin-regexp-function "nu") "n[ūúǔùǖǘǚǜ]"))
(should (equal (pinyin-isearch-pinyin-regexp-function "ssd") "ssd"))
(should (equal (pinyin-isearch-pinyin-regexp-function "n") "n"))
(should (equal (pinyin-isearch-pinyin-regexp-function "me") "m[ēéěè]"))
(should (equal (pinyin-isearch-pinyin-regexp-function "zuo") "z\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)"))
(should (equal (pinyin-isearch-pinyin-regexp-function "zuozuo") "z\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)\\s-*z\\s-*[uūúǔùǖǘǚǜ]\\s-*[oōóǒò]"))
(should (equal (pinyin-isearch-pinyin-regexp-function "zuo me") "z\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)\\s-* \\s-*m\\s-*[eēéěè]"))
(should (equal (pinyin-isearch-pinyin-regexp-function "zuome") "z\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)\\s-*m\\s-*[eēéěè]"))
(should (equal (pinyin-isearch-pinyin-regexp-function "zuom") "z\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)\\s-*m"))
(should (equal (pinyin-isearch-pinyin-regexp-function "zuomezuome") "z\\([ūúǔùǖǘǚǜ]\\s-*o\\|u[ōóǒò]\\)\\s-*m\\s-*[eēéěè]\\s-*z\\s-*[uūúǔùǖǘǚǜ]\\s-*[oōóǒò]\\s-*m\\s-*[eēéěè]"))
(should (equal (pinyin-isearch-pinyin-regexp-function "nuan") "n\\([ūúǔùǖǘǚǜ]\\s-*a\\|u[āáǎà]\\)n"))
(should (equal (pinyin-isearch-pinyin-regexp-function "nue") "n\\([ūúǔùǖǘǚǜ]\\s-*e\\|ü[ēéěè]\\)"))
(should (equal (pinyin-isearch-pinyin-regexp-function "pin") "p[īíǐì]\\s-*n"))
(should (equal (pinyin-isearch-pinyin-regexp-function "jiaoshenme") "j\\([īíǐì]\\s-*a\\|i[āáǎà]\\)\\s-*[oōóǒò]\\s-*s\\s-*h\\s-*[eēéěè]\\s-*n\\s-*m\\s-*[eēéěè]"))
(setq pinyin-isearch-strict nil) ; default
(should (equal (pinyin-isearch-pinyin-regexp-function "hi") "hi"))
(setq pinyin-isearch-strict t)
(should (equal (pinyin-isearch-pinyin-regexp-function "hi") nil))
(setq pinyin-isearch-strict nil)
)
)
;; (ert-deftest pinyin--sisheng-to-normal ()
;; (with-temp-buffer
;; (pinyin-isearch-mode)
;; (should (equal (pinyin-isearch-pinyin--sisheng-to-normal "nüē") "nue"))
;; )
;; )
;; test
;; (print (pinyin-isearch-pinyin--get-position-first-syllable "bian")) ; bi or an or bian? "bī" "ān" "biān" ;; "b\\([īíǐì][āáǎà]\\|i[āáǎà]\\|[īíǐì]a\\)n"
;; (print (pinyin-isearch-pinyin--get-position-first-syllable "bian")) ; bi or bian? "bī" "biān" ;; "b\\(i[āáǎà]\\|[īíǐì]a\\)n"
;; "b([īíǐì][āáǎà]|i[āáǎà]|[īíǐì]a)n"
;; "b\\([īíǐì][āáǎà]\\|i[āáǎà]\\|[īíǐì]a\\)n"
;; (ert-run-tests-interactively "pinyin--prepare-query")
;; (ert-run-tests-interactively "pinyin--sisheng-to-normal")
;; (ert-run-tests-interactively "pinyin--prepare-query2")
(provide 'pinyin-isearch-pinyin-tests)
;;; pinyin-isearch-pinyin-tests.el ends here