summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt/tests/writemode
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/rustfmt/tests/writemode
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rustfmt/tests/writemode')
-rw-r--r--src/tools/rustfmt/tests/writemode/source/fn-single-line.rs80
-rw-r--r--src/tools/rustfmt/tests/writemode/source/json.rs80
-rw-r--r--src/tools/rustfmt/tests/writemode/source/modified.rs14
-rw-r--r--src/tools/rustfmt/tests/writemode/source/stdin.rs6
-rw-r--r--src/tools/rustfmt/tests/writemode/target/checkstyle.xml2
-rw-r--r--src/tools/rustfmt/tests/writemode/target/modified.txt5
-rw-r--r--src/tools/rustfmt/tests/writemode/target/output.json1
-rw-r--r--src/tools/rustfmt/tests/writemode/target/stdin.json1
-rw-r--r--src/tools/rustfmt/tests/writemode/target/stdin.xml2
9 files changed, 191 insertions, 0 deletions
diff --git a/src/tools/rustfmt/tests/writemode/source/fn-single-line.rs b/src/tools/rustfmt/tests/writemode/source/fn-single-line.rs
new file mode 100644
index 000000000..ab1e13e17
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/source/fn-single-line.rs
@@ -0,0 +1,80 @@
+// rustfmt-fn_single_line: true
+// rustfmt-emit_mode: checkstyle
+// Test single-line functions.
+
+fn foo_expr() {
+ 1
+}
+
+fn foo_stmt() {
+ foo();
+}
+
+fn foo_decl_local() {
+ let z = 5;
+ }
+
+fn foo_decl_item(x: &mut i32) {
+ x = 3;
+}
+
+ fn empty() {
+
+}
+
+fn foo_return() -> String {
+ "yay"
+}
+
+fn foo_where() -> T where T: Sync {
+ let x = 2;
+}
+
+fn fooblock() {
+ {
+ "inner-block"
+ }
+}
+
+fn fooblock2(x: i32) {
+ let z = match x {
+ _ => 2,
+ };
+}
+
+fn comment() {
+ // this is a test comment
+ 1
+}
+
+fn comment2() {
+ // multi-line comment
+ let z = 2;
+ 1
+}
+
+fn only_comment() {
+ // Keep this here
+}
+
+fn aaaaaaaaaaaaaaaaa_looooooooooooooooooooooong_name() {
+ let z = "aaaaaaawwwwwwwwwwwwwwwwwwwwwwwwwwww";
+}
+
+fn lots_of_space () {
+ 1
+}
+
+fn mac() -> Vec<i32> { vec![] }
+
+trait CoolTypes {
+ fn dummy(&self) {
+ }
+}
+
+trait CoolerTypes { fn dummy(&self) {
+}
+}
+
+fn Foo<T>() where T: Bar {
+}
diff --git a/src/tools/rustfmt/tests/writemode/source/json.rs b/src/tools/rustfmt/tests/writemode/source/json.rs
new file mode 100644
index 000000000..89dcf6941
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/source/json.rs
@@ -0,0 +1,80 @@
+// rustfmt-fn_single_line: true
+// rustfmt-emit_mode: json
+// Test single-line functions.
+
+fn foo_expr() {
+ 1
+}
+
+fn foo_stmt() {
+ foo();
+}
+
+fn foo_decl_local() {
+ let z = 5;
+ }
+
+fn foo_decl_item(x: &mut i32) {
+ x = 3;
+}
+
+ fn empty() {
+
+}
+
+fn foo_return() -> String {
+ "yay"
+}
+
+fn foo_where() -> T where T: Sync {
+ let x = 2;
+}
+
+fn fooblock() {
+ {
+ "inner-block"
+ }
+}
+
+fn fooblock2(x: i32) {
+ let z = match x {
+ _ => 2,
+ };
+}
+
+fn comment() {
+ // this is a test comment
+ 1
+}
+
+fn comment2() {
+ // multi-line comment
+ let z = 2;
+ 1
+}
+
+fn only_comment() {
+ // Keep this here
+}
+
+fn aaaaaaaaaaaaaaaaa_looooooooooooooooooooooong_name() {
+ let z = "aaaaaaawwwwwwwwwwwwwwwwwwwwwwwwwwww";
+}
+
+fn lots_of_space () {
+ 1
+}
+
+fn mac() -> Vec<i32> { vec![] }
+
+trait CoolTypes {
+ fn dummy(&self) {
+ }
+}
+
+trait CoolerTypes { fn dummy(&self) {
+}
+}
+
+fn Foo<T>() where T: Bar {
+}
diff --git a/src/tools/rustfmt/tests/writemode/source/modified.rs b/src/tools/rustfmt/tests/writemode/source/modified.rs
new file mode 100644
index 000000000..948beb348
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/source/modified.rs
@@ -0,0 +1,14 @@
+// rustfmt-write_mode: modified
+// Test "modified" output
+
+fn
+blah
+()
+{ }
+
+
+#[cfg
+( a , b
+)]
+fn
+main() {}
diff --git a/src/tools/rustfmt/tests/writemode/source/stdin.rs b/src/tools/rustfmt/tests/writemode/source/stdin.rs
new file mode 100644
index 000000000..06f8a0c28
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/source/stdin.rs
@@ -0,0 +1,6 @@
+
+fn
+ some( )
+{
+}
+fn main () {}
diff --git a/src/tools/rustfmt/tests/writemode/target/checkstyle.xml b/src/tools/rustfmt/tests/writemode/target/checkstyle.xml
new file mode 100644
index 000000000..05bc3a252
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/target/checkstyle.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<checkstyle version="4.3"><file name="tests/writemode/source/fn-single-line.rs"><error line="5" severity="warning" message="Should be `fn foo_expr() { 1 }`" /><error line="7" severity="warning" message="Should be `fn foo_stmt() { foo(); }`" /><error line="9" severity="warning" message="Should be `fn foo_decl_local() { let z = 5; }`" /><error line="11" severity="warning" message="Should be `fn foo_decl_item(x: &amp;mut i32) { x = 3; }`" /><error line="13" severity="warning" message="Should be `fn empty() {}`" /><error line="15" severity="warning" message="Should be `fn foo_return() -&gt; String { &quot;yay&quot; }`" /><error line="17" severity="warning" message="Should be `fn foo_where() -&gt; T`" /><error line="18" severity="warning" message="Should be `where`" /><error line="19" severity="warning" message="Should be ` T: Sync,`" /><error line="20" severity="warning" message="Should be `{`" /><error line="55" severity="warning" message="Should be `fn lots_of_space() { 1 }`" /><error line="60" severity="warning" message="Should be ` fn dummy(&amp;self) {}`" /><error line="63" severity="warning" message="Should be `trait CoolerTypes {`" /><error line="64" severity="warning" message="Should be ` fn dummy(&amp;self) {}`" /><error line="67" severity="warning" message="Should be `fn Foo&lt;T&gt;()`" /><error line="68" severity="warning" message="Should be `where`" /><error line="69" severity="warning" message="Should be ` T: Bar,`" /><error line="70" severity="warning" message="Should be `{`" /></file></checkstyle>
diff --git a/src/tools/rustfmt/tests/writemode/target/modified.txt b/src/tools/rustfmt/tests/writemode/target/modified.txt
new file mode 100644
index 000000000..5c0539a66
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/target/modified.txt
@@ -0,0 +1,5 @@
+4 4 1
+fn blah() {}
+10 5 2
+#[cfg(a, b)]
+fn main() {}
diff --git a/src/tools/rustfmt/tests/writemode/target/output.json b/src/tools/rustfmt/tests/writemode/target/output.json
new file mode 100644
index 000000000..d8b5467ee
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/target/output.json
@@ -0,0 +1 @@
+[{"name":"tests/writemode/source/json.rs","mismatches":[{"original_begin_line":5,"original_end_line":7,"expected_begin_line":5,"expected_end_line":5,"original":"fn foo_expr() {\n 1\n}\n","expected":"fn foo_expr() { 1 }\n"},{"original_begin_line":9,"original_end_line":11,"expected_begin_line":7,"expected_end_line":7,"original":"fn foo_stmt() {\n foo();\n}\n","expected":"fn foo_stmt() { foo(); }\n"},{"original_begin_line":13,"original_end_line":15,"expected_begin_line":9,"expected_end_line":9,"original":"fn foo_decl_local() {\n let z = 5;\n }\n","expected":"fn foo_decl_local() { let z = 5; }\n"},{"original_begin_line":17,"original_end_line":19,"expected_begin_line":11,"expected_end_line":11,"original":"fn foo_decl_item(x: &mut i32) {\n x = 3;\n}\n","expected":"fn foo_decl_item(x: &mut i32) { x = 3; }\n"},{"original_begin_line":21,"original_end_line":21,"expected_begin_line":13,"expected_end_line":13,"original":" fn empty() {\n","expected":"fn empty() {}\n"},{"original_begin_line":23,"original_end_line":23,"expected_begin_line":15,"expected_end_line":15,"original":"}\n","expected":"fn foo_return() -> String { \"yay\" }\n"},{"original_begin_line":25,"original_end_line":29,"expected_begin_line":17,"expected_end_line":20,"original":"fn foo_return() -> String {\n \"yay\"\n}\n\nfn foo_where() -> T where T: Sync {\n","expected":"fn foo_where() -> T\nwhere\n T: Sync,\n{\n"},{"original_begin_line":64,"original_end_line":66,"expected_begin_line":55,"expected_end_line":55,"original":"fn lots_of_space () {\n 1 \n}\n","expected":"fn lots_of_space() { 1 }\n"},{"original_begin_line":71,"original_end_line":72,"expected_begin_line":60,"expected_end_line":60,"original":" fn dummy(&self) {\n }\n","expected":" fn dummy(&self) {}\n"},{"original_begin_line":75,"original_end_line":75,"expected_begin_line":63,"expected_end_line":64,"original":"trait CoolerTypes { fn dummy(&self) { \n","expected":"trait CoolerTypes {\n fn dummy(&self) {}\n"},{"original_begin_line":77,"original_end_line":77,"expected_begin_line":66,"expected_end_line":66,"original":"}\n","expected":""},{"original_begin_line":79,"original_end_line":79,"expected_begin_line":67,"expected_end_line":70,"original":"fn Foo<T>() where T: Bar {\n","expected":"fn Foo<T>()\nwhere\n T: Bar,\n{\n"}]}]
diff --git a/src/tools/rustfmt/tests/writemode/target/stdin.json b/src/tools/rustfmt/tests/writemode/target/stdin.json
new file mode 100644
index 000000000..dbf2c4863
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/target/stdin.json
@@ -0,0 +1 @@
+[{"name":"<stdin>","mismatches":[{"original_begin_line":1,"original_end_line":6,"expected_begin_line":1,"expected_end_line":2,"original":"\nfn\n some( )\n{\n}\nfn main () {}\n","expected":"fn some() {}\nfn main() {}\n"}]}]
diff --git a/src/tools/rustfmt/tests/writemode/target/stdin.xml b/src/tools/rustfmt/tests/writemode/target/stdin.xml
new file mode 100644
index 000000000..a7301bbc5
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/target/stdin.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<checkstyle version="4.3"><file name="<stdin>"><error line="1" severity="warning" message="Should be `fn some() {}`" /><error line="2" severity="warning" message="Should be `fn main() {}`" /></file></checkstyle>