Skip to content

Instantly share code, notes, and snippets.

@papaeye
Created December 20, 2014 11:29
Show Gist options
  • Save papaeye/56f3dc103f7312cd52c2 to your computer and use it in GitHub Desktop.
Save papaeye/56f3dc103f7312cd52c2 to your computer and use it in GitHub Desktop.
Tests for migemo.el
;;; migemo-tests.el --- Tests for migemo.el -*- lexical-binding: t; -*-
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'cl-lib)
(require 'ert)
(require 'migemo)
(ert-deftest migemo-regexp-too-big ()
(let* ((migemo-command "cmigemo")
(migemo-options '("-q" "-e"))
(migemo-dictionary
(expand-file-name "../share/migemo/utf-8/migemo-dict"
(file-name-directory
(executable-find migemo-command))))
(migemo-coding-system 'utf-8-unix)
migemo-use-pattern-alist
migemo-use-frequent-pattern-alist
(printable (cl-remove-if-not (lambda (x) (aref printable-chars x))
(number-sequence 0 127)))
;; "Regular expression too big" error.
(invalid-regexp '(?c))
;; Search failure
(search-failed '(?\])) ; (search-failed "[〕]】』]]")
)
(dolist (key printable)
(unless (or (memq key invalid-regexp)
(memq key search-failed))
(with-temp-buffer
(insert (string key))
(goto-char (point-min))
(message "ok: %s" (string key))
(should
(= (re-search-forward (migemo-get-pattern (string key)))
2)))))
(dolist (key invalid-regexp)
(message "invalid-regexp: %s" (string key))
(should-error
(re-search-forward (migemo-get-pattern (string key)))
:type 'invalid-regexp))
(dolist (key search-failed)
(message "search-failed: %s" (string key))
(should-not
(re-search-forward (migemo-get-pattern (string key)) nil t)))
))
(provide 'migemo-tests)
;;; migemo-tests.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment