Skip to content

Commit

Permalink
fmt: add basic tests for split-only, prefix, and skip-prefix args
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWiederhake committed May 5, 2024
1 parent e76f92c commit 3277bcb
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/by-util/test_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,74 @@ fn test_fmt_set_goal_not_contain_width() {
.stdout_is("this is a file with one word per line\n");
}
}

#[test]
fn split_does_not_reflow() {
for arg in ["-s", "-ss", "--split-only"] {
let (at, mut ucmd) = at_and_ucmd!();

Check failure on line 192 in tests/by-util/test_fmt.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo clippy`: unused variable: `at` (file:'tests/by-util/test_fmt.rs', line:192)
ucmd.arg("one-word-per-line.txt")
.arg(arg)
.succeeds()
.stdout_is_fixture("one-word-per-line.txt");
}
}

#[test]
fn prefix_minus() {
for prefix_args in [
vec!["-p-"],
vec!["-p", "-"],
vec!["--prefix=-"],
vec!["--prefix", "-"],
vec!["--pref=-"],
vec!["--pref", "-"],
// Test self-overriding:
vec!["--prefix==", "--prefix=-"],
] {
let (at, mut ucmd) = at_and_ucmd!();

Check failure on line 212 in tests/by-util/test_fmt.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo clippy`: unused variable: `at` (file:'tests/by-util/test_fmt.rs', line:212)
ucmd.args(&prefix_args)
.arg("prefixed-one-word-per-line.txt")
.succeeds()
.stdout_is_fixture("prefixed-one-word-per-line_p-.txt");
}
}

#[test]
fn prefix_equal() {
for prefix_args in [
// FIXME: #6353 vec!["-p="],
vec!["-p", "="],
vec!["--prefix=="],
vec!["--prefix", "="],
vec!["--pref=="],
vec!["--pref", "="],
// Test self-overriding:
vec!["--prefix=-", "--prefix=="],
] {
let (at, mut ucmd) = at_and_ucmd!();

Check failure on line 232 in tests/by-util/test_fmt.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo clippy`: unused variable: `at` (file:'tests/by-util/test_fmt.rs', line:232)
ucmd.args(&prefix_args)
.arg("prefixed-one-word-per-line.txt")
.succeeds()
.stdout_is_fixture("prefixed-one-word-per-line_p=.txt");
}
}

#[test]
fn prefix_equal_skip_prefix_equal_two() {
for prefix_args in [
// FIXME: #6353 vec!["--prefix==", "-P=2"],
vec!["--prefix==", "-P", "=2"],
vec!["--prefix==", "--skip-prefix==2"],
vec!["--prefix==", "--skip-prefix", "=2"],
vec!["--prefix==", "--skip-pref==2"],
vec!["--prefix==", "--skip-pref", "=2"],
// Test self-overriding:
vec!["--prefix==", "--skip-pref", "asdf", "-P", "=2"],
] {
let (at, mut ucmd) = at_and_ucmd!();

Check failure on line 252 in tests/by-util/test_fmt.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo clippy`: unused variable: `at` (file:'tests/by-util/test_fmt.rs', line:252)
ucmd.args(&prefix_args)
.arg("prefixed-one-word-per-line.txt")
.succeeds()
.stdout_is_fixture("prefixed-one-word-per-line_p=_P=2.txt");
}
}
19 changes: 19 additions & 0 deletions tests/fixtures/fmt/prefixed-one-word-per-line.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- this
- is
- a
- file
- with
- one
- word
- per
- line

=1this
=1is
=1a
=2file
=2with
=2one
=3word
=3per
=3line
11 changes: 11 additions & 0 deletions tests/fixtures/fmt/prefixed-one-word-per-line_p-.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- this is a file with one word per line

=1this
=1is
=1a
=2file
=2with
=2one
=3word
=3per
=3line
11 changes: 11 additions & 0 deletions tests/fixtures/fmt/prefixed-one-word-per-line_p=.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- this
- is
- a
- file
- with
- one
- word
- per
- line

=1this 1is 1a 2file 2with 2one 3word 3per 3line
15 changes: 15 additions & 0 deletions tests/fixtures/fmt/prefixed-one-word-per-line_p=_P=2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- this
- is
- a
- file
- with
- one
- word
- per
- line

=1this 1is 1a
=2file
=2with
=2one
=3word 3per 3line

0 comments on commit 3277bcb

Please sign in to comment.