mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #5324 from cakebaker/expr_fix_and_and_or
expr: interpret numbers != 0 as true for | and &
This commit is contained in:
commit
f31c017275
2 changed files with 20 additions and 3 deletions
|
@ -8,10 +8,10 @@
|
|||
//! * `<https://en.wikipedia.org/wiki/Shunting-yard_algorithm>`
|
||||
//!
|
||||
|
||||
// spell-checker:ignore (ToDO) binop binops ints paren prec multibytes
|
||||
// spell-checker:ignore (ToDO) ints paren prec multibytes
|
||||
|
||||
use num_bigint::BigInt;
|
||||
use num_traits::{One, Zero};
|
||||
use num_traits::Zero;
|
||||
use onig::{Regex, RegexOptions, Syntax};
|
||||
|
||||
use crate::tokens::Token;
|
||||
|
@ -515,7 +515,7 @@ fn value_as_bool(s: &str) -> bool {
|
|||
return false;
|
||||
}
|
||||
match s.parse::<BigInt>() {
|
||||
Ok(n) => n.is_one(),
|
||||
Ok(n) => n != Zero::zero(),
|
||||
Err(_) => true,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,16 @@ fn test_or() {
|
|||
.args(&["foo", "|", "bar"])
|
||||
.succeeds()
|
||||
.stdout_only("foo\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["14", "|", "1"])
|
||||
.succeeds()
|
||||
.stdout_only("14\n");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-14", "|", "1"])
|
||||
.succeeds()
|
||||
.stdout_only("-14\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -123,6 +133,13 @@ fn test_and() {
|
|||
.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"])
|
||||
.run()
|
||||
.stdout_is("-14\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue