summaryrefslogtreecommitdiff
path: root/rust-mode-tests.el
diff options
context:
space:
mode:
authorMicah Chalmer <micah@micahchalmer.net>2014-02-22 22:24:55 -0500
committerMicah Chalmer <micah@micahchalmer.net>2014-02-22 23:06:46 -0500
commitb2c9e05bc9275bc180b0372bd7225b47c525993c (patch)
treeb4211a625e25b9dda09c0b4a68947aa5aa26699b /rust-mode-tests.el
parent08006607ab96e1b4bdfd12ddb43d143d28763e76 (diff)
downloadrust-mode-b2c9e05bc9275bc180b0372bd7225b47c525993c.tar.gz
Emacs: indent relative to enclosing block
This changes the indent to calculate positions relative to the enclosing block (or braced/parenthesized expression), rather than by an absolute nesting level within the whole file. This allows things like this to work: let x = match expr { Pattern => ... } With the old method, only one level of nesting would be added within the match braces, so "Pattern" would have ended up aligned with the match. The other change is that multiple parens/braces on the same line only increase the indent once. This is a very common case for passing closures/procs. The absolute nesting method would do this: spawn(proc() { // Indented out two indent levels... }) whereas the code in this commit does this: spawn(proc() { // Indented out only one level... })
Diffstat (limited to 'rust-mode-tests.el')
-rw-r--r--rust-mode-tests.el64
1 files changed, 64 insertions, 0 deletions
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index c0543b6..bdd7d63 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -452,6 +452,70 @@ fn foo() {
"
))
+(ert-deftest indent-indented-match ()
+ (test-indent
+ "
+fn foo() {
+ let x =
+ match blah {
+ Pattern |
+ Pattern2 => {
+ hello()
+ },
+ _ => whatever
+ };
+ y();
+}
+"
+ ))
+
+(ert-deftest indent-curly-braces-within-parens ()
+ (test-indent
+ "
+fn foo() {
+ let x =
+ foo(bar(|x| {
+ only_one_indent_here();
+ }));
+ y();
+}
+"
+ ))
+
+(ert-deftest indent-weirdly-indented-block ()
+ (rust-test-manip-code
+ "
+fn foo() {
+ {
+this_block_is_over_to_the_left_for_some_reason();
+ }
+
+}
+"
+ 16
+ #'indent-for-tab-command
+ "
+fn foo() {
+ {
+ this_block_is_over_to_the_left_for_some_reason();
+ }
+
+}
+"
+ ))
+
+(ert-deftest indent-multi-line-attrib ()
+ (test-indent
+ "
+#[attrib(
+ this,
+ that,
+ theotherthing)]
+mod function_with_multiline_attribute() {}
+"
+ ))
+
+
;; Make sure that in effort to cover match patterns we don't mistreat || or expressions
(ert-deftest indent-nonmatch-or-expression ()
(test-indent