-
Notifications
You must be signed in to change notification settings - Fork 35
/
julia-repl-tests.el
68 lines (60 loc) · 2.65 KB
/
julia-repl-tests.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
;;; julia-repl-tests.el --- -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Tamas Papp
;; Author: Tamas Papp <[email protected]>
;; Package-Requires: ((emacs "25.1")(s "1.12"))
(require 'cl-lib)
(require 'julia-repl)
(require 'ert)
(ert-deftest julia-repl-cygwin-rewrite-test ()
(should (equal (julia-repl--path-rewrite "/home/PK/thread_buffers.jl"
julia-repl-cygwin-path-rewrite-rules)
"c:/cygwin64/home/PK/thread_buffers.jl"))
(should (equal (julia-repl--path-rewrite "/cygdrive/c/Users/PK/another.jl"
julia-repl-cygwin-path-rewrite-rules)
"c:/Users/PK/another.jl")))
(cl-defmacro julia-repl--buffer (contents position &body body)
"Make a temporary buffer with ‘contents’ and point at ‘position’, then run ‘body’."
`(with-temp-buffer
(julia-repl-mode)
(insert ,contents)
(goto-char ,position)
,@body))
(defun julia-repl--symbol-extraction (contents position)
"Extract symbols in reverse order from a temporary buffer with
‘contents’ and point at ‘position’."
(julia-repl--buffer contents position (julia-repl--symbols-at-point)))
(ert-deftest julia-repl-symbol-extraction-test ()
(let ((symbols '("Foo" "bar" "baz")))
(should (equal (julia-repl--symbol-extraction "Foo.bar.baz" 13) symbols))
(should (equal (julia-repl--symbol-extraction "Foo.bar.baz " 12) symbols))
(should (equal (julia-repl--symbol-extraction "Foo.bar.baz " 14) nil))
(should (equal (julia-repl--symbol-extraction "Foo.bar.baz " 6) symbols))
(should (equal (julia-repl--symbol-extraction "Foo.bar.baz.( " 12) symbols))
(should (equal (julia-repl--symbol-extraction "Foo.bar.baz.( " 6) symbols))))
(ert-deftest julia-repl-location-rx ()
(let ((str "@ Foo ~/code/Foo/src/Foo.jl:100"))
(should (string-match julia-repl--CR-at str))
(should (equal (match-string 1 str) "Foo"))
(should (equal (match-string 2 str) "~/code/Foo/src/Foo.jl"))
(should (equal (match-string 3 str) "100"))))
(ert-deftest julia-repl-error-locations ()
;; module name, absolute path
(should
(equal
(cdr (s-match julia-repl--CR-at " @ Main.MyModule /tmp/tmp.jl:3"))
'("Main.MyModule" "/tmp/tmp.jl" "3")))
;; tilde in path
(should
(equal
(cdr (s-match julia-repl--CR-at " @ Foo ~/tmp.jl:99"))
'("Foo" "~/tmp.jl" "99")))
;; underscore
(should
(equal
(cdr (s-match julia-repl--CR-at " @ Main.test_loops ~/tmp.jl:7"))
'("Main.test_loops" "~/tmp.jl" "7")))
;; no module
(should
(equal
(cdr (s-match julia-repl--CR-at " @ ~/tmp.jl:7"))
'(nil "~/tmp.jl" "7"))))