Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/uu/nl/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ nl-error-invalid-arguments = Invalid arguments supplied.
nl-error-could-not-read-line = could not read line
nl-error-line-number-overflow = line number overflow
nl-error-invalid-line-width = Invalid line number field width: ‘{ $value }’: Numerical result out of range
nl-error-invalid-blank-lines = Invalid line number of blank lines: ‘{ $value }’: Numerical result out of range
nl-error-invalid-regex = invalid regular expression
nl-error-invalid-numbering-style = invalid numbering style: '{ $style }'
nl-error-is-directory = { $path }: Is a directory
1 change: 0 additions & 1 deletion src/uu/nl/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ nl-error-invalid-arguments = Arguments fournis invalides.
nl-error-could-not-read-line = impossible de lire la ligne
nl-error-line-number-overflow = débordement du numéro de ligne
nl-error-invalid-line-width = Largeur de champ de numéro de ligne invalide : ‘{ $value }’ : Résultat numérique hors limites
nl-error-invalid-blank-lines = Nombre de lignes vides invalide : ‘{ $value }’ : Résultat numérique hors limites
nl-error-invalid-regex = expression régulière invalide
nl-error-invalid-numbering-style = style de numérotation invalide : '{ $style }'
nl-error-is-directory = { $path } : Est un répertoire
6 changes: 2 additions & 4 deletions src/uu/nl/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) ->
Some(num) if *num > 0 => settings.number_width = *num,
Some(_) => errs.push(translate!("nl-error-invalid-line-width", "value" => "0")),
}
match opts.get_one::<u64>(options::JOIN_BLANK_LINES) {
None => {}
Some(num) if *num > 0 => settings.join_blank_lines = *num,
Some(_) => errs.push(translate!("nl-error-invalid-blank-lines", "value" => "0")),
if let Some(num) = opts.get_one::<u64>(options::JOIN_BLANK_LINES) {
settings.join_blank_lines = *num;
}
if let Some(num) = opts.get_one::<i64>(options::LINE_INCREMENT) {
settings.line_increment = *num;
Expand Down
1 change: 1 addition & 0 deletions src/uu/nl/src/nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ fn nl<T: Read>(reader: &mut BufReader<T>, stats: &mut Stats, settings: &Settings
// for numbering, and only number the last one
NumberingStyle::All
if line.is_empty()
&& settings.join_blank_lines > 0
&& stats.consecutive_empty_lines % settings.join_blank_lines != 0 =>
{
false
Expand Down
28 changes: 19 additions & 9 deletions tests/by-util/test_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,25 @@ fn test_join_blank_lines() {
}
}

#[test]
fn test_join_blank_lines_zero() {
for arg in ["-l0", "--join-blank-lines=0"] {
new_ucmd!()
.arg(arg)
.arg("--body-numbering=a")
.pipe_in("\n\n\n\n\n\n")
.succeeds()
.stdout_is(concat!(
" 1\t\n",
" 2\t\n",
" 3\t\n",
" 4\t\n",
" 5\t\n",
" 6\t\n",
));
}
}

#[test]
fn test_join_blank_lines_multiple_files() {
let scene = TestScenario::new(util_name!());
Expand All @@ -351,15 +370,6 @@ fn test_join_blank_lines_multiple_files() {
}
}

#[test]
fn test_join_blank_lines_zero() {
for arg in ["-l0", "--join-blank-lines=0"] {
new_ucmd!().arg(arg).fails().stderr_contains(
"Invalid line number of blank lines: ‘0’: Numerical result out of range",
);
}
}

#[test]
fn test_invalid_join_blank_lines() {
for arg in ["-linvalid", "--join-blank-lines=invalid"] {
Expand Down
Loading