Skip to content

Commit

Permalink
fix: Match optional +/- prefix on float
Browse files Browse the repository at this point in the history
  • Loading branch information
dezyh authored and epage committed Jan 3, 2024
1 parent 35fdb62 commit 25e2d08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
8 changes: 6 additions & 2 deletions src/ascii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,8 +1367,12 @@ where
alt((
recognize_float,
crate::token::tag_no_case("nan"),
crate::token::tag_no_case("infinity"),
crate::token::tag_no_case("inf"),
(
opt(one_of(['+', '-'])),
crate::token::tag_no_case("infinity"),
)
.recognize(),
(opt(one_of(['+', '-'])), crate::token::tag_no_case("inf")).recognize(),
))
.parse_next(input)
}
Expand Down
29 changes: 11 additions & 18 deletions src/ascii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,24 +566,17 @@ mod complete {

println!("now parsing: {} -> {}", test, expected32);

if (test.starts_with('-') || test.starts_with('+')) && expected32.is_infinite() {
assert!(float::<_, f32, ()>.parse_peek(test.as_bytes()).is_err());
assert!(float::<_, f32, ()>.parse_peek(test).is_err());
assert!(float::<_, f64, ()>.parse_peek(test.as_bytes()).is_err());
assert!(float::<_, f64, ()>.parse_peek(test).is_err());
} else {
assert_parse!(
float.parse_peek(test.as_bytes()),
Ok((&b""[..], expected32))
);
assert_parse!(float.parse_peek(test), Ok(("", expected32)));

assert_parse!(
float.parse_peek(test.as_bytes()),
Ok((&b""[..], expected64))
);
assert_parse!(float.parse_peek(test), Ok(("", expected64)));
}
assert_parse!(
float.parse_peek(test.as_bytes()),
Ok((&b""[..], expected32))
);
assert_parse!(float.parse_peek(test), Ok(("", expected32)));

assert_parse!(
float.parse_peek(test.as_bytes()),
Ok((&b""[..], expected64))
);
assert_parse!(float.parse_peek(test), Ok(("", expected64)));
}

let remaining_exponent = "-1.234E-";
Expand Down

0 comments on commit 25e2d08

Please # to comment.