1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

tr: add -c/-d tests

This commit is contained in:
Michael Gehring 2014-05-18 22:20:07 +02:00
parent 5fb465a9cd
commit 358b7a1155

View file

@ -1,7 +1,7 @@
use std::io::process::Command; use std::io::process::Command;
fn run(input: &str, set1: &str, set2: &str) -> Vec<u8> { fn run(input: &str, args: &[&'static str]) -> Vec<u8> {
let mut process = Command::new("build/tr").arg(set1).arg(set2).spawn().unwrap(); let mut process = Command::new("build/tr").args(args).spawn().unwrap();
process.stdin.take_unwrap().write_str(input).unwrap(); process.stdin.take_unwrap().write_str(input).unwrap();
@ -14,20 +14,32 @@ fn run(input: &str, set1: &str, set2: &str) -> Vec<u8> {
#[test] #[test]
fn test_toupper() { fn test_toupper() {
let out = run("!abcd!", "a-z", "A-Z"); let out = run("!abcd!", ["a-z", "A-Z"]);
assert_eq!(out.as_slice(), bytes!("!ABCD!")); assert_eq!(out.as_slice(), bytes!("!ABCD!"));
} }
#[test] #[test]
fn test_small_set2() { fn test_small_set2() {
let out = run("@0123456789", "0-9", "X"); let out = run("@0123456789", ["0-9", "X"]);
assert_eq!(out.as_slice(), bytes!("@XXXXXXXXXX")); assert_eq!(out.as_slice(), bytes!("@XXXXXXXXXX"));
} }
#[test] #[test]
fn test_unicode() { fn test_unicode() {
let out = run("(,°□°), ┬─┬", ", ┬─┬", "╯︵┻━┻"); let out = run("(,°□°), ┬─┬", [", ┬─┬", "╯︵┻━┻"]);
assert_eq!(out.as_slice(), bytes!("(╯°□°)╯︵┻━┻")); assert_eq!(out.as_slice(), bytes!("(╯°□°)╯︵┻━┻"));
} }
#[test]
fn test_delete() {
let out = run("aBcD", ["-d", "a-z"]);
assert_eq!(out.as_slice(), bytes!("BD"));
}
#[test]
fn test_delete_complement() {
let out = run("aBcD", ["-d", "-c", "a-z"]);
assert_eq!(out.as_slice(), bytes!("ac"));
}