mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
seq: Updates hex parse readability, adds hex test
This commit is contained in:
parent
4e1f945e86
commit
cddd40b4e1
2 changed files with 19 additions and 20 deletions
|
@ -89,25 +89,9 @@ impl FromStr for Number {
|
|||
s = &s[1..];
|
||||
}
|
||||
let is_neg = s.starts_with('-');
|
||||
let is_hex = {
|
||||
// GNU 20.11.2 - Parsing of Floats
|
||||
match s.find("0x") {
|
||||
Some(i) => (true, i),
|
||||
None => match s.find("0X") {
|
||||
Some(i) => (true, i),
|
||||
None => (false, 0),
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
match is_hex {
|
||||
(true, i) => match i <= 1 {
|
||||
false => Err(format!(
|
||||
"invalid hexadecimal argument: {}\nTry '{} --help' for more information.",
|
||||
s.quote(),
|
||||
uucore::execution_phrase(),
|
||||
)),
|
||||
true => match &s.as_bytes()[i + 2] {
|
||||
match s.to_lowercase().find("0x") {
|
||||
Some(i) if i <= 1 => match &s.as_bytes()[i + 2] {
|
||||
b'-' | b'+' => Err(format!(
|
||||
"invalid hexadecimal argument: {}\nTry '{} --help' for more information.",
|
||||
s.quote(),
|
||||
|
@ -133,8 +117,13 @@ impl FromStr for Number {
|
|||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
(false, _) => match s.parse::<BigInt>() {
|
||||
Some(_) => Err(format!(
|
||||
"invalid hexadecimal argument: {}\nTry '{} --help' for more information.",
|
||||
s.quote(),
|
||||
uucore::execution_phrase(),
|
||||
)),
|
||||
|
||||
None => match s.parse::<BigInt>() {
|
||||
Ok(n) => {
|
||||
// If `s` is '-0', then `parse()` returns
|
||||
// `BigInt::zero()`, but we need to return
|
||||
|
|
|
@ -54,6 +54,16 @@ fn test_hex_big_number() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hex_identifier_in_wrong_place() {
|
||||
new_ucmd!()
|
||||
.args(&["1234ABCD0x"])
|
||||
.fails()
|
||||
.no_stdout()
|
||||
.stderr_contains("invalid hexadecimal argument: '1234ABCD0x'")
|
||||
.stderr_contains("for more information.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rejects_nan() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue