Skip to content

Commit

Permalink
Follow linter suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingepumpe committed Aug 13, 2024
1 parent 9cbf740 commit 254c42b
Show file tree
Hide file tree
Showing 8 changed files with 3,608 additions and 4,540 deletions.
1 change: 0 additions & 1 deletion fitparser/examples/fit_to_json.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Read one or more FIT files and dump their contents as JSON
use fitparser;
use fitparser::de::{from_reader_with_options, DecodeOption};
use serde::Serialize;
use std::collections::{BTreeMap, HashSet};
Expand Down
40 changes: 16 additions & 24 deletions fitparser/src/de/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ mod tests {
let sl = &data[12..];
let (_, hdr) = message_header(sl).unwrap();

assert_eq!(hdr.contains_developer_data, false);
assert!(!hdr.contains_developer_data);
assert_eq!(hdr.local_message_number, 0);
assert_eq!(hdr.message_type, FitMessageType::Definition);
assert_eq!(hdr.time_offset, None);
Expand All @@ -685,30 +685,29 @@ mod tests {
let (rem, val) = data_field_value(&data, BaseType::UInt8, Endianness::Native, 1).unwrap();
match val {
Some(v) => assert_eq!(v, Value::UInt8(0x01)),
None => assert!(false, "No value returned."),
None => panic!("No value returned."),
}
assert_eq!(rem, &[0xFF]);

// parse off an invalid byte
let (rem, val) = data_field_value(rem, BaseType::UInt8, Endianness::Native, 1).unwrap();
match val {
Some(_) => assert!(false, "None should be returned for invalid bytes."),
None => {}
if val.is_some() {
panic!("None should be returned for invalid bytes.")
}
assert_eq!(rem, &[]);

// parse two byte values with defined endianess
let (rem, val) = data_field_value(&data, BaseType::UInt16, Endianness::Big, 2).unwrap();
match val {
Some(v) => assert_eq!(v, Value::UInt16(0x01FF)),
None => assert!(false, "No value returned."),
None => panic!("No value returned."),
}
assert_eq!(rem, &[]);

let (rem, val) = data_field_value(&data, BaseType::UInt16, Endianness::Little, 2).unwrap();
match val {
Some(v) => assert_eq!(v, Value::UInt16(0xFF01)),
None => assert!(false, "No value returned."),
None => panic!("No value returned."),
}
assert_eq!(rem, &[]);
}
Expand All @@ -729,24 +728,19 @@ mod tests {
Value::UInt8(0x03)
])
),
None => assert!(false, "No value returned."),
None => panic!("No value returned."),
}
assert_eq!(rem, &[0xFF]);

// parse off an invalid byte
let (rem, val) = data_field_value(&data, BaseType::UInt8, Endianness::Native, 5).unwrap();
match val {
Some(_) => assert!(false, "None should be returned for invalid bytes."),
None => {}
if val.is_some() {
panic!("None should be returned for invalid bytes.")
}
assert_eq!(rem, &[]);

match val {
Some(_) => assert!(
false,
"None should be returned for array with an invalid size."
),
None => {}
if val.is_some() {
panic!("None should be returned for array with an invalid size.")
}
assert_eq!(rem, &[]);
}
Expand All @@ -759,16 +753,15 @@ mod tests {
let (rem, val) = data_field_value(&data, BaseType::String, Endianness::Native, 8).unwrap();
match val {
Some(v) => assert_eq!(v, Value::String(String::from("GARMIN"))),
None => assert!(false, "No value returned."),
None => panic!("No value returned."),
}
assert_eq!(rem, &[0xFF]);

// parse invalid UTF8 string
let data = [71, 195, 40, 77, 73, 78, 0, 63, 255];
let (rem, val) = data_field_value(&data, BaseType::String, Endianness::Native, 8).unwrap();
match val {
Some(_) => assert!(false, "None should be returned for invalid string."),
None => {}
if val.is_some() {
panic!("None should be returned for invalid string.")
}
assert_eq!(rem, &[0xFF]);

Expand All @@ -777,7 +770,7 @@ mod tests {
let (rem, val) = data_field_value(&data, BaseType::String, Endianness::Native, 8).unwrap();
match val {
Some(v) => assert_eq!(v, Value::String(String::from("GARM"))),
None => assert!(false, "No value returned."),
None => panic!("No value returned."),
}
assert_eq!(rem, &[0xFF]);
}
Expand All @@ -788,8 +781,7 @@ mod tests {
// try and parse an array with a size that isn't a multiple of the base type
let data: Vec<u8> = (0..=255).collect();
match data_field_value(&data, BaseType::UInt16, Endianness::Native, 255) {
Ok(..) => {}
Err(..) => {}
Ok(..) | Err(..) => {}
};
}
}
19 changes: 6 additions & 13 deletions fitparser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,12 @@ mod tests {
data[12] = 0x00;
data[13] = 0x00;
match de::from_bytes(&data) {
Ok(_) => assert!(
false,
Ok(_) => panic!(
"This test should fail without the data CRC value being recomputed to include the header."
),
Err(e) => match *e {
ErrorKind::InvalidCrc(..) => {}
_ => assert!(false, "Incorrect error returned {:?}", e),
_ => panic!("Incorrect error returned {:?}", e),
},
}

Expand All @@ -480,13 +479,10 @@ mod tests {
data[13] = 0xFF;
let mut options = HashSet::new();
match de::from_bytes_with_options(&data, &options) {
Ok(_) => assert!(
false,
"This test should fail without the SkipHeaderCrcValidation option."
),
Ok(_) => panic!("This test should fail without the SkipHeaderCrcValidation option."),
Err(e) => match *e {
ErrorKind::InvalidCrc(..) => {}
_ => assert!(false, "Incorrect error returned {:?}", e),
_ => panic!("Incorrect error returned {:?}", e),
},
}

Expand All @@ -505,13 +501,10 @@ mod tests {
data[leng - 1] = 0xFF;
let mut options = HashSet::new();
match de::from_bytes_with_options(&data, &options) {
Ok(_) => assert!(
false,
"This test should fail without the SkipDataCrcValidation option."
),
Ok(_) => panic!("This test should fail without the SkipDataCrcValidation option."),
Err(e) => match *e {
ErrorKind::InvalidCrc(..) => {}
_ => assert!(false, "Incorrect error returned {:?}", e),
_ => panic!("Incorrect error returned {:?}", e),
},
}

Expand Down
Loading

0 comments on commit 254c42b

Please sign in to comment.