Skip to content

Commit 33de6c8

Browse files
committed
test: allow parsing of bigger numbers
Fixes: tests/misc/test.pl
1 parent f0b8b33 commit 33de6c8

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/uu/test/src/test.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ fn integers(a: &OsStr, b: &OsStr, op: &OsStr) -> Result<bool, String> {
245245
let format_err = |value: &OsStr| format!("invalid integer {}", value.quote());
246246

247247
// Parse the two inputs
248-
let a: i64 = a
248+
let a: i128 = a
249249
.to_str()
250250
.and_then(|s| s.parse().ok())
251251
.ok_or_else(|| format_err(a))?;
252252

253-
let b: i64 = b
253+
let b: i128 = b
254254
.to_str()
255255
.and_then(|s| s.parse().ok())
256256
.ok_or_else(|| format_err(b))?;
@@ -442,3 +442,28 @@ fn path(path: &OsStr, condition: &PathCondition) -> bool {
442442
PathCondition::Executable => false, // TODO
443443
}
444444
}
445+
446+
#[cfg(test)]
447+
mod tests {
448+
use super::integers;
449+
use std::ffi::OsStr;
450+
451+
#[test]
452+
fn test_integer_op() {
453+
let a = OsStr::new("18446744073709551616");
454+
let b = OsStr::new("0");
455+
assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), false);
456+
let a = OsStr::new("18446744073709551616");
457+
let b = OsStr::new("0");
458+
assert_eq!(integers(a, b, OsStr::new("-gt")).unwrap(), true);
459+
let a = OsStr::new("-1");
460+
let b = OsStr::new("0");
461+
assert_eq!(integers(a, b, OsStr::new("-lt")).unwrap(), true);
462+
let a = OsStr::new("42");
463+
let b = OsStr::new("42");
464+
assert_eq!(integers(a, b, OsStr::new("-eq")).unwrap(), true);
465+
let a = OsStr::new("42");
466+
let b = OsStr::new("42");
467+
assert_eq!(integers(a, b, OsStr::new("-ne")).unwrap(), false);
468+
}
469+
}

tests/by-util/test_test.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,3 +929,26 @@ fn test_file_N() {
929929
at.touch("regular_file");
930930
scene.ucmd().args(&["-N", "regular_file"]).succeeds();
931931
}
932+
933+
#[test]
934+
fn test_long_integer() {
935+
let scene = TestScenario::new(util_name!());
936+
scene
937+
.ucmd()
938+
.args(&["18446744073709551616", "-eq", "0"])
939+
.fails();
940+
scene
941+
.ucmd()
942+
.args(&["-9223372036854775809", "-ge", "18446744073709551616"])
943+
.fails();
944+
scene
945+
.ucmd()
946+
.args(&[
947+
"'('",
948+
"-9223372036854775809",
949+
"-ge",
950+
"18446744073709551616",
951+
"')'",
952+
])
953+
.fails();
954+
}

0 commit comments

Comments
 (0)