From 601690b0791680669cd7d6c371619cf9a00acbbf Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 15 May 2020 14:21:23 +0200 Subject: [PATCH] test(expand): Add some tests for expand (#1505) --- tests/fixtures/expand/with-spaces.txt | 6 +++ tests/fixtures/expand/with-tab.txt | 6 +++ tests/fixtures/expand/with-trailing-tab.txt | 7 +++ tests/test_expand.rs | 48 +++++++++++++++++++++ tests/tests.rs | 1 + 5 files changed, 68 insertions(+) create mode 100644 tests/fixtures/expand/with-spaces.txt create mode 100644 tests/fixtures/expand/with-tab.txt create mode 100644 tests/fixtures/expand/with-trailing-tab.txt create mode 100644 tests/test_expand.rs diff --git a/tests/fixtures/expand/with-spaces.txt b/tests/fixtures/expand/with-spaces.txt new file mode 100644 index 000000000..235ad8cc7 --- /dev/null +++ b/tests/fixtures/expand/with-spaces.txt @@ -0,0 +1,6 @@ +// !note: file contains significant whitespace +// * indentation uses characters +int foo() { + // with spaces + return 0; +} diff --git a/tests/fixtures/expand/with-tab.txt b/tests/fixtures/expand/with-tab.txt new file mode 100644 index 000000000..e6fd89f55 --- /dev/null +++ b/tests/fixtures/expand/with-tab.txt @@ -0,0 +1,6 @@ +// !note: file contains significant whitespace +// * indentation uses characters +int main() { + // with tabs + return 0; +} diff --git a/tests/fixtures/expand/with-trailing-tab.txt b/tests/fixtures/expand/with-trailing-tab.txt new file mode 100644 index 000000000..dfb2c03dd --- /dev/null +++ b/tests/fixtures/expand/with-trailing-tab.txt @@ -0,0 +1,7 @@ +// !note: file contains significant whitespace +// * indentation uses characters +int main() { + // * next line has both a leading & trailing tab + // with tabs=> + return 0; +} diff --git a/tests/test_expand.rs b/tests/test_expand.rs new file mode 100644 index 000000000..a8474e9b3 --- /dev/null +++ b/tests/test_expand.rs @@ -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")); +} diff --git a/tests/tests.rs b/tests/tests.rs index ed1271744..432caf63f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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;