-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjezebel-tree-test.el
55 lines (46 loc) · 1.71 KB
/
jezebel-tree-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
(require 'jezebel-test-util)
(require 'jezebel-tree)
(ert-deftest jezt-basic-trees ()
(let ((tr (-> (jez-make-empty-tree)
(jez-tree-put 'foo 1)
(jez-tree-put 'bar 2))))
(should-eql (jez-tree-get tr 'bar) 2)
(should-eql (jez-tree-get tr 'foo) 1)))
(defun jezt-make-basic-tree ()
;; N.B. This code may look imperative, but it is in fact purely
;; functional!
(-> (jez-make-empty-tree)
(jez-tree-put 'label 'a)
(jez-tree-append-child)
(jez-tree-put 'label 'amiddle)
(jezt-passthrough tr
(should-error (jez-tree-next-sibling tr)))
(jez-tree-up)
(jez-tree-prepend-child)
(jez-tree-put 'label 'afirst)
(jezt-passthrough tr
(should-error (jez-tree-prev-sibling tr))
(should-eql (-> tr
(jez-tree-next-sibling)
(jez-tree-get 'label))
'amiddle))
(jez-tree-up)
(jez-tree-append-child)
(jez-tree-put 'label 'alast)
(jezt-passthrough tr
(should-error (jez-tree-next-sibling tr))
(should-eql (-> tr
(jez-tree-prev-sibling)
(jez-tree-get 'label))
'amiddle))
(jez-tree-up)))
(ert-deftest jezt-tree-construction ()
(let ((tr (jezt-make-basic-tree)))
(should-error (jez-tree-next-sibling tr))
(should-error (jez-tree-prev-sibling tr))
(should-error (jez-tree-up tr))
(should (jez-tree-root-p tr))
(should-eql (jez-tree-get tr 'label) 'a)
(should-eql (jez-tree-get (jez-tree-first-child tr) 'label) 'afirst)
(should-eql (jez-tree-get (jez-tree-last-child tr) 'label) 'alast)))
(provide 'jezebel-tree-test)