summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-12-03 21:50:28 -0600
committerToby Vincent <tobyv13@gmail.com>2022-12-03 21:50:28 -0600
commite2c6d5e4aa9c093fb216e8d103f4e7182361d650 (patch)
tree63101e8e5e426841faa5a557439a100527a3dc1b
parentd957268920841101a5dd2621ee779a0a7e72a90a (diff)
test: finish impl test_process_input
-rw-r--r--src/lib.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0ef1b4c..ab3002d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -107,26 +107,14 @@ fn parse_nonprinting_char(mut c: u8) -> Vec<u8> {
mod test {
use super::*;
- use std::{
- io::{BufWriter, Write},
- process::{Command, Stdio},
- };
+ use std::process::{Command, Stdio};
#[test]
- fn test_nonprinting_char() {
- let perl_exp = r#"\
- for( my $i=0 ; $i < 256; $i++ ) {
- print ( sprintf( "%c is %d %x", $i, $i ,$i ) );
- }"#;
-
- let perl_stdout = Command::new("perl")
- .arg("-e")
- .arg(perl_exp)
- .output()
- .unwrap()
- .stdout;
-
- println!("{:?}", perl_stdout);
+ fn test_process_input() {
+ let input = (0..255_u8)
+ .map(|i| format!("{}", i as char))
+ .collect::<Vec<String>>()
+ .join("\n");
let cat_child = Command::new("cat")
.arg("-")
@@ -136,20 +124,30 @@ mod test {
.spawn()
.unwrap();
- BufWriter::new(cat_child.stdin.as_ref().unwrap())
- .write_all(&perl_stdout)
+ cat_child
+ .stdin
+ .as_ref()
+ .unwrap()
+ .write_all(input.as_bytes())
.unwrap();
- let cat_output = cat_child.wait_with_output().unwrap().stdout;
+ let cat_output = cat_child.wait_with_output().unwrap();
+ let cat_result = String::from_utf8(cat_output.stdout).unwrap();
- let mut catr_output = Vec::new();
let opts = Opts {
show_nonprinting: true,
..Default::default()
};
- process_input(&*perl_stdout, &mut catr_output, &opts).unwrap();
+ let mut writer = Vec::new();
+
+ process_input(input.as_bytes(), &mut writer, &opts).unwrap();
+
+ let result = String::from_utf8(writer).unwrap();
- assert_eq!(cat_output, catr_output)
+ cat_result
+ .lines()
+ .zip(result.lines())
+ .for_each(|(c_cat, c)| assert_eq!(c_cat, c));
}
}