aboutsummaryrefslogtreecommitdiffstats
path: root/test/oni-core-test.el
blob: b9cf0d2ee930ee94709d6910e10b5f5568da5626 (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
(require 'oni-core)

(ert-deftest oni-core-move-beginning-of-dwim-moves-to-beginning-of-indentation ()
  "Test that ‘oni-core-move-beginning-of-dwim’ moves to the beginning of indentation."
  (with-temp-buffer
    (emacs-lisp-mode)
    (insert "(defun test-defun ()\n  \"Just testing a function\")")
    (goto-char (point-max))
    (oni-core-move-beginning-of-dwim)
    (should (equal 24 (point)))))

(ert-deftest oni-core-move-beginning-of-dwim-moves-to-beginning-of-line ()
  "Test that ‘oni-core-move-beginning-of-dwim’ moves to the beginning of the line."
  (with-temp-buffer
    (emacs-lisp-mode)
    (insert "(defun test-defun ()\n  \"Just testing a function\")")
    (goto-char (point-max))
    (oni-core-move-beginning-of-dwim)
    (oni-core-move-beginning-of-dwim)
    (should (equal 22 (point)))))

(ert-deftest oni-core-move-beginning-of-dwim-moves-to-beginning-of-indentation-again ()
  "Test that ‘oni-core-move-beginning-of-dwim’ moves to the beginning of indentation again."
  (with-temp-buffer
    (emacs-lisp-mode)
    (insert "(defun test-defun ()\n  \"Just testing a function\")")
    (goto-char (point-max))
    (oni-core-move-beginning-of-dwim)
    (oni-core-move-beginning-of-dwim)
    (oni-core-move-beginning-of-dwim)
    (should (equal 24 (point)))))

(ert-deftest oni-core-move-end-of-dwim-moves-to-end-of-code ()
  "Test that ‘oni-core-move-end-of-dwim’ moves to the end of the code before a comment."
  (with-temp-buffer
    (emacs-lisp-mode)
    (insert "(defun test-defun ()  ;; Just testing\n  \"Just testing a function\")")
    (goto-char (point-min))
    (oni-core-move-end-of-dwim)
    (should (equal 21 (point)))))

(ert-deftest oni-core-move-end-of-dwim-moves-to-end-of-line ()
  "Test that ‘oni-core-move-end-of-dwim’ moves to the end of the line."
  (with-temp-buffer
    (emacs-lisp-mode)
    (insert "(defun test-defun ()  ;; Just testing\n  \"Just testing a function\")")
    (goto-char (point-min))
    (oni-core-move-end-of-dwim)
    (oni-core-move-end-of-dwim)
    (should (equal 38 (point)))))

(ert-deftest oni-core-move-end-of-dwim-moves-to-end-of-code-again ()
  "Test that ‘oni-core-move-end-of-dwim’ moves to the end of the code before a comment again."
  (with-temp-buffer
    (emacs-lisp-mode)
    (insert "(defun test-defun ()  ;; Just testing\n  \"Just testing a function\")")
    (goto-char (point-min))
    (oni-core-move-end-of-dwim)
    (oni-core-move-end-of-dwim)
    (oni-core-move-end-of-dwim)
    (should (equal 21 (point)))))

(ert-deftest oni-core-loading-is-idempotent-recentf-idle-timer ()
  "Test that loading ‘oni-core’ is idempotent in regards to an idle timer."
  ;; We already loaded it with the ‘require’ call above. We load it again so we
  ;; can check that the timer set up in it doesn’t appear twice.
  (load-library "oni-core")
  (let* ((pred (lambda (elt) (eq 'oni-core-recentf-save-list-silently (aref elt 5))))
         (matches (delete nil (mapcar pred timer-idle-list))))
   (should (eq 1 (length matches)))))