1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

test: allow parsing of bigger numbers

Fixes: tests/misc/test.pl
This commit is contained in:
Sylvestre Ledru 2022-10-02 19:56:54 -10:00
parent f0b8b33dc1
commit 33de6c89db
2 changed files with 50 additions and 2 deletions

View file

@ -245,12 +245,12 @@ fn integers(a: &OsStr, b: &OsStr, op: &OsStr) -> Result<bool, String> {
let format_err = |value: &OsStr| format!("invalid integer {}", value.quote()); let format_err = |value: &OsStr| format!("invalid integer {}", value.quote());
// Parse the two inputs // Parse the two inputs
let a: i64 = a let a: i128 = a
.to_str() .to_str()
.and_then(|s| s.parse().ok()) .and_then(|s| s.parse().ok())
.ok_or_else(|| format_err(a))?; .ok_or_else(|| format_err(a))?;
let b: i64 = b let b: i128 = b
.to_str() .to_str()
.and_then(|s| s.parse().ok()) .and_then(|s| s.parse().ok())
.ok_or_else(|| format_err(b))?; .ok_or_else(|| format_err(b))?;
@ -442,3 +442,28 @@ fn path(path: &OsStr, condition: &PathCondition) -> bool {
PathCondition::Executable => false, // TODO PathCondition::Executable => false, // TODO
} }
} }
#[cfg(test)]
mod tests {
use super::integers;
use std::ffi::OsStr;
#[test]
fn test_integer_op() {
let a = OsStr::new("18446744073709551616");
let b = OsStr::new("0");
assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), false);
let a = OsStr::new("18446744073709551616");
let b = OsStr::new("0");
assert_eq!(integers(a, b, OsStr::new("-gt")).unwrap(), true);
let a = OsStr::new("-1");
let b = OsStr::new("0");
assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), true);
let a = OsStr::new("42");
let b = OsStr::new("42");
assert_eq!(integers(a, b, OsStr::new("-eq")).unwrap(), true);
let a = OsStr::new("42");
let b = OsStr::new("42");
assert_eq!(integers(a, b, OsStr::new("-ne")).unwrap(), false);
}
}

View file

@ -929,3 +929,26 @@ fn test_file_N() {
at.touch("regular_file"); at.touch("regular_file");
scene.ucmd().args(&["-N", "regular_file"]).succeeds(); scene.ucmd().args(&["-N", "regular_file"]).succeeds();
} }
#[test]
fn test_long_integer() {
let scene = TestScenario::new(util_name!());
scene
.ucmd()
.args(&["18446744073709551616", "-eq", "0"])
.fails();
scene
.ucmd()
.args(&["-9223372036854775809", "-ge", "18446744073709551616"])
.fails();
scene
.ucmd()
.args(&[
"'('",
"-9223372036854775809",
"-ge",
"18446744073709551616",
"')'",
])
.fails();
}