diff options
author | Chen Bin <chenbin.sh@gmail.com> | 2018-04-20 00:38:29 +1000 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2018-04-28 09:56:14 +0300 |
commit | c6e6503900534d939dd94b812563c27f22c49b7d (patch) | |
tree | 4fd31046412e32e6475e43497bf94040ef79975e /test/lisp/subr-tests.el | |
parent | 4bc74dac281ff2a502fc89e76f6210dc711cfed1 (diff) | |
download | emacs-c6e6503900534d939dd94b812563c27f22c49b7d.tar.gz emacs-c6e6503900534d939dd94b812563c27f22c49b7d.tar.bz2 emacs-c6e6503900534d939dd94b812563c27f22c49b7d.zip |
New function 'string-distance'
* src/fns.c (Fstring_distance): New primitive.
(syms_of_fns): Defsubr it.
* test/lisp/subr-tests.el (subr-tests--string-distance): New test.
* etc/NEWS: Mention 'string-distance'.
Diffstat (limited to 'test/lisp/subr-tests.el')
-rw-r--r-- | test/lisp/subr-tests.el | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 52b61d9fb97..6b80c743a05 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -281,6 +281,24 @@ indirectly `mapbacktrace'." (should (equal (string-match-p "\\`[[:blank:]]\\'" "\u3000") 0)) (should-not (string-match-p "\\`[[:blank:]]\\'" "\N{LINE SEPARATOR}"))) +(ert-deftest subr-tests--string-distance () + "Test `string-distance' behavior." + ;; ASCII characters are always fine + (should (equal 1 (string-distance "heelo" "hello"))) + (should (equal 2 (string-distance "aeelo" "hello"))) + (should (equal 0 (string-distance "ab" "ab" t))) + (should (equal 1 (string-distance "ab" "abc" t))) + + ;; string containing hanzi character, compare by byte + (should (equal 6 (string-distance "ab" "ab我她" t))) + (should (equal 3 (string-distance "ab" "a我b" t))) + (should (equal 3 (string-distance "我" "她" t))) + + ;; string containing hanzi character, compare by character + (should (equal 2 (string-distance "ab" "ab我她"))) + (should (equal 1 (string-distance "ab" "a我b"))) + (should (equal 1 (string-distance "我" "她")))) + (ert-deftest subr-tests--dolist--wrong-number-of-args () "Test that `dolist' doesn't accept wrong types or length of SPEC, cf. Bug#25477." |