Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Bartlett authored and Licenser committed Oct 28, 2024
1 parent 07eb6d4 commit 4c151fc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl Error {
match &self.error {
ErrorType::Io(_) | ErrorType::InputTooLarge => true,
ErrorType::InternalError(e) if !matches!(e, crate::InternalError::TapeError) => true,
_ => false
_ => false,
}
}

Expand All @@ -234,7 +234,8 @@ impl Error {
#[must_use]
pub fn is_syntax(&self) -> bool {
// Lazy? maybe but if it aint something else...
matches!(self.error,
matches!(
self.error,
ErrorType::InternalError(crate::InternalError::TapeError) | //This seems to get thrown on some syntax errors
ErrorType::BadKeyType |
ErrorType::ExpectedArrayComma |
Expand All @@ -258,7 +259,8 @@ impl Error {
ErrorType::ExpectedObjectContent |
ErrorType::ExpectedObjectKey |
ErrorType::Overflow |
ErrorType::SimdUnsupported)
ErrorType::SimdUnsupported
)
}
}
impl std::error::Error for Error {}
Expand Down
33 changes: 24 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,8 @@ impl DerefMut for AlignedBuf {

#[cfg(test)]
mod tests {
use serde_ext::Deserialize;
use crate::Deserializer;
use serde_ext::Deserialize;

static JSON: &str = r#"{
"code": 200,
Expand All @@ -1106,14 +1106,14 @@ mod tests {

#[derive(Deserialize, PartialEq, Debug)]
struct TestPayload {
features: Vec<String>
features: Vec<String>,
}

#[derive(Deserialize, PartialEq, Debug)]
struct TestEnvelope {
code: usize,
success: bool,
payload: TestPayload
payload: TestPayload,
}

#[test]
Expand All @@ -1135,11 +1135,18 @@ mod tests {

// proving that value peeking doesn't affect the deserializer

assert_eq!(original_index, d.idx, "Deserializer has been internally modified");
assert_eq!(original_nodes, d.tape.len(), "Deserializer has been internally modified");
assert_eq!(
original_index, d.idx,
"Deserializer has been internally modified"
);
assert_eq!(
original_nodes,
d.tape.len(),
"Deserializer has been internally modified"
);
}

#[test]
#[test]
fn test_deser_restart() {
let mut json = JSON.as_bytes().to_vec();
let mut d = Deserializer::from_slice(&mut json).expect("Invalid JSON");
Expand All @@ -1149,12 +1156,20 @@ mod tests {

let test1 = TestEnvelope::deserialize(&mut d).expect("Deserialization failed");

assert!(original_index != d.idx, "Deserializer has NOT been internally modified");
assert_eq!(original_nodes, d.tape.len(), "Deserializer nodes are NOT intact");
assert!(
original_index != d.idx,
"Deserializer has NOT been internally modified"
);
assert_eq!(
original_nodes,
d.tape.len(),
"Deserializer nodes are NOT intact"
);

d.restart();

let test2 = TestEnvelope::deserialize(&mut d).expect("Deserialization failed");

assert_eq!(test2, test1, "Deserializer is not idempotent");
}}
}
}

0 comments on commit 4c151fc

Please sign in to comment.