-
Notifications
You must be signed in to change notification settings - Fork 4
/
tests.el
96 lines (82 loc) · 4.35 KB
/
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
(require 'enlive)
(ert-deftest enlive-test-get-elements-by-class-name ()
(let ((element (enlive-parse "<div id=\"id1\" class=\"cls cls2\"></div>")))
(should (equal (enlive-get-elements-by-class-name element "cls2")
'((div ((id . "id1") (class . "cls cls2"))))))))
(ert-deftest enlive-test-get-element-by-id ()
(let ((element (enlive-parse "<div id=\"id1\" class=\"cls cls2\"><span id=\"id2\"></span></div>")))
(should (equal (enlive-get-element-by-id element "id2")
'(span ((id . "id2")))))))
(ert-deftest enlive-test-get-elements-by-tag-name ()
(let ((element (enlive-parse "<div><span>span</span></div>")))
(should (equal (enlive-get-elements-by-tag-name element 'span)
'((span nil "span"))))))
(ert-deftest enlive-test-find-elements ()
(let ((element (enlive-parse "<div id=\"id1\" class=\"cls cls2\"><span id=\"id2\"></span></div>")))
(should (equal (enlive-find-elements element '((id . "id2")))
'((span ((id . "id2"))))))))
(ert-deftest enlive-test-parse-selector ()
(should (equal (enlive-parse-selector [.cls .cls2])
'((enlive-find-elements node '((class . "cls")))
(enlive-direct-children node)
(enlive-find-elements node '((class . "cls2"))))))
(should (equal (enlive-parse-selector [tag > .cls2])
'((enlive-find-elements node '((tag . "tag")))
(enlive-direct-children node)
(enlive-match-element node '((class . "cls2"))))))
(should (equal (enlive-parse-selector [div *])
'((enlive-find-elements node '((tag . "div")))
(enlive-direct-children node)
(enlive-all node)))))
(ert-deftest enlive-test-query-class ()
(let ((element (enlive-parse "<div id=\"id1\" class=\"cls cls2\"><span class=\"cls3 cls4\"></span></div>")))
(should (equal (enlive-query element [.cls3])
'(span ((class . "cls3 cls4")))))))
(ert-deftest enlive-test-query-id ()
(let ((element (enlive-parse "<div id=\"id1\" class=\"cls cls2\"><span class=\"cls2\" id=\"id2\"></span></div>")))
(should (equal (enlive-query element [:id1 .cls2])
'(span ((class . "cls2") (id . "id2")))))))
(ert-deftest enlive-test-query-nested-classes ()
(let ((element (enlive-parse "<p class=\"cls cls2\">
<i class=\"cls3\"></i>
<i class=\"cls3\">
<i class=\"cls4\">
<i class=\"cls5\"></i>
</i>
</i>
<i class=\"cls3\">
<i class=\"cls4\"></i>
</i>
</p>")))
(should (equal (enlive-query-all element [.cls2 .cls3 .cls4 .cls5])
'((i ((class . "cls5"))))))
(should (equal (enlive-query-all element [.cls2 .cls3 .cls5])
'((i ((class . "cls5"))))))
(should (equal (enlive-query-all element [.cls3 .cls5])
'((i ((class . "cls5"))))))))
(ert-deftest enlive-test-query-tag ()
(let ((element (enlive-parse "<p><a><i></i></a></p>")))
(should (equal (enlive-query element [a i])
'(i nil)))
(should (equal (enlive-query element [i])
'(i nil)))))
(ert-deftest enlive-test-query-asterisk ()
(let ((element (enlive-parse "<span><i class=\"cls\"></i><i></i></span>")))
(should (equal (enlive-query-all element [span *])
'((i ((class . "cls")))
(i nil))))))
(ert-deftest enlive-test-tokenize ()
(should (equal (enlive-tokenize "tag:id.cls.cls2")
'((tag . "tag") (id . "id") (class . "cls") (class . "cls2")))))
(ert-deftest enlive-test-with ()
(enlive-with (enlive-parse "<div class=\"cls\"><span><i></i></span><i></i></div>")
(should (equal (enlive-query-all [.cls i])
'((i nil) (i nil))))))
(ert-deftest enlive-test-let ()
(should
(equal
(enlive-let (enlive-parse "<div><span><i class=\"cls1\"></i></span><span class=\"cls2\"></span></div>")
((el1 [.cls1])
(el2 [.cls2]))
(list (caar el1) (caar el2)))
'(i span))))