2015-01-10 19:31:55 +00:00
|
|
|
#![allow(unstable)]
|
|
|
|
|
2015-01-29 07:29:31 +00:00
|
|
|
use std::old_io::process::Command;
|
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> {
|
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,
|
2014-10-30 09:06:47 +00:00
|
|
|
Err(err) => panic!("{}", err),
|
2014-05-18 15:58:56 +00:00
|
|
|
};
|
|
|
|
po.output
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_toupper() {
|
2014-11-20 19:45:52 +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-11-20 19:45:52 +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-11-20 19:45:52 +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() {
|
2014-11-20 19:45:52 +00:00
|
|
|
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() {
|
2014-11-20 19:45:52 +00:00
|
|
|
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
|
|
|
|