-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdictcc-test.el
63 lines (48 loc) · 2.28 KB
/
dictcc-test.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
;;; dictcc-test --- Tests for `dictcc'
;; Copyright (C) 2015 Marten Lienen
;; This file is not part of GNU Emacs.
;; 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:
;; We are testing various aspects of how `dictcc' parses the translations from
;; the HTML results.
;;; Code:
(require 'dictcc)
(require 'dash)
(require 'f)
(defun dictcc-test--parse-html-string (string)
"Parse STRING as an HTML document."
(let ((doc (with-temp-buffer
(insert string)
(libxml-parse-html-region (point-min) (point-max)))))
(caddr (caddr doc))))
(ert-deftest dictcc-parses-cell-to-translation ()
(let* ((cell (dictcc-test--parse-html-string (f-read-text "test/cell.html")))
(translation (dictcc--translation-from-cell cell)))
(should (equal (dictcc--translation-text translation)
"math"))
(should (-same-items-p (dictcc--translation-tags translation)
(list "Am." "coll." "math." "educ.")))))
(ert-deftest dictcc-parsing-ignores-spaces ()
"This should not error."
(let ((cell (dictcc-test--parse-html-string "<td> </td>")))
(dictcc--translation-from-cell cell)))
(ert-deftest dictcc-multiword-tags-should-be-parsed-as-one ()
(let* ((cell (dictcc-test--parse-html-string
(f-read-text "test/split-tags.html")))
(translation (dictcc--translation-from-cell cell)))
(should (equal (dictcc--translation-tags translation)
(list "also ironic")))))
(ert-deftest dictcc-tags-are-parsed-correctly ()
(should (equal (dictcc--tags-from-string "educ. [Am.] {var} [also ironic]")
(list "educ." "Am." "var" "also ironic"))))
(provide 'dictcc-test)
;;; dictcc-test.el ends here