Advertisement
ziriuz84

Untitled

Jan 25th, 2024
1,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.41 KB | None | 0 0
  1. use std::fs;
  2. fn open_file(file_path: &str) -> String {
  3.     fs::read_to_string(file_path).expect("Failed to read file")
  4. }
  5. fn main() {
  6.     let contents = open_file("test.txt");
  7.     println!("{}", contents);
  8. }
  9.  
  10. #[cfg(test)]
  11. mod tests {
  12.     use super::*;
  13.  
  14.     #[test]
  15.     fn test_open_file() {
  16.         let content: String = open_file("test.txt");
  17.         assert_eq!(content, "hello world\n");
  18.     }
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement