1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #5416 from Luv-Ray/fix-expr-issue5411

`expr`: return 0 for `"" \| ""`
This commit is contained in:
Daniel Hofstetter 2023-10-17 17:30:46 +02:00 committed by GitHub
commit 895e13683c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View file

@ -464,12 +464,15 @@ fn infix_operator_or(values: &[String]) -> String {
assert!(values.len() == 2);
if value_as_bool(&values[0]) {
values[0].clone()
} else {
} else if value_as_bool(&values[1]) {
values[1].clone()
} else {
0.to_string()
}
}
fn infix_operator_and(values: &[String]) -> String {
assert!(values.len() == 2);
if value_as_bool(&values[0]) && value_as_bool(&values[1]) {
values[0].clone()
} else {

View file

@ -143,6 +143,14 @@ fn test_or() {
.args(&["12", "|", "9a", "+", "1"])
.succeeds()
.stdout_only("12\n");
new_ucmd!().args(&["", "|", ""]).run().stdout_only("0\n");
new_ucmd!().args(&["", "|", "0"]).run().stdout_only("0\n");
new_ucmd!().args(&["", "|", "00"]).run().stdout_only("0\n");
new_ucmd!().args(&["", "|", "-0"]).run().stdout_only("0\n");
}
#[test]
@ -152,14 +160,20 @@ fn test_and() {
.succeeds()
.stdout_only("foo\n");
new_ucmd!().args(&["", "&", "1"]).run().stdout_is("0\n");
new_ucmd!().args(&["14", "&", "1"]).run().stdout_is("14\n");
new_ucmd!()
.args(&["14", "&", "1"])
.succeeds()
.stdout_only("14\n");
new_ucmd!()
.args(&["-14", "&", "1"])
.run()
.stdout_is("-14\n");
.succeeds()
.stdout_only("-14\n");
new_ucmd!()
.args(&["-1", "&", "10", "/", "5"])
.succeeds()
.stdout_only("-1\n");
new_ucmd!()
.args(&["0", "&", "a", "/", "5"])
@ -171,10 +185,9 @@ fn test_and() {
.run()
.stdout_only("0\n");
new_ucmd!()
.args(&["-1", "&", "10", "/", "5"])
.succeeds()
.stdout_only("-1\n");
new_ucmd!().args(&["", "&", "1"]).run().stdout_only("0\n");
new_ucmd!().args(&["", "&", ""]).run().stdout_only("0\n");
}
#[test]