Skip to content

Commit

Permalink
Fix number parsing edge case when there's only a single digit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grinkers committed Feb 23, 2024
1 parent 3bc91cf commit 8dd45b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/deserialize/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ fn num_den_from_slice(slice: impl AsRef<str>) -> Option<(i64, u64)> {
}

fn read_number(n: char, chars: &mut iter::Enumerate<core::str::Chars<'_>>) -> Result<Edn, Error> {
let i = chars
.clone()
.next()
.ok_or_else(|| Error::ParseEdn("Could not identify symbol index".to_string()))?
.0;
let c_len = chars
.clone()
.take_while(|(_, c)| !c.is_whitespace() && !DELIMITERS.contains(c))
Expand Down Expand Up @@ -286,7 +281,7 @@ fn read_number(n: char, chars: &mut iter::Enumerate<core::str::Chars<'_>>) -> Re
read_symbol(n.next().unwrap_or(' '), &mut n.enumerate())
}
_ => Err(Error::ParseEdn(format!(
"{number} could not be parsed at char count {i} with radix {radix}"
"{number} could not be parsed with radix {radix}"
))),
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ mod test {

#[test]
fn parse_number() {
assert_eq!(Edn::from_str("7").unwrap(), Edn::UInt(7));
assert_eq!(Edn::from_str("143").unwrap(), Edn::UInt(143));
assert_eq!(Edn::from_str("-435143").unwrap(), Edn::Int(-435_143));
assert_eq!(
Expand Down Expand Up @@ -852,14 +853,14 @@ mod test {
assert_eq!(
Edn::from_str("42invalid123"),
Err(Error::ParseEdn(
"42invalid123 could not be parsed at char count 1 with radix 10".to_string()
"42invalid123 could not be parsed with radix 10".to_string()
))
);

assert_eq!(
Edn::from_str("0xxyz123"),
Err(Error::ParseEdn(
"xyz123 could not be parsed at char count 1 with radix 16".to_string()
"xyz123 could not be parsed with radix 16".to_string()
))
);

Expand Down

0 comments on commit 8dd45b6

Please sign in to comment.