summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/prog/jao-rust.el31
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/prog/jao-rust.el b/lib/prog/jao-rust.el
index 9c08e9b..fdc6b0d 100644
--- a/lib/prog/jao-rust.el
+++ b/lib/prog/jao-rust.el
@@ -40,14 +40,36 @@
(replace-regexp-in-string "/\\(mod\\|lib\\|main\\)$" "")
(string-replace "/" "::"))))
+(defconst jao-rust--test-header-rx
+ (concat "#\\[" (regexp-opt '("test" "quickcheck" "tokio::test") t)))
+
+(defconst jao-rust--test-name-rx "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(")
+
+(defun jao-rust-test-at-point ()
+ (when (looking-at jao-rust--test-name-rx) (match-string-no-properties 3)))
+
+(defun jao-rust-test-before-point ()
+ (save-excursion
+ (when (re-search-backward jao-rust--test-header-rx nil t)
+ (forward-line)
+ (jao-rust-test-at-point))))
+
+(defun jao-rust-test-current ()
+ (interactive)
+ (if-let* ((m (jao-rust-current-module-name))
+ (n (jao-rust-test-before-point)))
+ (let ((rustic-test-arguments (format "-- --exact %s::tests::%s" m n))
+ (rustic-cargo-use-last-stored-arguments t))
+ (rustic-cargo-test))
+ (message "No test before point")))
+
(defun jao-rust-buffer-tests ()
(save-excursion
(goto-char (point-min))
(let ((res '()))
- (while (re-search-forward "#\\[\\(tokio::test\\|test\\|quickcheck\\)" nil t)
+ (while (re-search-forward jao-rust--test-header-rx nil t)
(forward-line)
- (when (looking-at "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(")
- (push (match-string-no-properties 3) res)))
+ (when-let* ((name (jao-rust-test-at-point))) (push name res)))
res)))
(defun jao-rust-test-module ()
@@ -57,7 +79,8 @@
(messages "No tests in this module")
(let* ((mod (jao-rust-current-module-name))
(tests (mapconcat (lambda (x) (format "%s::tests::%s" mod x)) tests " "))
- (rustic-test-arguments (format "-- --exact %s" tests)))
+ (rustic-test-arguments (format "-- --exact %s" tests))
+ (rustic-cargo-use-last-stored-arguments t))
(rustic-cargo-test)))))
(defun jao-rust-test-workspace ()