mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 21:47:46 +00:00
numfmt: add tests for handle_buffer
This commit is contained in:
parent
413bff26f8
commit
1287ce3780
1 changed files with 42 additions and 2 deletions
|
@ -281,7 +281,22 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_options() -> NumfmtOptions {
|
fn get_valid_options() -> NumfmtOptions {
|
||||||
|
NumfmtOptions {
|
||||||
|
transform: TransformOptions {
|
||||||
|
from: Unit::None,
|
||||||
|
to: Unit::None,
|
||||||
|
},
|
||||||
|
padding: 10,
|
||||||
|
header: 0,
|
||||||
|
fields: vec![Range { low: 0, high: 1 }],
|
||||||
|
delimiter: None,
|
||||||
|
round: RoundMethod::Nearest,
|
||||||
|
suffix: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_invalid_options() -> NumfmtOptions {
|
||||||
NumfmtOptions {
|
NumfmtOptions {
|
||||||
transform: TransformOptions {
|
transform: TransformOptions {
|
||||||
from: Unit::Auto,
|
from: Unit::Auto,
|
||||||
|
@ -299,10 +314,35 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn broken_buffer_returns_io_error() {
|
fn broken_buffer_returns_io_error() {
|
||||||
let mock_buffer = MockBuffer {};
|
let mock_buffer = MockBuffer {};
|
||||||
let result = handle_buffer(BufReader::new(mock_buffer), get_options())
|
let result = handle_buffer(BufReader::new(mock_buffer), get_valid_options())
|
||||||
.expect_err("returned Ok after receiving IO error");
|
.expect_err("returned Ok after receiving IO error");
|
||||||
let result_debug = format!("{:?}", result);
|
let result_debug = format!("{:?}", result);
|
||||||
|
let result_display = format!("{}", result);
|
||||||
assert_eq!(result_debug, "IoError(\"broken pipe\")");
|
assert_eq!(result_debug, "IoError(\"broken pipe\")");
|
||||||
|
assert_eq!(result_display, "broken pipe");
|
||||||
assert_eq!(result.code(), 1);
|
assert_eq!(result.code(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_numeric_returns_formatting_error() {
|
||||||
|
let input_value = b"hello";
|
||||||
|
let result = handle_buffer(BufReader::new(&input_value[..]), get_valid_options())
|
||||||
|
.expect_err("returned Ok after receiving improperly formatted input");
|
||||||
|
let result_debug = format!("{:?}", result);
|
||||||
|
let result_display = format!("{}", result);
|
||||||
|
assert_eq!(
|
||||||
|
result_debug,
|
||||||
|
"FormattingError(\"invalid suffix in input: 'hello'\")"
|
||||||
|
);
|
||||||
|
assert_eq!(result_display, "invalid suffix in input: 'hello'");
|
||||||
|
assert_eq!(result.code(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn valid_input_returns_ok() {
|
||||||
|
let input_value = b"165";
|
||||||
|
let result = handle_buffer(BufReader::new(&input_value[..]), get_valid_options());
|
||||||
|
println!("{:?}", result);
|
||||||
|
assert!(result.is_ok(), "did not return Ok for valid input");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue