2017-01-26 11:58:31 +00:00
|
|
|
#[macro_use] extern crate lazy_static;
|
|
|
|
extern crate find_folder;
|
|
|
|
use find_folder::Search;
|
|
|
|
|
|
|
|
extern crate unichars;
|
|
|
|
use unichars::*;
|
|
|
|
|
|
|
|
lazy_static! {
|
2017-09-01 10:38:10 +00:00
|
|
|
static ref PATH: ::std::path::PathBuf = { Search::ParentsThenKids(3, 3).for_folder("target").unwrap().join(::std::path::Path::new("debug/pwgenr")) };
|
2017-01-26 11:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! exe {
|
2017-09-01 10:38:10 +00:00
|
|
|
($($arg:expr),*) => {
|
|
|
|
match ::std::process::Command::new(&*PATH)
|
|
|
|
// Start a repetition:
|
|
|
|
$(
|
|
|
|
// Each repeat will contain the following statement, with
|
|
|
|
// $arg replaced with the corresponding expression.
|
|
|
|
.arg($arg)
|
|
|
|
)*
|
|
|
|
.output()
|
|
|
|
.expect("failed to execute process") {
|
|
|
|
::std::process::Output { status: _, stdout: out, stderr: err } => {
|
|
|
|
let out = String::from_utf8(out).unwrap();
|
|
|
|
let err = String::from_utf8(err).unwrap();
|
|
|
|
println!("out\n{}\nerr\n{}", out, err);
|
|
|
|
// skip last empty line
|
|
|
|
(out.rsplit('\n').skip(1).map(|x| x.to_string()).collect::<Vec<_>>(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 11:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn length_amount() {
|
2017-09-01 10:38:10 +00:00
|
|
|
let (out, _) = exe!("19", "15");
|
|
|
|
assert_eq!(out.len(), 15);
|
|
|
|
for line in &out {
|
|
|
|
assert_eq!(line.chars().count(), 19);
|
|
|
|
}
|
2017-01-26 11:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ascii() {
|
2018-10-18 17:14:49 +00:00
|
|
|
let (out, _) = exe!("-c", "ascii", "--", "1", "10");
|
2017-09-01 10:38:10 +00:00
|
|
|
assert_eq!(out.len(), 10);
|
|
|
|
for line in &out {
|
|
|
|
assert_eq!(line.chars().count(), 1);
|
|
|
|
for c in line.chars() {
|
|
|
|
assert!(ASCII.contains(&c));
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 11:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn categories() {
|
2017-09-01 10:38:10 +00:00
|
|
|
let (out, _) = exe!("-c", "box", "arrows", "--", "16", "20");
|
|
|
|
assert_eq!(out.len(), 20);
|
|
|
|
for line in &out {
|
|
|
|
assert_eq!(line.chars().count(), 16);
|
|
|
|
for c in line.chars() {
|
|
|
|
assert!(BOX.contains(&c) || ARROWS.contains(&c));
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 11:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty() {
|
2017-09-01 10:38:10 +00:00
|
|
|
let (out, _) = exe!("0", "0");
|
|
|
|
assert_eq!(out.len(), 0);
|
2017-01-26 11:58:31 +00:00
|
|
|
}
|