coreutils/test/tr.rs

52 lines
1.4 KiB
Rust
Raw Normal View History

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> {
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() {
let out = run("!abcd!", &["a-z", "A-Z"]);
assert_eq!(&out[..], b"!ABCD!");
2014-05-18 15:58:56 +00:00
}
#[test]
fn test_small_set2() {
let out = run("@0123456789", &["0-9", "X"]);
assert_eq!(&out[..], b"@XXXXXXXXXX");
2014-05-18 15:58:56 +00:00
}
#[test]
fn test_unicode() {
let out = run("(,°□°), ┬─┬", &[", ┬─┬", "╯︵┻━┻"]);
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() {
let out = run("aBcD", &["-d", "a-z"]);
assert_eq!(&out[..], b"BD");
2014-05-18 20:20:07 +00:00
}
#[test]
fn test_delete_complement() {
let out = run("aBcD", &["-d", "-c", "a-z"]);
assert_eq!(&out[..], b"ac");
2014-05-18 20:20:07 +00:00
}
2014-05-18 15:58:56 +00:00