2015-05-29 17:47:00 +00:00
|
|
|
use std::process::Command;
|
|
|
|
use util::*;
|
2014-07-28 00:11:49 +00:00
|
|
|
|
|
|
|
static PROGNAME: &'static str = "./unexpand";
|
|
|
|
|
2015-05-29 17:47:00 +00:00
|
|
|
#[path = "common/util.rs"]
|
|
|
|
#[macro_use]
|
|
|
|
mod util;
|
2014-07-28 00:11:49 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_init_0() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t4"]), " 1\n 2\n 3\n 4\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, " 1\n 2\n 3\n\t4\n");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_init_1() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t4"]), " 5\n 6\n 7\n 8\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "\t 5\n\t 6\n\t 7\n\t\t8\n");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_init_list_0() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t2,4"]), " 1\n 2\n 3\n 4\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, " 1\n\t2\n\t 3\n\t\t4\n");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_init_list_1() {
|
|
|
|
// Once the list is exhausted, spaces are not converted anymore
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t2,4"]), " 5\n 6\n 7\n 8\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "\t\t 5\n\t\t 6\n\t\t 7\n\t\t 8\n");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_aflag_0() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["--"]), "e E\nf F\ng G\nh H\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "e E\nf F\ng G\nh H\n");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_aflag_1() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-a"]), "e E\nf F\ng G\nh H\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "e E\nf F\ng\tG\nh\t H\n");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_aflag_2() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t8"]), "e E\nf F\ng G\nh H\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "e E\nf F\ng\tG\nh\t H\n");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_first_only_0() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t3"]), " A B");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "\t\t A\t B");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_first_only_1() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t3", "--first-only"]), " A B");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "\t\t A B");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_trailing_space_0() { // evil
|
|
|
|
// Individual spaces before fields starting with non blanks should not be
|
|
|
|
// converted, unless they are at the beginning of the line.
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t4"]), "123 \t1\n123 1\n123 \n123 ");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "123\t\t1\n123 1\n123 \n123 ");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_trailing_space_1() { // super evil
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t1"]), " abc d e f g ");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "\tabc d e\t\tf\t\tg ");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_spaces_follow_tabs_0() {
|
|
|
|
// The two first spaces can be included into the first tab.
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd, " \t\t A");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "\t\t A");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unexpand_spaces_follow_tabs_1() { // evil
|
|
|
|
// Explanation of what is going on here:
|
|
|
|
// 'a' -> 'a' // first tabstop (1)
|
|
|
|
// ' \t' -> '\t' // second tabstop (4)
|
|
|
|
// ' ' -> '\t' // third tabstop (5)
|
|
|
|
// ' B \t' -> ' B \t' // after the list is exhausted, nothing must change
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-t1,4,5"]), "a \t B \t");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "a\t\t B \t");
|
2014-07-28 00:11:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 06:54:24 +00:00
|
|
|
#[test]
|
|
|
|
fn unexpand_spaces_after_fields() {
|
2015-05-29 17:47:00 +00:00
|
|
|
let mut cmd = Command::new(PROGNAME);
|
2015-05-31 00:53:07 +00:00
|
|
|
let result = run_piped_stdin(&mut cmd.args(&["-a"]), " \t A B C D A\t\n");
|
2015-05-29 17:47:00 +00:00
|
|
|
assert_eq!(result.stdout, "\t\tA B C D\t\t A\t\n");
|
2015-04-29 06:54:24 +00:00
|
|
|
}
|