Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tamada committed Sep 11, 2021
1 parent 9b2898d commit 41870e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions 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<Box<dyn BufRead>, String> {
Expand All @@ -17,7 +17,7 @@ fn open_input_file(file_name: &str) -> Result<Box<dyn BufRead>, String> {
}

fn open_stdin() -> Result<Box<dyn BufRead>, String> {
Ok(Box::new(BufReader::new(io::stdin())))
return Ok(Box::new(BufReader::new(stdin())));
}

fn open_input(input: Option<String>) -> Result<Box<dyn BufRead>, String> {
Expand All @@ -36,7 +36,7 @@ fn open_output_file(output: &str) -> Result<Box<dyn Write>, String> {
}

fn open_stdout() -> Result<Box<dyn Write>, String> {
Ok(Box::new(BufWriter::new(io::stdout())))
Ok(Box::new(BufWriter::new(stdout())))
}

fn open_output(output: Option<String>) -> Result<Box<dyn Write>, String> {
Expand All @@ -58,7 +58,6 @@ pub fn open(

mod tests {
use super::*;
use std::fs;

#[test]
fn test_input_with_none() {
Expand Down Expand Up @@ -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]
Expand Down
16 changes: 16 additions & 0 deletions src/uniqer.rs
Expand Up @@ -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<u8> = vec![];
let mut uniqer = construct_uniqer(false, false, false);
let input = BufReader::new(File::open("testdata/test1.txt").unwrap());
let mut input_box: Box<dyn BufRead> = Box::new(input);
let mut output_box: Box<dyn Write> = 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();
}
}

0 comments on commit 41870e7

Please sign in to comment.