test(expand): Add some tests for expand (#1505)

This commit is contained in:
Sylvestre Ledru 2020-05-15 14:21:23 +02:00 committed by Roy Ivy III
parent 0ca5132a06
commit 601690b079
5 changed files with 68 additions and 0 deletions

6
tests/fixtures/expand/with-spaces.txt vendored Normal file
View file

@ -0,0 +1,6 @@
// !note: file contains significant whitespace
// * indentation uses <SPACE> characters
int foo() {
// with spaces
return 0;
}

6
tests/fixtures/expand/with-tab.txt vendored Normal file
View file

@ -0,0 +1,6 @@
// !note: file contains significant whitespace
// * indentation uses <TAB> characters
int main() {
// with tabs
return 0;
}

View file

@ -0,0 +1,7 @@
// !note: file contains significant whitespace
// * indentation uses <TAB> characters
int main() {
// * next line has both a leading & trailing tab
// with tabs=>
return 0;
}

48
tests/test_expand.rs Normal file
View file

@ -0,0 +1,48 @@
use common::util::*;
#[test]
fn test_with_tab() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-tab.txt").run();
assert!(result.success);
assert!(result.stdout.contains(" "));
assert!(!result.stdout.contains("\t"));
}
#[test]
fn test_with_trailing_tab() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-trailing-tab.txt").run();
assert!(result.success);
assert!(result.stdout.contains("with tabs=> "));
assert!(!result.stdout.contains("\t"));
}
#[test]
fn test_with_trailing_tab_i() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-trailing-tab.txt").arg("-i").run();
assert!(result.success);
assert!(result.stdout.contains(" // with tabs=>\t"));
}
#[test]
fn test_with_tab_size() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-tab.txt").arg("--tabs=10").run();
assert!(result.success);
assert!(result.stdout.contains(" "));
}
#[test]
fn test_with_space() {
let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("with-spaces.txt").run();
assert!(result.success);
assert!(result.stdout.contains(" return"));
}

View file

@ -62,6 +62,7 @@ generic! {
"du", test_du;
"echo", test_echo;
"env", test_env;
"expand", test_expand;
"expr", test_expr;
"factor", test_factor;
"false", test_false;