mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
expr: make substr infallible
Instead of returning an Err it should return the "null string" (in our case that's the empty string) when the offset or length is invalid.
This commit is contained in:
parent
4061ada132
commit
218f523e1b
2 changed files with 41 additions and 24 deletions
|
@ -54,3 +54,32 @@ fn test_and() {
|
|||
|
||||
new_ucmd!().args(&["", "&", "1"]).run().stdout_is("0\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_substr() {
|
||||
new_ucmd!()
|
||||
.args(&["substr", "abc", "1", "1"])
|
||||
.succeeds()
|
||||
.stdout_only("a\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_substr() {
|
||||
new_ucmd!()
|
||||
.args(&["substr", "abc", "0", "1"])
|
||||
.fails()
|
||||
.status_code(1)
|
||||
.stdout_only("\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["substr", "abc", &(std::usize::MAX.to_string() + "0"), "1"])
|
||||
.fails()
|
||||
.status_code(1)
|
||||
.stdout_only("\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["substr", "abc", "0", &(std::usize::MAX.to_string() + "0")])
|
||||
.fails()
|
||||
.status_code(1)
|
||||
.stdout_only("\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue