2014-05-18 15:58:56 +00:00
|
|
|
use std::io::process::Command;
|
|
|
|
|
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> {
|
2014-07-21 17:08:19 +00:00
|
|
|
let mut process = Command::new(PROGNAME).args(args).spawn().unwrap();
|
2014-05-18 15:58:56 +00:00
|
|
|
|
2014-09-17 03:08:40 +00:00
|
|
|
process.stdin.take().unwrap().write_str(input).unwrap();
|
2014-05-18 15:58:56 +00:00
|
|
|
|
|
|
|
let po = match process.wait_with_output() {
|
|
|
|
Ok(p) => p,
|
|
|
|
Err(err) => fail!("{}", err),
|
|
|
|
};
|
|
|
|
po.output
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_toupper() {
|
2014-05-18 20:20:07 +00:00
|
|
|
let out = run("!abcd!", ["a-z", "A-Z"]);
|
2014-06-20 13:15:44 +00:00
|
|
|
assert_eq!(out.as_slice(), b"!ABCD!");
|
2014-05-18 15:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_small_set2() {
|
2014-05-18 20:20:07 +00:00
|
|
|
let out = run("@0123456789", ["0-9", "X"]);
|
2014-06-20 13:15:44 +00:00
|
|
|
assert_eq!(out.as_slice(), b"@XXXXXXXXXX");
|
2014-05-18 15:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unicode() {
|
2014-05-18 20:20:07 +00:00
|
|
|
let out = run("(,°□°), ┬─┬", [", ┬─┬", "╯︵┻━┻"]);
|
2014-06-20 13:15:44 +00:00
|
|
|
assert_eq!(out.as_slice(), "(╯°□°)╯︵┻━┻".as_bytes());
|
2014-05-18 15:58:56 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 20:20:07 +00:00
|
|
|
#[test]
|
|
|
|
fn test_delete() {
|
|
|
|
let out = run("aBcD", ["-d", "a-z"]);
|
2014-06-20 13:15:44 +00:00
|
|
|
assert_eq!(out.as_slice(), b"BD");
|
2014-05-18 20:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_delete_complement() {
|
|
|
|
let out = run("aBcD", ["-d", "-c", "a-z"]);
|
2014-06-20 13:15:44 +00:00
|
|
|
assert_eq!(out.as_slice(), b"ac");
|
2014-05-18 20:20:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-18 15:58:56 +00:00
|
|
|
|