Skip to content

Commit

Permalink
Obey clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <heinz@licenser.net>
  • Loading branch information
Licenser committed Dec 1, 2022
1 parent 6df5645 commit 8a9169b
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 236 deletions.
391 changes: 193 additions & 198 deletions src/lib.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ macro_rules! json_internal_owned {
let len = json_internal_owned!(@object @count [@entries $(($value => $($key)+))*]);
$object = $crate::value::owned::Object::with_capacity(len);
$(
#[allow(clippy::let_underscore_drop)]
let _ = $object.insert(($($key)+).into(), $value);
)*
};
Expand Down Expand Up @@ -784,6 +785,7 @@ macro_rules! json_internal_borrowed {
let len = json_internal_borrowed!(@object @count [@entries $(($value => $($key)+))*]);
$object = $crate::value::borrowed::Object::with_capacity(len);
$(
#[allow(clippy::let_underscore_drop)]
let _ = $object.insert(($($key)+).into(), $value);
)*
};
Expand Down
66 changes: 36 additions & 30 deletions src/numberparse/correct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,27 +383,25 @@ mod test {
to_value(val)
}

#[allow(clippy::float_cmp)]
#[test]
fn float() {
fn float() -> Result<(), crate::Error> {
assert_eq!(
to_value_from_str("0.4e5").expect("40000.0"),
Static(F64(40000.0))
);
assert_eq!(
to_value_from_str("-12345678901234.56789012").unwrap(),
to_value_from_str("-12345678901234.56789012")?,
Static(F64(-12_345_678_901_234.568))
);
assert_eq!(to_value_from_str("0.4e-001").unwrap(), Static(F64(0.04)));
assert_eq!(to_value_from_str("0.4e-001")?, Static(F64(0.04)));
assert_eq!(
to_value_from_str("0.123456789e-12").unwrap(),
to_value_from_str("0.123456789e-12")?,
Static(F64(1.234_567_89e-13))
);
assert_eq!(to_value_from_str("1.234567890E+34")?, 1.234_567_89e34);
assert_eq!(
to_value_from_str("1.234567890E+34").unwrap(),
1.234_567_89e34
);
assert_eq!(
to_value_from_str("23456789012E66").unwrap(),
to_value_from_str("23456789012E66")?,
Static(F64(2.345_678_901_2e76))
);
assert_eq!(
Expand All @@ -412,34 +410,37 @@ mod test {
Static(F64(1.23))
);
assert_eq!(to_value_from_str("0.6").expect("0.6"), Static(F64(0.6)));
Ok(())
}

#[allow(clippy::float_cmp)]
#[test]
fn float_precision() {
fn float_precision() -> Result<(), crate::Error> {
assert_eq!(
to_value_from_str("31.245270191439438").unwrap(),
to_value_from_str("31.245270191439438")?,
31.245_270_191_439_438
);
assert_eq!(
to_value_from_str("-31.245270191439438").unwrap(),
to_value_from_str("-31.245270191439438")?,
-31.245_270_191_439_438
);
assert_eq!(
to_value_from_str("121.48791951161945").unwrap(),
to_value_from_str("121.48791951161945")?,
121.487_919_511_619_45
);
assert_eq!(
to_value_from_str("-121.48791951161945").unwrap(),
to_value_from_str("-121.48791951161945")?,
-121.487_919_511_619_45
);
assert_eq!(
to_value_from_str("100.78399658203125").unwrap(),
to_value_from_str("100.78399658203125")?,
100.783_996_582_031_25
);
assert_eq!(
to_value_from_str("-100.78399658203125").unwrap(),
to_value_from_str("-100.78399658203125")?,
-100.783_996_582_031_25
);
Ok(())
}

#[test]
Expand Down Expand Up @@ -500,34 +501,39 @@ mod test {
}

#[test]
fn zero_int() {
assert_eq!(to_value_from_str("0").expect("0"), Static(I64(0)));
fn zero_int() -> Result<(), crate::Error> {
assert_eq!(to_value_from_str("0")?, Static(I64(0)));
Ok(())
}

#[test]
fn zero_float() {
assert_eq!(to_value_from_str("0e1").expect("0e1"), Static(F64(0.0)));
assert_eq!(to_value_from_str("0.00e-00").unwrap(), Static(F64(0.0)));
assert_eq!(to_value_from_str("0e-1").expect("0e-1"), Static(F64(-0.0)));
assert_eq!(to_value_from_str("-0.00e-00").unwrap(), Static(F64(-0.0)));
fn zero_float() -> Result<(), crate::Error> {
assert_eq!(to_value_from_str("0e1")?, Static(F64(0.0)));
assert_eq!(to_value_from_str("0.00e-00")?, Static(F64(0.0)));
assert_eq!(to_value_from_str("0e-1")?, Static(F64(-0.0)));
assert_eq!(to_value_from_str("-0.00e-00")?, Static(F64(-0.0)));
Ok(())
}

#[test]
fn int() {
assert_eq!(to_value_from_str("1").unwrap(), Static(I64(1)));
assert_eq!(to_value_from_str("257").unwrap(), Static(I64(257)));
fn int() -> Result<(), crate::Error> {
assert_eq!(to_value_from_str("1")?, Static(I64(1)));
assert_eq!(to_value_from_str("257")?, Static(I64(257)));
Ok(())
}

#[test]
fn minus_309() {
fn minus_309() -> Result<(), crate::Error> {
assert_eq!(
to_value_from_str("-5.96916642387374e-309").unwrap(),
to_value_from_str("-5.96916642387374e-309")?,
Static(F64(-5.969_166_423_873_74e-_309))
);
Ok(())
}
#[allow(clippy::unreadable_literal)]
#[test]
fn tiny_float() {
assert_eq!(to_value_from_str("-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000596916642387374").unwrap(), Static(F64(-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000596916642387374)));
fn tiny_float() -> Result<(), crate::Error> {
assert_eq!(to_value_from_str("-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000596916642387374")?, Static(F64(-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000596916642387374)));
Ok(())
}
}
4 changes: 2 additions & 2 deletions src/serde/value/borrowed/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ mod test {
#[test]
fn deserialize() {
use halfbrown::{hashmap, HashMap};
#[derive(serde::Deserialize, Debug, PartialEq)]
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Rotate {
Left,
Expand All @@ -999,7 +999,7 @@ mod test {
pub pos: Point,
pub age: u64,
}
#[derive(serde::Deserialize, Debug, PartialEq)]
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
pub struct TestStruct {
pub key: HashMap<String, String>,
pub vec: Vec<Vec<Option<u8>>>,
Expand Down
4 changes: 2 additions & 2 deletions src/serde/value/owned/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ mod test {
#[test]
fn deserialize() {
use halfbrown::{hashmap, HashMap};
#[derive(serde::Deserialize, Debug, PartialEq)]
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Rotate {
Left,
Expand All @@ -1074,7 +1074,7 @@ mod test {
pub pos: Point,
pub age: u64,
}
#[derive(serde::Deserialize, Debug, PartialEq)]
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
pub struct TestStruct {
pub key: HashMap<String, String>,
pub vec: Vec<Vec<Option<u8>>>,
Expand Down
4 changes: 2 additions & 2 deletions src/value/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,8 @@ mod test {
#[test]
fn prop_serialize_deserialize(borrowed in arb_value()) {
let mut string = borrowed.encode();
let mut bytes = unsafe{ string.as_bytes_mut()};
let decoded = to_value(&mut bytes).expect("Failed to decode");
let bytes = unsafe{ string.as_bytes_mut()};
let decoded = to_value(bytes).expect("Failed to decode");
prop_assert_eq!(borrowed, decoded);
}
#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/value/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,8 @@ mod test {
#[test]
fn prop_serialize_deserialize(owned in arb_value()) {
let mut string = owned.encode();
let mut bytes = unsafe{ string.as_bytes_mut()};
let decoded = to_value(&mut bytes).expect("Failed to decode");
let bytes = unsafe{ string.as_bytes_mut()};
let decoded = to_value(bytes).expect("Failed to decode");
prop_assert_eq!(owned, decoded);
}
#[test]
Expand Down
1 change: 1 addition & 0 deletions src/value/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use value_trait::StaticNode;
/// `Tape`
pub struct Tape<'input>(Vec<Node<'input>>);

#[allow(clippy::derive_partial_eq_without_eq)]
/// Tape `Node`
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Node<'input> {
Expand Down

0 comments on commit 8a9169b

Please sign in to comment.