-
Notifications
You must be signed in to change notification settings - Fork 8
/
xmlgen-test.el
65 lines (50 loc) · 2.7 KB
/
xmlgen-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
64
65
;;; xmlgen-test.el --- unit tests for xmlgen -*- lexical-binding: t; -*-
;; Copyright (C) 2017 Google Inc.
;; Author: Google Inc.
;; 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 2 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:
;; Unit tests for xmlgen.el.
;;; Code:
(require 'xmlgen)
(ert-deftest xmlgen-extract-plist ()
(should (equal (xmlgen-extract-plist '(h1 :class "big" "A Title"))
'((h1 "A Title") (:class "big"))))
(should (equal (xmlgen-extract-plist '(hello :big "world"))
'((hello) (:big "world"))))
(should (equal (xmlgen-extract-plist '(big :one 1 :two 2 :three 3))
'((big) (:one 1 :two 2 :three 3))))
(should-error (xmlgen-extract-plist '(hello "world" :how))))
(ert-deftest xmlgen-attr-to-string ()
(should (equal (xmlgen-attr-to-string '(:one "1" :two "2")) " one=\"1\" two=\"2\"")))
(ert-deftest xmlgen-string-escape ()
(should (equal "This & this" (xmlgen-string-escape "This & this")))
(should (equal "This <&> this" (xmlgen-string-escape "This <&> this"))))
(ert-deftest xmlgen ()
(should (equal (xmlgen '(p "this & this")) "<p>this & this</p>"))
(should (equal (xmlgen '(p :class "big")) "<p class=\"big\"/>"))
(should (equal (xmlgen '(p :class "big" "hi")) "<p class=\"big\">hi</p>"))
(should (equal (xmlgen '(h1)) "<h1/>"))
(should (equal (xmlgen '(h1 "Title")) "<h1>Title</h1>"))
(should (equal (xmlgen '(h1 :class "something" "hi"))
(should "<h1 class=\"something\">hi</h1>")))
(should (equal (xmlgen '(div (p "Escaped: &") (!unescape (p "Unescaped: &") (!escape
(p "& escaped")))))
"<div><p>Escaped: &</p><p>Unescaped: &</p><p>& escaped</p></div>"))
(should (equal (xmlgen '(p "hello" "again")) "<p>helloagain</p>")))
(ert-deftest xmlgen--more-complex ()
(should (equal (xmlgen
'(html
(head
(title "hello")
(meta :something "hi"))))
(concat "<html><head><title>hello</title><meta something=\"hi\"/></head></html>"))))
;;; xmlgen-test.el ends here