-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmagit-pg-test.el
78 lines (67 loc) · 2.89 KB
/
magit-pg-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
66
67
68
69
70
71
72
73
74
75
76
77
78
;;; -*-coding: utf-8 -*-
;;; testing routines for pretty graph
(require 'cl-lib)
(defconst magit-pg-test-buffer-name "*magit-pg-test*")
(defvar magit-pg-tests (list)
"All defined test functions.")
(defmacro magit-pg-deftest (name output &rest body)
(declare (indent 2))
(let ((vars (list))
(test-sym (intern (concat "magit-pg-testfun-" (symbol-name name))))
(output-str (mapconcat #'identity output "\n"))
(output-sym (gensym)))
(mapc #'(lambda (form) (when (eq (car form) 'setq) (push (cadr form) vars)))
body)
(setq vars (cl-remove-duplicates vars :test #'eq))
`(progn
(defun ,test-sym ()
(let (,@vars
(,output-sym ,output-str))
(with-current-buffer (get-buffer-create magit-pg-test-buffer-name)
(setq mode-name "Magit Log Test")
(erase-buffer)
(toggle-truncate-lines 1)
,@body
(string= (substring-no-properties (buffer-string)) ,output-sym))))
(push ',test-sym magit-pg-tests)
(setq magit-pg-tests (cl-remove-duplicates magit-pg-tests)))))
(defmacro magit-pg-runtest (test)
`(funcall (function
,(intern (concat "magit-pg-testfun-" (symbol-name test))))))
(defun magit-pg-test-empty-commit (hash parents)
"Makes a valid commit with given hash (an object) and
parents (a list)."
(make-magit-pg-commit
:hash hash
:parent-hashes parents))
(magit-pg-deftest mergeleft ("├┬│─┬─╮ "
"│╰┤ │ │ ")
(setq commit (magit-pg-test-empty-commit 1 (list 5 2 3 4)))
(let ((magit-pg-trunks (list 1 2)))
(insert
(magit-pg-print-merge commit (magit-pg-commit-parent-hashes commit)))))
(magit-pg-deftest mergemid ("│╭┼╮│ "
"├╯│╰┤ ")
(setq commit (magit-pg-test-empty-commit 2 (list 4 1 3)))
(let ((magit-pg-trunks (list 1 2 3)))
(insert
(magit-pg-print-merge commit (magit-pg-commit-parent-hashes commit)))))
(magit-pg-deftest mergeright ("╭─┬─│┬┤ "
"│ │ ├╯│ ")
(setq commit (magit-pg-test-empty-commit 4 (list 5 1 2 3)))
(let ((magit-pg-trunks (list nil nil 3 4)))
(insert
(magit-pg-print-merge commit (magit-pg-commit-parent-hashes commit)))))
(magit-pg-deftest branchleft ("├─│─┴─│─┴─│─┴─│─╯ ")
(let ((magit-pg-trunks (list 1 2 1 3 1 4 1 5 1)))
(insert
(magit-pg-print-branches))))
(magit-pg-deftest branchmulti ("├─┴─│─│─│─╯ │ │ │ "
"│ ├─┴─│───╯ │ │ "
"│ │ ├─────┴─╯ ")
(let ((magit-pg-trunks (list 1 1 2 2 3 1 2 3 3)))
(insert
(magit-pg-print-branches))))
(defun magit-pg-test-alltests ()
(cl-reduce #'(lambda (t1 t2) (and t1 t2))
(mapcar #'funcall magit-pg-tests)))