coreutils/test/tr.rs

50 lines
1.1 KiB
Rust
Raw Normal View History

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
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() {
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() {
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() {
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