Skip to content

Commit 0f1f8f5

Browse files
committed
factor out the logic of julia--should-move-point to a function
1 parent 5229989 commit 0f1f8f5

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

julia-mode-tests.el

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,36 @@
6464
"Assert that TEXT at position POS gets font-locked with FACE in `julia-mode'."
6565
`(should (eq ,face (julia--get-font-lock ,text ,pos))))
6666

67+
(defun julia--should-move-point-helper (text fun from to &optional end arg)
68+
"Takes the same arguments as `julia--should-move-point', returns a cons of the expected and the actual point."
69+
(with-temp-buffer
70+
(julia-mode)
71+
(insert text)
72+
(indent-region (point-min) (point-max))
73+
(goto-char (point-min))
74+
(if (stringp from)
75+
(re-search-forward from)
76+
(goto-char from))
77+
(funcall fun arg)
78+
(let ((actual-to (point))
79+
(expected-to
80+
(if (stringp to)
81+
(progn (goto-char (point-min))
82+
(re-search-forward to)
83+
(if end (goto-char (match-end 0))
84+
(goto-char (match-beginning 0))
85+
(point-at-bol)))
86+
to)))
87+
(cons expected-to actual-to))))
88+
6789
(defmacro julia--should-move-point (text fun from to &optional end arg)
6890
"With TEXT in `julia-mode', after calling FUN, the point should move FROM\
6991
to TO. If FROM is a string, move the point to matching string before calling
7092
function FUN. If TO is a string, match resulting point to point a beginning of
7193
matching line or end of match if END is non-nil. Optional ARG is passed to FUN."
7294
(declare (indent defun))
73-
`(with-temp-buffer
74-
(julia-mode)
75-
(insert ,text)
76-
(indent-region (point-min) (point-max))
77-
(goto-char (point-min))
78-
(if (stringp ,from)
79-
(re-search-forward ,from)
80-
(goto-char ,from))
81-
(funcall ,fun ,arg)
82-
(should (eq (point) (if (stringp ,to)
83-
(progn (goto-char (point-min))
84-
(re-search-forward ,to)
85-
(if ,end (goto-char (match-end 0))
86-
(goto-char (match-beginning 0))
87-
(point-at-bol)))
88-
,to)))))
95+
`(let ((positions (julia--should-move-point-helper ,text ,fun ,from ,to ,end ,arg)))
96+
(should (eq (car positions) (cdr positions)))))
8997

9098
;;; indent tests
9199

0 commit comments

Comments
 (0)