about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <mail@marcusklaas.nl>2016-03-22 10:14:04 +0100
committerMarcus Klaas de Vries <mail@marcusklaas.nl>2016-03-22 10:14:04 +0100
commitca757183fedf8e89286372b91ca074c11d99c4f4 (patch)
tree0637fd97e554176c2cb6180202f12d57edc830d1 /tests
parent4cb043112bb3d4f6212678eb6cf97952f0d68350 (diff)
parent8d299210a6bee1ead0301073c72b5671ce4d8c84 (diff)
Merge pull request #864 from Venti-/fn-density
Add option for vertical function argument list
Diffstat (limited to 'tests')
-rw-r--r--tests/source/fn-custom-7.rs19
-rw-r--r--tests/source/fn_args_density-vertical.rs33
-rw-r--r--tests/target/fn-custom-7.rs32
-rw-r--r--tests/target/fn_args_density-vertical.rs36
4 files changed, 120 insertions, 0 deletions
diff --git a/tests/source/fn-custom-7.rs b/tests/source/fn-custom-7.rs
new file mode 100644
index 00000000000..6a56c440d33
--- /dev/null
+++ b/tests/source/fn-custom-7.rs
@@ -0,0 +1,19 @@
+// rustfmt-fn_args_layout: Block
+// rustfmt-fn_args_density: Vertical
+// rustfmt-fn_arg_indent: Tabbed
+// rustfmt-fn_brace_style: AlwaysNextLine
+
+// Case with only one variable.
+fn foo(a: u8) -> u8 {
+    bar()
+}
+
+// Case with 2 variables and some pre-comments.
+fn foo(a: u8 /* Comment 1 */, b: u8 /* Comment 2 */) -> u8 {
+    bar()
+}
+
+// Case with 2 variables and some post-comments.
+fn foo(/* Comment 1 */ a: u8, /* Comment 2 */ b: u8) -> u8 {
+    bar()
+}
diff --git a/tests/source/fn_args_density-vertical.rs b/tests/source/fn_args_density-vertical.rs
new file mode 100644
index 00000000000..7dd4dcbfc4d
--- /dev/null
+++ b/tests/source/fn_args_density-vertical.rs
@@ -0,0 +1,33 @@
+// rustfmt-fn_args_density: Vertical
+
+// Empty list shoul stay on one line.
+fn do_bar(
+
+) -> u8 {
+    bar()
+}
+
+// A single argument should stay on the same line.
+fn do_bar(
+        a: u8) -> u8 {
+    bar()
+}
+
+// Multiple arguments should each get their own line.
+fn do_bar(a: u8, mut b: u8, c: &u8, d: &mut u8, closure: &Fn(i32) -> i32) -> i32 {
+    // This feature should not affect closures.
+    let bar = |x: i32, y: i32| -> i32 { x + y };
+    bar(a, b)
+}
+
+// If the first argument doesn't fit on the same line with the function name,
+// the whole list should probably be pushed to the next line with hanging
+// indent. That's not what happens though, so check current behaviour instead.
+// In any case, it should maintain single argument per line.
+fn do_this_that_and_the_other_thing(
+        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: u8,
+        b: u8, c: u8, d: u8) {
+    this();
+    that();
+    the_other_thing();
+}
diff --git a/tests/target/fn-custom-7.rs b/tests/target/fn-custom-7.rs
new file mode 100644
index 00000000000..1c4cbde24b8
--- /dev/null
+++ b/tests/target/fn-custom-7.rs
@@ -0,0 +1,32 @@
+// rustfmt-fn_args_layout: Block
+// rustfmt-fn_args_density: Vertical
+// rustfmt-fn_arg_indent: Tabbed
+// rustfmt-fn_brace_style: AlwaysNextLine
+
+// Case with only one variable.
+fn foo(
+    a: u8
+) -> u8
+{
+    bar()
+}
+
+// Case with 2 variables and some pre-comments.
+fn foo(
+    a: u8, // Comment 1
+    b: u8 // Comment 2
+) -> u8
+{
+    bar()
+}
+
+// Case with 2 variables and some post-comments.
+fn foo(
+    // Comment 1
+    a: u8,
+    // Comment 2
+    b: u8
+) -> u8
+{
+    bar()
+}
diff --git a/tests/target/fn_args_density-vertical.rs b/tests/target/fn_args_density-vertical.rs
new file mode 100644
index 00000000000..250d32654e5
--- /dev/null
+++ b/tests/target/fn_args_density-vertical.rs
@@ -0,0 +1,36 @@
+// rustfmt-fn_args_density: Vertical
+
+// Empty list shoul stay on one line.
+fn do_bar() -> u8 {
+    bar()
+}
+
+// A single argument should stay on the same line.
+fn do_bar(a: u8) -> u8 {
+    bar()
+}
+
+// Multiple arguments should each get their own line.
+fn do_bar(a: u8,
+          mut b: u8,
+          c: &u8,
+          d: &mut u8,
+          closure: &Fn(i32) -> i32)
+          -> i32 {
+    // This feature should not affect closures.
+    let bar = |x: i32, y: i32| -> i32 { x + y };
+    bar(a, b)
+}
+
+// If the first argument doesn't fit on the same line with the function name,
+// the whole list should probably be pushed to the next line with hanging
+// indent. That's not what happens though, so check current behaviour instead.
+// In any case, it should maintain single argument per line.
+fn do_this_that_and_the_other_thing(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: u8,
+                                    b: u8,
+                                    c: u8,
+                                    d: u8) {
+    this();
+    that();
+    the_other_thing();
+}