mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #8540 from cakebaker/nl_join_blank_lines_allow_zero
nl: allow zero for `--join-blank-lines`
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!());
|
||||
@@ -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"] {
|
||||
|
||||
Reference in New Issue
Block a user