summaryrefslogtreecommitdiff
path: root/evil-org-test.el
blob: d8fec1e6290f137b76c65d7f1ac0761af35a1369 (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(require 'evil-org)
(require 'ert)

(defmacro evil-org-with (in &rest body)
  ;; TODO use evil-test-buffer instead
  `(with-temp-buffer
     ;; "hello"
     (evil-mode)
     (org-mode)
     (evil-org-mode)
     (insert ,in)
     (goto-char (point-min))
     (search-forward "|")
     (backward-delete-char 1)
     ,@body
     (insert "|")
     (buffer-substring-no-properties (point-min) (point-max))))

(ert-deftest evil-org-test-beginning-of-line ()
  (should (equal "|hello"
                 (evil-org-with "hello|" (evil-org-beginning-of-line))))
  (should (equal "|*hello\nworld"
                 (evil-org-with "|*hello\nworld" (evil-org-beginning-of-line)))))

;; TODO test with org-special-ctrl-a/e

(ert-deftest evil-org-test-end-of-line ()
  (should (equal "hello|"
                 (evil-org-with "|hello" (evil-org-end-of-line))))
  (should (equal "*hello|\nworld"
                 (evil-org-with "|*hello\nworld" (evil-org-end-of-line)))))

;; TODO test with org-special-ctrl-a/e

(ert-deftest evil-org-test-insert-line-special ()
  (should (equal "* TODO |hello"
                 (evil-org-with "* TODO hello|"
                                (let ((org-special-ctrl-a/e t))
                                  (evil-org-insert-line 1))))))

(ert-deftest evil-org-test-insert-line-no-special ()
 (should (equal "|* TODO hello"
                (evil-org-with "* TODO hello|"
                               (let ((org-special-ctrl-a/e nil))
                                 (evil-org-insert-line 1))))))

(ert-deftest evil-org-test-append-line-special ()
  (should (equal "* hello|  :tag:"
                 (evil-org-with "|* hello  :tag:"
                                (let ((org-special-ctrl-a/e t))
                                  (evil-org-append-line 1))))))

(ert-deftest evil-org-test-append-line-no-special ()
  (should (equal "* hello  :tag\:|"
                 (evil-org-with "|* hello  :tag:"
                                (let ((org-special-ctrl-a/e nil))
                                  (evil-org-append-line 1))))))

(ert-deftest evil-org-test-open-below ()
  (should (equal "hello\n|"
                 (evil-org-with "|hello" (evil-org-open-below 1)))))

(ert-deftest evil-org-test-open-below-heading ()
  (dolist (opener '(evil-org-open-below evil-open-below))
   (should (equal "* heading\nfolded\n|"
                  (evil-org-with "|* heading\nfolded"
                                 (org-overview) ; Make folded to be folded
                                 (call-interactively opener))))))

(ert-deftest evil-org-test-open-below-table ()
  (should (equal "| cell 1 | cell 2 |
| |       |        |\n"
                 (evil-org-with "||cell 1| cell 2|"
                                (call-interactively 'evil-org-open-below)))))

(ert-deftest evil-org-test-open-below-itemlist-continue ()
  (should (equal "- hello\n- |"
                 (evil-org-with "- |hello"
                                (call-interactively 'evil-org-open-below)))))

(ert-deftest evil-org-test-open-below-itemlist-no-continue ()
  (should (equal "- hello\n\n  |\n"
                 (evil-org-with "- hello\n|\n"
                                (call-interactively 'evil-org-open-below)))))

(ert-deftest evil-org-test-open-below-itemlist-last-line ()
  :expected-result :failed
  (should (equal "- hello\n\n  |"
                 (evil-org-with "- hello\n|"
                                (call-interactively 'evil-org-open-below)))))

(ert-deftest evil-org-test-open-below-code ()
  (should (equal
           "- code
   #+BEGIN_SRC emacs-lisp
   (message \"press o now\")
   |
   #+END_SRC"
           (evil-org-with
            "- code
   #+BEGIN_SRC emacs-lisp
   (message |\"press o now\")
   #+END_SRC"
            (call-interactively 'evil-org-open-below)))))

(ert-deftest evil-org-test-delete-list-item ()
  (should (equal "
                  1. emacs
|                  2. evil_org"
                 (evil-org-with "
                  4. emacs
                  5. |evil
                  6. evil_org"
                                (evil-org-delete (line-beginning-position)
                                                 (line-beginning-position 2)
                                                 'line)))))

(ert-deftest evil-org-test-delete-tags ()
  (should (equal "* |heading with some text                                           :testcase:"
                 (evil-org-with
                  "* |Funny heading with some text                                     :testcase:"
                  (let ((w (evil-a-word)))
                    (evil-org-delete (cl-first w) (cl-second w)))))))

;; TODO test x and X
;; TODO test < and >