diff --git a/src/io.rs b/src/io.rs index f7bacfd..88f777d 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,5 +1,5 @@ use std::fs::{File, OpenOptions}; -use std::io::{self, BufRead, BufReader, BufWriter, Write}; +use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Write}; use std::path::Path; fn open_input_file(file_name: &str) -> Result, String> { @@ -17,7 +17,7 @@ fn open_input_file(file_name: &str) -> Result, String> { } fn open_stdin() -> Result, String> { - Ok(Box::new(BufReader::new(io::stdin()))) + return Ok(Box::new(BufReader::new(stdin()))); } fn open_input(input: Option) -> Result, String> { @@ -36,7 +36,7 @@ fn open_output_file(output: &str) -> Result, String> { } fn open_stdout() -> Result, String> { - Ok(Box::new(BufWriter::new(io::stdout()))) + Ok(Box::new(BufWriter::new(stdout()))) } fn open_output(output: Option) -> Result, String> { @@ -58,7 +58,6 @@ pub fn open( mod tests { use super::*; - use std::fs; #[test] fn test_input_with_none() { @@ -88,7 +87,7 @@ mod tests { fn test_output_with_not_exist_file() { let output = open_output(Some("testdata/not_exist_file.txt".to_string())); assert!(output.is_ok()); - let _ = fs::remove_file("testdata/not_exist_file.txt"); + let _ = std::fs::remove_file("testdata/not_exist_file.txt"); } #[test] diff --git a/src/uniqer.rs b/src/uniqer.rs index 280ffff..5a98e96 100644 --- a/src/uniqer.rs +++ b/src/uniqer.rs @@ -170,4 +170,20 @@ mod tests { assert!(uniqer.next("previous".to_string()).is_some()); assert!(uniqer.next("hogehoge".to_string()).is_some()); } + + use std::fs::File; + use std::io::BufReader; + use std::vec::Vec; + + #[test] + fn test_filter() { + let dest: Vec = vec![]; + let mut uniqer = construct_uniqer(false, false, false); + let input = BufReader::new(File::open("testdata/test1.txt").unwrap()); + let mut input_box: Box = Box::new(input); + let mut output_box: Box = Box::new(dest); + // uniqer.filter(&mut input_box, &mut output_box); + // How do I get the result from written to the memory?? + // String::from_utf8(dest).unwrap(); + } }