summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/rust-mode-tests.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/rust-mode-tests.el')
-rw-r--r--.emacs.d/lisp/rust-mode-tests.el62
1 files changed, 61 insertions, 1 deletions
diff --git a/.emacs.d/lisp/rust-mode-tests.el b/.emacs.d/lisp/rust-mode-tests.el
index 259afb2..c8e3e9a 100644
--- a/.emacs.d/lisp/rust-mode-tests.el
+++ b/.emacs.d/lisp/rust-mode-tests.el
@@ -1979,6 +1979,28 @@ this_is_not_a_string();)"
1979 "union" font-lock-variable-name-face 1979 "union" font-lock-variable-name-face
1980 "bar" font-lock-type-face))) 1980 "bar" font-lock-type-face)))
1981 1981
1982(ert-deftest rust-test-raw-context-sensitive ()
1983 (rust-test-font-lock
1984 "let raw = 7; let foo = &raw const raw; let bar = &raw mut raw;"
1985 '("let" font-lock-keyword-face
1986 ;; The first raw is a variable name.
1987 "raw" font-lock-variable-name-face
1988 "let" font-lock-keyword-face
1989 "foo" font-lock-variable-name-face
1990 "&" rust-ampersand-face
1991 ;; The second raw is a contextual keyword.
1992 "raw" font-lock-keyword-face
1993 "const" font-lock-keyword-face
1994 ;; The third raw is a value.
1995 "let" font-lock-keyword-face
1996 "bar" font-lock-variable-name-face
1997 "&" rust-ampersand-face
1998 ;; The fourth raw is a contextual keyword.
1999 "raw" font-lock-keyword-face
2000 "mut" font-lock-keyword-face
2001 ;; The fifth raw is a value.
2002 )))
2003
1982(ert-deftest indent-method-chains-no-align () 2004(ert-deftest indent-method-chains-no-align ()
1983 (let ((rust-indent-method-chain nil)) (test-indent 2005 (let ((rust-indent-method-chain nil)) (test-indent
1984 " 2006 "
@@ -3693,6 +3715,7 @@ let b = 1;"
3693 (insert "note: `ZZZ` could also refer to the constant imported here -> b\n --> file4.rs:12:34\n\n") 3715 (insert "note: `ZZZ` could also refer to the constant imported here -> b\n --> file4.rs:12:34\n\n")
3694 (insert " ::: file5.rs:12:34\n\n") 3716 (insert " ::: file5.rs:12:34\n\n")
3695 (insert "thread 'main' panicked at src/file7.rs:12:34:\n\n") 3717 (insert "thread 'main' panicked at src/file7.rs:12:34:\n\n")
3718 (insert "thread 'aaa::bbb' (19178688) panicked at crates/a/src/b.rs:13:9:\n\n")
3696 (insert "[src/file8.rs:159:5] symbol_value(SOME_VAR) = Some(\n\n") 3719 (insert "[src/file8.rs:159:5] symbol_value(SOME_VAR) = Some(\n\n")
3697 (insert " at file9.rs:12:34\n\n") 3720 (insert " at file9.rs:12:34\n\n")
3698 ;; should not match 3721 ;; should not match
@@ -3714,7 +3737,8 @@ let b = 1;"
3714 (("file5.rs" "12" "34" compilation-info "file5.rs:12:34")) 3737 (("file5.rs" "12" "34" compilation-info "file5.rs:12:34"))
3715 ((like-previous-one "82" back-to-indentation compilation-info "82") 3738 ((like-previous-one "82" back-to-indentation compilation-info "82")
3716 (like-previous-one "132" back-to-indentation compilation-info "132")) 3739 (like-previous-one "132" back-to-indentation compilation-info "132"))
3717 (("src/file7.rs" "12" "34" nil "src/file7.rs:12:34")) 3740 (("src/file7.rs" "12" "34" nil "src/file7.rs:12:34")
3741 ("crates/a/src/b.rs" "13" "9" nil "crates/a/src/b.rs:13:9"))
3718 (("src/file8.rs" "159" "5" compilation-info "src/file8.rs:159:5")) 3742 (("src/file8.rs" "159" "5" compilation-info "src/file8.rs:159:5"))
3719 (("file9.rs" "12" "34" compilation-info "file9.rs:12:34"))) 3743 (("file9.rs" "12" "34" compilation-info "file9.rs:12:34")))
3720 (mapcar #'rust-collect-matches 3744 (mapcar #'rust-collect-matches
@@ -3809,3 +3833,39 @@ let b = 1;"
3809 (string-match "^C-c C" ,match))) 3833 (string-match "^C-c C" ,match)))
3810 t)) 3834 t))
3811 (should (< 0 match-count))))) 3835 (should (< 0 match-count)))))
3836
3837;; Toggle mutability tests
3838
3839(ert-deftest rust-toggle-mutability-let ()
3840 "Test toggling let <-> let mut."
3841 (with-temp-buffer
3842 (rust-mode)
3843 (insert " let x = 5;")
3844 (rust-toggle-mutability)
3845 (should (string= (buffer-string) " let mut x = 5;"))
3846 (rust-toggle-mutability)
3847 (should (string= (buffer-string) " let x = 5;"))))
3848
3849(ert-deftest rust-toggle-mutability-ref ()
3850 "Test toggling & <-> &mut."
3851 (with-temp-buffer
3852 (rust-mode)
3853 (insert " let y = & x;")
3854 (goto-char (line-end-position))
3855 (rust-toggle-mutability)
3856 (should (string-match-p "&mut " (buffer-string)))
3857 (goto-char (line-end-position))
3858 (rust-toggle-mutability)
3859 (should (string-match-p "& x" (buffer-string)))))
3860
3861(ert-deftest rust-toggle-mutability-self ()
3862 "Test toggling &self <-> &mut self."
3863 (with-temp-buffer
3864 (rust-mode)
3865 (insert " fn foo(&self) {")
3866 (goto-char (line-end-position))
3867 (rust-toggle-mutability)
3868 (should (string-match-p "&mut self" (buffer-string)))
3869 (goto-char (line-end-position))
3870 (rust-toggle-mutability)
3871 (should (string-match-p "&self" (buffer-string)))))