]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(indent-tests): Include a simple Rust indent test
authorChristian Brabandt <cb@256bit.org>
Sun, 28 Dec 2025 14:00:44 +0000 (14:00 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 28 Dec 2025 14:00:44 +0000 (14:00 +0000)
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/indent/testdir/rust.in [new file with mode: 0644]
runtime/indent/testdir/rust.ok [new file with mode: 0644]

diff --git a/runtime/indent/testdir/rust.in b/runtime/indent/testdir/rust.in
new file mode 100644 (file)
index 0000000..848912b
--- /dev/null
@@ -0,0 +1,27 @@
+// vim: set ft=rust ts=8 sw=4 sts=4 et :
+// START_INDENT
+use std::fs::File;
+use std::io::prelude::*;
+use std::path::Path;
+
+fn main() {
+    // Create a path to the desired file
+    let path = Path::new("hello.txt");
+    let display = path.display();
+
+    // Open the path in read-only mode, returns `io::Result<File>`
+    let mut file = match File::open(&path) {
+    Err(why) => panic!("couldn't open {}: {}", display, why),
+       Ok(file) => file,
+    };
+
+    // Read the file contents into a string, returns `io::Result<usize>`
+    let mut s = String::new();
+        match file.read_to_string(&mut s) {
+        Err(why) => panic!("couldn't read {}: {}", display, why),
+        Ok(_) => print!("{} contains:\n{}", display, s),
+        }
+
+    // file goes out of scope, and the "hello.txt" file gets closed
+}
+// END_INDENT
diff --git a/runtime/indent/testdir/rust.ok b/runtime/indent/testdir/rust.ok
new file mode 100644 (file)
index 0000000..ea2a071
--- /dev/null
@@ -0,0 +1,27 @@
+// vim: set ft=rust ts=8 sw=4 sts=4 et :
+// START_INDENT
+use std::fs::File;
+use std::io::prelude::*;
+use std::path::Path;
+
+fn main() {
+    // Create a path to the desired file
+    let path = Path::new("hello.txt");
+    let display = path.display();
+
+    // Open the path in read-only mode, returns `io::Result<File>`
+    let mut file = match File::open(&path) {
+        Err(why) => panic!("couldn't open {}: {}", display, why),
+        Ok(file) => file,
+    };
+
+    // Read the file contents into a string, returns `io::Result<usize>`
+    let mut s = String::new();
+    match file.read_to_string(&mut s) {
+        Err(why) => panic!("couldn't read {}: {}", display, why),
+        Ok(_) => print!("{} contains:\n{}", display, s),
+    }
+
+    // file goes out of scope, and the "hello.txt" file gets closed
+}
+// END_INDENT