Skip to content

Commit

Permalink
fixup serde errors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Dec 1, 2023
1 parent 8815701 commit ae82f74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
29 changes: 1 addition & 28 deletions src/parse.rs
Expand Up @@ -10,18 +10,7 @@ impl Peak {
pub const Null: Self = Self(b'n');
pub const True: Self = Self(b't');
pub const False: Self = Self(b'f');
pub const Zero: Self = Self(b'0');
pub const One: Self = Self(b'1');
pub const Two: Self = Self(b'2');
pub const Three: Self = Self(b'3');
pub const Four: Self = Self(b'4');
pub const Five: Self = Self(b'5');
pub const Six: Self = Self(b'6');
pub const Seven: Self = Self(b'7');
pub const Eight: Self = Self(b'8');
pub const Nine: Self = Self(b'9');
pub const Minus: Self = Self(b'-');
pub const Plus: Self = Self(b'+');
pub const Infinity: Self = Self(b'I');
pub const NaN: Self = Self(b'N');
pub const String: Self = Self(b'"');
Expand All @@ -35,23 +24,7 @@ impl Peak {
}

pub const fn is_num(self) -> bool {
matches!(
self,
Self::Zero
| Self::One
| Self::Two
| Self::Three
| Self::Four
| Self::Five
| Self::Six
| Self::Seven
| Self::Eight
| Self::Nine
| Self::Minus
| Self::Plus
| Self::Infinity
| Self::NaN
)
self.0.is_ascii_digit() || matches!(self, Self::Minus | Self::Infinity | Self::NaN)
}

pub const fn into_inner(self) -> u8 {
Expand Down
4 changes: 2 additions & 2 deletions src/value.rs
Expand Up @@ -144,9 +144,9 @@ pub(crate) fn take_value(
Ok(NumberAny::Float(float)) => Ok(JsonValue::Float(float)),
Err(e) => {
if !peak.is_num() {
Err(json_error!(ExpectedSomeValue, parser.index).into())
Err(json_error!(ExpectedSomeValue, parser.index))

Check warning on line 147 in src/value.rs

View check run for this annotation

Codecov / codecov/patch

src/value.rs#L147

Added line #L147 was not covered by tests
} else {
Err(e.into())
Err(e)
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/main.rs
Expand Up @@ -630,7 +630,7 @@ fn jiter_object() {
assert_eq!(jiter.next_object().unwrap(), Some("foo"));
assert_eq!(jiter.next_str().unwrap(), "bar");
assert_eq!(jiter.next_key().unwrap(), Some("spam"));
assert_eq!(jiter.next_array().unwrap(), Some(Peak::One));
assert_eq!(jiter.next_array().unwrap().unwrap().into_inner(), b'1');
assert_eq!(jiter.next_int().unwrap(), NumberInt::Int(1));
assert_eq!(jiter.array_step().unwrap(), Some(Peak::Minus));
assert_eq!(jiter.next_int().unwrap(), NumberInt::Int(-2));
Expand Down Expand Up @@ -681,20 +681,20 @@ fn jiter_bytes() {
#[test]
fn jiter_number() {
let mut jiter = Jiter::new(br#" [1, 2.2, 3, 4.1, 5.67]"#, false);
assert_eq!(jiter.next_array().unwrap(), Some(Peak::One));
assert_eq!(jiter.next_array().unwrap().unwrap().into_inner(), b'1');
assert_eq!(jiter.next_int().unwrap(), NumberInt::Int(1));
assert_eq!(jiter.array_step().unwrap(), Some(Peak::Two));
assert_eq!(jiter.array_step().unwrap().unwrap().into_inner(), b'2');
assert_eq!(jiter.next_float().unwrap(), 2.2);
assert_eq!(jiter.array_step().unwrap(), Some(Peak::Three));
assert_eq!(jiter.array_step().unwrap().unwrap().into_inner(), b'3');

let n = jiter.next_number().unwrap();
assert_eq!(n, NumberAny::Int(NumberInt::Int(3)));
let n_float: f64 = n.into();
assert_eq!(n_float, 3.0);

assert_eq!(jiter.array_step().unwrap(), Some(Peak::Four));
assert_eq!(jiter.array_step().unwrap().unwrap().into_inner(), b'4');
assert_eq!(jiter.next_number().unwrap(), NumberAny::Float(4.1));
assert_eq!(jiter.array_step().unwrap(), Some(Peak::Five));
assert_eq!(jiter.array_step().unwrap().unwrap().into_inner(), b'5');
assert_eq!(jiter.next_number_bytes().unwrap(), b"5.67");
assert_eq!(jiter.array_step().unwrap(), None);
jiter.finish().unwrap();
Expand Down Expand Up @@ -726,7 +726,7 @@ fn jiter_empty_array() {
#[test]
fn jiter_trailing_bracket() {
let mut jiter = Jiter::new(b"[1]]", false);
assert_eq!(jiter.next_array().unwrap(), Some(Peak::One));
assert_eq!(jiter.next_array().unwrap().unwrap().into_inner(), b'1');
assert_eq!(jiter.next_int().unwrap(), NumberInt::Int(1));
assert!(jiter.array_step().unwrap().is_none());
let e = jiter.finish().unwrap_err();
Expand Down Expand Up @@ -914,17 +914,17 @@ fn readme_jiter() {
fn jiter_clone() {
let json = r#"[1, 2]"#;
let mut jiter1 = Jiter::new(json.as_bytes(), false);
assert_eq!(jiter1.next_array().unwrap().unwrap(), Peak::One);
assert_eq!(jiter1.next_array().unwrap().unwrap().into_inner(), b'1');
let n = jiter1.next_number().unwrap();
assert_eq!(n, NumberAny::Int(NumberInt::Int(1)));

let mut jiter2 = jiter1.clone();

assert_eq!(jiter1.array_step().unwrap().unwrap(), Peak::Two);
assert_eq!(jiter1.array_step().unwrap().unwrap().into_inner(), b'2');
let n = jiter1.next_number().unwrap();
assert_eq!(n, NumberAny::Int(NumberInt::Int(2)));

assert_eq!(jiter2.array_step().unwrap().unwrap(), Peak::Two);
assert_eq!(jiter2.array_step().unwrap().unwrap().into_inner(), b'2');
let n = jiter2.next_number().unwrap();
assert_eq!(n, NumberAny::Int(NumberInt::Int(2)));

Expand Down

0 comments on commit ae82f74

Please sign in to comment.