2015-04-29 01:16:11 +00:00
|
|
|
use std::io::Write;
|
|
|
|
use std::process::{Command, Stdio};
|
2014-05-18 15:58:56 +00:00
|
|
|
|
2014-07-21 17:08:19 +00:00
|
|
|
static PROGNAME: &'static str = "./tr";
|
|
|
|
|
2014-05-18 20:20:07 +00:00
|
|
|
fn run(input: &str, args: &[&'static str]) -> Vec<u8> {
|
2015-04-29 01:16:11 +00:00
|
|
|
let mut process = Command::new(PROGNAME)
|
|
|
|
.args(args)
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap_or_else(|e| panic!("{}", e));
|
|
|
|
|
|
|
|
process.stdin.take().unwrap_or_else(|| panic!("Could not take child process stdin"))
|
|
|
|
.write_all(input.as_bytes()).unwrap_or_else(|e| panic!("{}", e));
|
|
|
|
|
|
|
|
let po = process.wait_with_output().unwrap_or_else(|e| panic!("{}", e));
|
|
|
|
po.stdout
|
2014-05-18 15:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_toupper() {
|
2014-11-20 19:45:52 +00:00
|
|
|
let out = run("!abcd!", &["a-z", "A-Z"]);
|
2015-04-29 01:16:11 +00:00
|
|
|
assert_eq!(&out[..], b"!ABCD!");
|
2014-05-18 15:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_small_set2() {
|
2014-11-20 19:45:52 +00:00
|
|
|
let out = run("@0123456789", &["0-9", "X"]);
|
2015-04-29 01:16:11 +00:00
|
|
|
assert_eq!(&out[..], b"@XXXXXXXXXX");
|
2014-05-18 15:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unicode() {
|
2014-11-20 19:45:52 +00:00
|
|
|
let out = run("(,°□°), ┬─┬", &[", ┬─┬", "╯︵┻━┻"]);
|
2015-04-29 01:16:11 +00:00
|
|
|
assert_eq!(&out[..], "(╯°□°)╯︵┻━┻".as_bytes());
|
2014-05-18 15:58:56 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 20:20:07 +00:00
|
|
|
#[test]
|
|
|
|
fn test_delete() {
|
2014-11-20 19:45:52 +00:00
|
|
|
let out = run("aBcD", &["-d", "a-z"]);
|
2015-04-29 01:16:11 +00:00
|
|
|
assert_eq!(&out[..], b"BD");
|
2014-05-18 20:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_delete_complement() {
|
2014-11-20 19:45:52 +00:00
|
|
|
let out = run("aBcD", &["-d", "-c", "a-z"]);
|
2015-04-29 01:16:11 +00:00
|
|
|
assert_eq!(&out[..], b"ac");
|
2014-05-18 20:20:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 15:58:56 +00:00
|
|
|
|