Merge pull request #4215 from sylvestre/busybox3

factor: trim the input to fix some busybox results
This commit is contained in:
Sylvestre Ledru 2022-12-06 07:53:15 +01:00 committed by GitHub
commit 321866aae9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View file

@ -35,12 +35,16 @@ fn print_factors_str(
w: &mut io::BufWriter<impl io::Write>,
factors_buffer: &mut String,
) -> Result<(), Box<dyn Error>> {
num_str.parse::<u64>().map_err(|e| e.into()).and_then(|x| {
factors_buffer.clear();
writeln!(factors_buffer, "{}:{}", x, factor(x))?;
w.write_all(factors_buffer.as_bytes())?;
Ok(())
})
num_str
.trim()
.parse::<u64>()
.map_err(|e| e.into())
.and_then(|x| {
factors_buffer.clear();
writeln!(factors_buffer, "{}:{}", x, factor(x))?;
w.write_all(factors_buffer.as_bytes())?;
Ok(())
})
}
#[uucore::main]

View file

@ -108,10 +108,10 @@ fn test_cli_args() {
new_ucmd!().args(&["3"]).succeeds().stdout_contains("3: 3");
new_ucmd!()
.args(&["3", "6"])
.args(&["3", "6", " +9"])
.succeeds()
.stdout_contains("3: 3")
.stdout_contains("6: 2 3");
.stdout_contains("9: 3 3");
}
#[test]