diff options
| author | Simeon Simeonov | 2024-03-14 22:27:34 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2024-03-14 22:27:34 +0100 |
| commit | 236114bdeab5edab09969e5ad398c32c2738dead (patch) | |
| tree | 42b337b433de9ada45f2aa441833c5cde42c3a1e /.emacs.d/lisp/rust-mode-tests.el | |
| parent | 9fffbc025f80ef22a77ccc62f53baa990568b214 (diff) | |
Upgrade markdown-mode, rust and yasnippet
Diffstat (limited to '.emacs.d/lisp/rust-mode-tests.el')
| -rw-r--r-- | .emacs.d/lisp/rust-mode-tests.el | 202 |
1 files changed, 139 insertions, 63 deletions
diff --git a/.emacs.d/lisp/rust-mode-tests.el b/.emacs.d/lisp/rust-mode-tests.el index e4949b2..62cd261 100644 --- a/.emacs.d/lisp/rust-mode-tests.el +++ b/.emacs.d/lisp/rust-mode-tests.el | |||
| @@ -45,14 +45,23 @@ | |||
| 45 | (put 'rust-compare-code-after-manip 'ert-explainer | 45 | (put 'rust-compare-code-after-manip 'ert-explainer |
| 46 | 'rust-test-explain-bad-manip) | 46 | 'rust-test-explain-bad-manip) |
| 47 | 47 | ||
| 48 | (defun rust-test-manip-code (original point-pos manip-func expected) | 48 | (defun rust-test-manip-code (original manip-pos manip-func expected &optional final-pos) |
| 49 | (with-temp-buffer | 49 | (with-temp-buffer |
| 50 | (rust-mode) | 50 | (rust-mode) |
| 51 | (insert original) | 51 | (insert original) |
| 52 | (goto-char point-pos) | 52 | (goto-char manip-pos) |
| 53 | (funcall manip-func) | 53 | (funcall manip-func) |
| 54 | (should (rust-compare-code-after-manip | 54 | (should (rust-compare-code-after-manip |
| 55 | original point-pos manip-func expected (buffer-string))))) | 55 | original manip-pos manip-func expected (buffer-string))) |
| 56 | (if final-pos | ||
| 57 | (should (equal (point) final-pos))))) | ||
| 58 | |||
| 59 | (defmacro rust-test-with-standard-fill-settings (&rest body) | ||
| 60 | (declare (indent defun)) | ||
| 61 | `(let ((fill-column rust-test-fill-column) | ||
| 62 | (sentence-end-double-space t) | ||
| 63 | (colon-double-space nil)) | ||
| 64 | ,@body)) | ||
| 56 | 65 | ||
| 57 | (defun rust-test-fill-paragraph (unfilled expected &optional start-pos end-pos) | 66 | (defun rust-test-fill-paragraph (unfilled expected &optional start-pos end-pos) |
| 58 | "We're going to run through many scenarios here--the point should be able to be anywhere from the start-pos (defaults to 1) through end-pos (defaults to the length of what was passed in) and (fill-paragraph) should return the same result. It should also work with fill-region from start-pos to end-pos. | 67 | "We're going to run through many scenarios here--the point should be able to be anywhere from the start-pos (defaults to 1) through end-pos (defaults to the length of what was passed in) and (fill-paragraph) should return the same result. It should also work with fill-region from start-pos to end-pos. |
| @@ -78,7 +87,7 @@ Also, the result should be the same regardless of whether the code is at the beg | |||
| 78 | (concat padding-beginning unfilled padding-end) | 87 | (concat padding-beginning unfilled padding-end) |
| 79 | pos | 88 | pos |
| 80 | (lambda () | 89 | (lambda () |
| 81 | (let ((fill-column rust-test-fill-column)) | 90 | (rust-test-with-standard-fill-settings |
| 82 | (fill-paragraph))) | 91 | (fill-paragraph))) |
| 83 | (concat padding-beginning expected padding-end))))) | 92 | (concat padding-beginning expected padding-end))))) |
| 84 | ;; In addition to all the fill-paragraph tests, check that it works using fill-region | 93 | ;; In addition to all the fill-paragraph tests, check that it works using fill-region |
| @@ -86,7 +95,7 @@ Also, the result should be the same regardless of whether the code is at the beg | |||
| 86 | unfilled | 95 | unfilled |
| 87 | start-pos | 96 | start-pos |
| 88 | (lambda () | 97 | (lambda () |
| 89 | (let ((fill-column rust-test-fill-column)) | 98 | (rust-test-with-standard-fill-settings |
| 90 | (fill-region start-pos end-pos))) | 99 | (fill-region start-pos end-pos))) |
| 91 | expected) | 100 | expected) |
| 92 | )) | 101 | )) |
| @@ -1094,6 +1103,25 @@ fn test4();") | |||
| 1094 | (beginning-of-defun 2) | 1103 | (beginning-of-defun 2) |
| 1095 | (should (eq (point) fn-1))))) | 1104 | (should (eq (point) fn-1))))) |
| 1096 | 1105 | ||
| 1106 | (ert-deftest rust-beginning-of-defun-pub-scoped () | ||
| 1107 | (let (fn-1-start fn-1-end fn-2-start fn-2-end) | ||
| 1108 | (with-temp-buffer | ||
| 1109 | (rust-mode) | ||
| 1110 | (setq fn-1-start (point)) | ||
| 1111 | (insert "pub(crate::mod1) fn test2() {}\n") | ||
| 1112 | (setq fn-1-end (point)) | ||
| 1113 | (setq fn-2-start (point)) | ||
| 1114 | (insert "pub(self) fn test1() {}\n") | ||
| 1115 | (setq fn-3-end (point)) | ||
| 1116 | |||
| 1117 | (goto-char (point-max)) | ||
| 1118 | |||
| 1119 | (beginning-of-defun) | ||
| 1120 | (should (eq (point) fn-2-start)) | ||
| 1121 | |||
| 1122 | (beginning-of-defun) | ||
| 1123 | (should (eq (point) fn-1-start))))) | ||
| 1124 | |||
| 1097 | (ert-deftest rust-end-of-defun-from-middle-of-fn () | 1125 | (ert-deftest rust-end-of-defun-from-middle-of-fn () |
| 1098 | (rust-test-motion | 1126 | (rust-test-motion |
| 1099 | rust-test-motion-string | 1127 | rust-test-motion-string |
| @@ -1136,6 +1164,25 @@ fn test4();") | |||
| 1136 | 'between-fn1-fn2 | 1164 | 'between-fn1-fn2 |
| 1137 | #'end-of-defun -2)) | 1165 | #'end-of-defun -2)) |
| 1138 | 1166 | ||
| 1167 | (ert-deftest rust-end-of-defun-pub-scoped () | ||
| 1168 | (let (fn-1-start fn-1-end fn-2-start fn-2-end) | ||
| 1169 | (with-temp-buffer | ||
| 1170 | (rust-mode) | ||
| 1171 | (setq fn-1-start (point)) | ||
| 1172 | (insert "pub(crate::mod1) fn test2() {}\n") | ||
| 1173 | (setq fn-1-end (point)) | ||
| 1174 | (setq fn-2-start (point)) | ||
| 1175 | (insert "pub(self) fn test1() {}\n") | ||
| 1176 | (setq fn-2-end (point)) | ||
| 1177 | |||
| 1178 | (goto-char (point-min)) | ||
| 1179 | |||
| 1180 | (end-of-defun) | ||
| 1181 | (should (eq (point) fn-1-end)) | ||
| 1182 | |||
| 1183 | (end-of-defun) | ||
| 1184 | (should (eq (point) fn-2-end))))) | ||
| 1185 | |||
| 1139 | (ert-deftest rust-mark-defun-from-middle-of-fn () | 1186 | (ert-deftest rust-mark-defun-from-middle-of-fn () |
| 1140 | (rust-test-region | 1187 | (rust-test-region |
| 1141 | rust-test-region-string | 1188 | rust-test-region-string |
| @@ -2752,7 +2799,7 @@ fn foo<T:Fn() -> X<Y>>() -> Z { | |||
| 2752 | ) | 2799 | ) |
| 2753 | )) | 2800 | )) |
| 2754 | 2801 | ||
| 2755 | (ert-deftest rust-test-paren-matching-lt-ops-in-fn-params () | 2802 | (ert-deftest rust-test-paren-matching-lt-ops-in-fn-params-1 () |
| 2756 | (rust-test-matching-parens | 2803 | (rust-test-matching-parens |
| 2757 | " | 2804 | " |
| 2758 | fn foo(x:i32) { | 2805 | fn foo(x:i32) { |
| @@ -2764,7 +2811,7 @@ fn foo(x:i32) { | |||
| 2764 | ) | 2811 | ) |
| 2765 | )) | 2812 | )) |
| 2766 | 2813 | ||
| 2767 | (ert-deftest rust-test-paren-matching-lt-ops-in-fn-params () | 2814 | (ert-deftest rust-test-paren-matching-lt-ops-in-fn-params-2 () |
| 2768 | (rust-test-matching-parens | 2815 | (rust-test-matching-parens |
| 2769 | " | 2816 | " |
| 2770 | fn foo(x:i32) -> bool { | 2817 | fn foo(x:i32) -> bool { |
| @@ -3116,7 +3163,7 @@ macro_c!{ | |||
| 3116 | (syntax-ppss)))) | 3163 | (syntax-ppss)))) |
| 3117 | 3164 | ||
| 3118 | 3165 | ||
| 3119 | (ert-deftest rust-test-in-macro-no-caching () | 3166 | (ert-deftest rust-test-in-macro-around-opening () |
| 3120 | (should-not | 3167 | (should-not |
| 3121 | (with-temp-buffer | 3168 | (with-temp-buffer |
| 3122 | (insert | 3169 | (insert |
| @@ -3125,66 +3172,38 @@ macro_c!{ | |||
| 3125 | struct Boo<D> {} | 3172 | struct Boo<D> {} |
| 3126 | ") | 3173 | ") |
| 3127 | (rust-mode) | 3174 | (rust-mode) |
| 3128 | (search-backward "macro") | 3175 | (search-backward "macro_c") |
| 3129 | ;; do not use the cache | 3176 | (and |
| 3130 | (let ((rust-macro-scopes nil)) | 3177 | (not (rust-in-macro)) |
| 3131 | (rust-in-macro))))) | 3178 | (progn (forward-thing 'symbol 1) (not (rust-in-macro))) |
| 3132 | 3179 | (progn (forward-char 1) (rust-in-macro)) | |
| 3133 | (ert-deftest rust-test-in-macro-fake-cache () | 3180 | (progn (goto-char (point-max)) (rust-in-macro)))))) |
| 3134 | (should | ||
| 3135 | (with-temp-buffer | ||
| 3136 | (insert | ||
| 3137 | "fn foo<A>(a:A) { | ||
| 3138 | macro_c!{ | ||
| 3139 | struct Boo<D> {} | ||
| 3140 | ") | ||
| 3141 | (rust-mode) | ||
| 3142 | (search-backward "macro") | ||
| 3143 | ;; make the cache lie to make the whole buffer in scope | ||
| 3144 | ;; we need to be at paren level 1 for this to work | ||
| 3145 | (let ((rust-macro-scopes `((,(point-min) ,(point-max))))) | ||
| 3146 | (rust-in-macro))))) | ||
| 3147 | |||
| 3148 | (ert-deftest rust-test-in-macro-broken-cache () | ||
| 3149 | (should-error | ||
| 3150 | (with-temp-buffer | ||
| 3151 | (insert | ||
| 3152 | "fn foo<A>(a:A) { | ||
| 3153 | macro_c!{ | ||
| 3154 | struct Boo<D> {} | ||
| 3155 | ") | ||
| 3156 | (rust-mode) | ||
| 3157 | (search-backward "Boo") | ||
| 3158 | ;; do we use the cache at all | ||
| 3159 | (let ((rust-macro-scopes '(I should break))) | ||
| 3160 | (rust-in-macro))))) | ||
| 3161 | 3181 | ||
| 3162 | (ert-deftest rust-test-in-macro-nested () | 3182 | (ert-deftest rust-test-in-macro-nested () |
| 3163 | (should | 3183 | (with-temp-buffer |
| 3164 | (equal | 3184 | (insert |
| 3165 | (with-temp-buffer | 3185 | "macro_rules! outer { |
| 3166 | (insert | ||
| 3167 | "macro_rules! outer { | ||
| 3168 | () => { vec![] }; | 3186 | () => { vec![] }; |
| 3169 | }") | 3187 | }") |
| 3170 | (rust-mode) | 3188 | (rust-mode) |
| 3171 | (rust-macro-scope (point-min) (point-max))) | 3189 | (should (progn (goto-char 20) (not (rust-in-macro)))) |
| 3172 | '((38 40) (20 45))))) | 3190 | (should (progn (goto-char 21) (eq (rust-in-macro) 20))) |
| 3191 | (should (progn (goto-char 38) (eq (rust-in-macro) 20))) | ||
| 3192 | (should (progn (goto-char 39) (eq (rust-in-macro) 38))) | ||
| 3193 | (should (progn (goto-char 40) (eq (rust-in-macro) 20))) | ||
| 3194 | (should (progn (goto-char 44) (eq (rust-in-macro) 20))) | ||
| 3195 | (should (progn (goto-char 45) (not (rust-in-macro)))))) | ||
| 3173 | 3196 | ||
| 3174 | (ert-deftest rust-test-in-macro-not-with-space () | 3197 | (ert-deftest rust-test-in-macro-not-with-space () |
| 3175 | (should | 3198 | (with-temp-buffer |
| 3176 | (equal | 3199 | (insert |
| 3177 | (with-temp-buffer | ||
| 3178 | (insert | ||
| 3179 | "fn foo<T>() { | 3200 | "fn foo<T>() { |
| 3180 | if !(mem::size_of::<T>() > 8) { | 3201 | if !(mem::size_of::<T>() > 8) { |
| 3181 | bar() | 3202 | bar() |
| 3182 | } | 3203 | } |
| 3183 | }") | 3204 | }") |
| 3184 | (rust-mode) | 3205 | (rust-mode) |
| 3185 | (rust-macro-scope (point-min) (point-max))) | 3206 | (should (progn (goto-char 24) (not (rust-in-macro)))))) |
| 3186 | 'empty))) | ||
| 3187 | |||
| 3188 | 3207 | ||
| 3189 | (ert-deftest rust-test-paren-matching-type-with-module-name () | 3208 | (ert-deftest rust-test-paren-matching-type-with-module-name () |
| 3190 | (rust-test-matching-parens | 3209 | (rust-test-matching-parens |
| @@ -3430,19 +3449,72 @@ impl Two<'a> { | |||
| 3430 | "Foo" font-lock-type-face | 3449 | "Foo" font-lock-type-face |
| 3431 | "in" font-lock-keyword-face))) | 3450 | "in" font-lock-keyword-face))) |
| 3432 | 3451 | ||
| 3433 | (ert-deftest rust-test-dbg-wrap-symbol () | 3452 | (ert-deftest rust-test-dbg-wrap-sexp () |
| 3453 | "a valid sexp ahead of current pos" | ||
| 3434 | (rust-test-manip-code | 3454 | (rust-test-manip-code |
| 3435 | "let x = add(first, second);" | 3455 | "let x = add(first, second);" |
| 3436 | 15 | 3456 | 15 |
| 3437 | #'rust-dbg-wrap-or-unwrap | 3457 | #'rust-dbg-wrap-or-unwrap |
| 3438 | "let x = add(dbg!(first), second);")) | 3458 | "let x = add(dbg!(first), second);" |
| 3459 | 24)) | ||
| 3460 | |||
| 3461 | (ert-deftest rust-test-dbg-wrap-sexp-fallback () | ||
| 3462 | "a invalid sexp ahead of current pos" | ||
| 3463 | ;; inside | ||
| 3464 | (rust-test-manip-code | ||
| 3465 | "if let Ok(val) = may_val {}" | ||
| 3466 | 27 | ||
| 3467 | #'rust-dbg-wrap-or-unwrap | ||
| 3468 | "if let Ok(val) = may_val {dbg!()}" | ||
| 3469 | 32) | ||
| 3470 | ;; before | ||
| 3471 | (rust-test-manip-code | ||
| 3472 | "let a = {}" | ||
| 3473 | 9 | ||
| 3474 | #'rust-dbg-wrap-or-unwrap | ||
| 3475 | "let a = dbg!({})" | ||
| 3476 | 17)) | ||
| 3477 | |||
| 3478 | (ert-deftest rust-test-dbg-wrap-empty-line () | ||
| 3479 | (rust-test-manip-code | ||
| 3480 | "let a = 1; | ||
| 3481 | |||
| 3482 | let b = 1;" | ||
| 3483 | 12 | ||
| 3484 | #'rust-dbg-wrap-or-unwrap | ||
| 3485 | "let a = 1; | ||
| 3486 | dbg!() | ||
| 3487 | let b = 1;" | ||
| 3488 | 17)) | ||
| 3489 | |||
| 3490 | (ert-deftest rust-test-dbg-wrap-empty-before-comment () | ||
| 3491 | (rust-test-manip-code | ||
| 3492 | "let a = 1; | ||
| 3493 | // comment | ||
| 3494 | let b = 1;" | ||
| 3495 | 12 | ||
| 3496 | #'rust-dbg-wrap-or-unwrap | ||
| 3497 | "let a = 1; | ||
| 3498 | dbg!()// comment | ||
| 3499 | let b = 1;" | ||
| 3500 | 17) | ||
| 3501 | ;; between statements and comments | ||
| 3502 | (rust-test-manip-code | ||
| 3503 | "let a = 1;// comment | ||
| 3504 | let b = 1;" | ||
| 3505 | 11 | ||
| 3506 | #'rust-dbg-wrap-or-unwrap | ||
| 3507 | "let a = 1;dbg!()// comment | ||
| 3508 | let b = 1;" | ||
| 3509 | 16)) | ||
| 3439 | 3510 | ||
| 3440 | (ert-deftest rust-test-dbg-wrap-symbol-unbalanced () | 3511 | (ert-deftest rust-test-dbg-wrap-symbol-unbalanced () |
| 3441 | (rust-test-manip-code | 3512 | (rust-test-manip-code |
| 3442 | "let x = add((first, second);" | 3513 | "let x = add((first, second);" |
| 3443 | 14 | 3514 | 14 |
| 3444 | #'rust-dbg-wrap-or-unwrap | 3515 | #'rust-dbg-wrap-or-unwrap |
| 3445 | "let x = add((dbg!(first), second);")) | 3516 | "let x = add((dbg!(first), second);" |
| 3517 | 25)) | ||
| 3446 | 3518 | ||
| 3447 | (ert-deftest rust-test-dbg-wrap-region () | 3519 | (ert-deftest rust-test-dbg-wrap-region () |
| 3448 | (rust-test-manip-code | 3520 | (rust-test-manip-code |
| @@ -3453,7 +3525,8 @@ impl Two<'a> { | |||
| 3453 | (push-mark nil t t) | 3525 | (push-mark nil t t) |
| 3454 | (goto-char 26) | 3526 | (goto-char 26) |
| 3455 | (rust-dbg-wrap-or-unwrap)) | 3527 | (rust-dbg-wrap-or-unwrap)) |
| 3456 | "let x = dbg!(add(first, second));")) | 3528 | "let x = dbg!(add(first, second));" |
| 3529 | 33)) | ||
| 3457 | 3530 | ||
| 3458 | (defun rust-test-dbg-unwrap (position) | 3531 | (defun rust-test-dbg-unwrap (position) |
| 3459 | (rust-test-manip-code | 3532 | (rust-test-manip-code |
| @@ -3527,6 +3600,7 @@ impl Two<'a> { | |||
| 3527 | (insert "warning found a -> b\n --> file3.rs:12:34\n\n") | 3600 | (insert "warning found a -> b\n --> file3.rs:12:34\n\n") |
| 3528 | (insert "note: `ZZZ` could also refer to the constant imported here -> b\n --> file4.rs:12:34\n\n") | 3601 | (insert "note: `ZZZ` could also refer to the constant imported here -> b\n --> file4.rs:12:34\n\n") |
| 3529 | (insert " ::: file5.rs:12:34\n\n") | 3602 | (insert " ::: file5.rs:12:34\n\n") |
| 3603 | (insert "thread 'main' panicked at src/file7.rs:12:34:\n\n") | ||
| 3530 | ;; should not match | 3604 | ;; should not match |
| 3531 | (insert "werror found a -> b\n --> no_match.rs:12:34\n\n") | 3605 | (insert "werror found a -> b\n --> no_match.rs:12:34\n\n") |
| 3532 | (insert "error[E0061]: this function takes 1 parameter but 2 parameters were supplied\n --> file6.rs:132:34 | 3606 | (insert "error[E0061]: this function takes 1 parameter but 2 parameters were supplied\n --> file6.rs:132:34 |
| @@ -3545,11 +3619,13 @@ impl Two<'a> { | |||
| 3545 | ("file6.rs" "132" "34" compilation-error "file6.rs:132:34")) | 3619 | ("file6.rs" "132" "34" compilation-error "file6.rs:132:34")) |
| 3546 | (("file5.rs" "12" "34" compilation-info "file5.rs:12:34")) | 3620 | (("file5.rs" "12" "34" compilation-info "file5.rs:12:34")) |
| 3547 | ((like-previous-one "82" back-to-indentation compilation-info "82") | 3621 | ((like-previous-one "82" back-to-indentation compilation-info "82") |
| 3548 | (like-previous-one "132" back-to-indentation compilation-info "132"))) | 3622 | (like-previous-one "132" back-to-indentation compilation-info "132")) |
| 3623 | (("src/file7.rs" "12" "34" nil "src/file7.rs:12:34"))) | ||
| 3549 | (mapcar #'rust-collect-matches | 3624 | (mapcar #'rust-collect-matches |
| 3550 | (list rustc-compilation-regexps | 3625 | (list rustc-compilation-regexps |
| 3551 | rustc-colon-compilation-regexps | 3626 | rustc-colon-compilation-regexps |
| 3552 | rustc-refs-compilation-regexps)))))) | 3627 | rustc-refs-compilation-regexps |
| 3628 | rustc-panics-compilation-regexps)))))) | ||
| 3553 | 3629 | ||
| 3554 | ;; If electric-pair-mode is available, load it and run the tests that use it. If not, | 3630 | ;; If electric-pair-mode is available, load it and run the tests that use it. If not, |
| 3555 | ;; no error--the tests will be skipped. | 3631 | ;; no error--the tests will be skipped. |
