mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
csplit: fix up tests and error message for filenames
This commit is contained in:
parent
50cab572db
commit
fc82360f58
2 changed files with 23 additions and 33 deletions
|
@ -4,7 +4,7 @@
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
// spell-checker:ignore (regex) diuox
|
// spell-checker:ignore (regex) diuox
|
||||||
|
|
||||||
use uucore::format::{num_format::UnsignedInt, Format};
|
use uucore::format::{num_format::UnsignedInt, Format, FormatError};
|
||||||
|
|
||||||
use crate::csplit_error::CsplitError;
|
use crate::csplit_error::CsplitError;
|
||||||
|
|
||||||
|
@ -52,8 +52,11 @@ impl SplitName {
|
||||||
None => format!("%0{n_digits}u"),
|
None => format!("%0{n_digits}u"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let format = Format::<UnsignedInt>::parse(format_string)
|
let format = match Format::<UnsignedInt>::parse(format_string) {
|
||||||
.map_err(|_| CsplitError::SuffixFormatIncorrect)?;
|
Ok(format) => Ok(format),
|
||||||
|
Err(FormatError::TooManySpecs(_)) => Err(CsplitError::SuffixFormatTooManyPercents),
|
||||||
|
Err(_) => Err(CsplitError::SuffixFormatIncorrect),
|
||||||
|
}?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
prefix: prefix.as_bytes().to_owned(),
|
prefix: prefix.as_bytes().to_owned(),
|
||||||
|
@ -187,7 +190,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn alternate_form_octal() {
|
fn alternate_form_octal() {
|
||||||
let split_name = SplitName::new(None, Some(String::from("cst-%#10o-")), None).unwrap();
|
let split_name = SplitName::new(None, Some(String::from("cst-%#10o-")), None).unwrap();
|
||||||
assert_eq!(split_name.get(42), "xxcst- 0o52-");
|
assert_eq!(split_name.get(42), "xxcst- 052-");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -199,7 +202,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn alternate_form_upper_hex() {
|
fn alternate_form_upper_hex() {
|
||||||
let split_name = SplitName::new(None, Some(String::from("cst-%#10X-")), None).unwrap();
|
let split_name = SplitName::new(None, Some(String::from("cst-%#10X-")), None).unwrap();
|
||||||
assert_eq!(split_name.get(42), "xxcst- 0x2A-");
|
assert_eq!(split_name.get(42), "xxcst- 0X2A-");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -223,19 +226,19 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn left_adjusted_octal() {
|
fn left_adjusted_octal() {
|
||||||
let split_name = SplitName::new(None, Some(String::from("cst-%-10o-")), None).unwrap();
|
let split_name = SplitName::new(None, Some(String::from("cst-%-10o-")), None).unwrap();
|
||||||
assert_eq!(split_name.get(42), "xxcst-0o52 -");
|
assert_eq!(split_name.get(42), "xxcst-52 -");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn left_adjusted_lower_hex() {
|
fn left_adjusted_lower_hex() {
|
||||||
let split_name = SplitName::new(None, Some(String::from("cst-%-10x-")), None).unwrap();
|
let split_name = SplitName::new(None, Some(String::from("cst-%-10x-")), None).unwrap();
|
||||||
assert_eq!(split_name.get(42), "xxcst-0x2a -");
|
assert_eq!(split_name.get(42), "xxcst-2a -");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn left_adjusted_upper_hex() {
|
fn left_adjusted_upper_hex() {
|
||||||
let split_name = SplitName::new(None, Some(String::from("cst-%-10X-")), None).unwrap();
|
let split_name = SplitName::new(None, Some(String::from("cst-%-10X-")), None).unwrap();
|
||||||
assert_eq!(split_name.get(42), "xxcst-0x2A -");
|
assert_eq!(split_name.get(42), "xxcst-2A -");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1345,8 +1345,9 @@ fn test_line_num_range_with_up_to_match3() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn precision_format() {
|
fn precision_format() {
|
||||||
|
for f in ["%#6.3x", "%0#6.3x"] {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
ucmd.args(&["numbers50.txt", "10", "--suffix-format", "%#6.3x"])
|
ucmd.args(&["numbers50.txt", "10", "--suffix-format", f])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("18\n123\n");
|
.stdout_only("18\n123\n");
|
||||||
|
|
||||||
|
@ -1357,18 +1358,4 @@ fn precision_format() {
|
||||||
assert_eq!(at.read("xx 000"), generate(1, 10));
|
assert_eq!(at.read("xx 000"), generate(1, 10));
|
||||||
assert_eq!(at.read("xx 0x001"), generate(10, 51));
|
assert_eq!(at.read("xx 0x001"), generate(10, 51));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn precision_format2() {
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
|
||||||
ucmd.args(&["numbers50.txt", "10", "--suffix-format", "%0#6.3x"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("18\n123\n");
|
|
||||||
|
|
||||||
let count = glob(&at.plus_as_string("xx*"))
|
|
||||||
.expect("there should be splits created")
|
|
||||||
.count();
|
|
||||||
assert_eq!(count, 2);
|
|
||||||
assert_eq!(at.read("xx 000"), generate(1, 10));
|
|
||||||
assert_eq!(at.read("xx 0x001"), generate(10, 51));
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue