From f51a0316c2f7026252064f963745b370e7162ad2 Mon Sep 17 00:00:00 2001 From: Momo Langenstein Date: Thu, 24 Feb 2022 12:38:44 +0000 Subject: [PATCH 1/2] Increased coverage for unit tests --- src/de/value.rs | 2 +- src/lib.rs | 2 +- tests/129_indexmap.rs | 8 ++++---- tests/359_deserialize_seed.rs | 10 ++++++++++ tests/preserve_sequence.rs | 8 +------- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/de/value.rs b/src/de/value.rs index 041c16f9..544ee05e 100644 --- a/src/de/value.rs +++ b/src/de/value.rs @@ -9,7 +9,7 @@ use crate::error::SpannedResult; use crate::value::{Map, Number, Value}; impl std::str::FromStr for Value { - type Err = crate::SpannedError; + type Err = crate::error::SpannedError; /// Creates a value from a string reference. fn from_str(s: &str) -> SpannedResult { diff --git a/src/lib.rs b/src/lib.rs index 0be42340..1e768a1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,7 @@ pub mod extensions; pub mod options; pub use de::{from_str, Deserializer}; -pub use error::{Result, SpannedError}; +pub use error::{Error, Result}; pub use options::Options; pub use ser::{to_string, Serializer}; pub use value::{Map, Number, Value}; diff --git a/tests/129_indexmap.rs b/tests/129_indexmap.rs index ccaaaef9..7fae9935 100644 --- a/tests/129_indexmap.rs +++ b/tests/129_indexmap.rs @@ -34,9 +34,9 @@ tasks: { Value::String("shell command".to_string()) ); } - _ => panic!(), + _ => panic!(), // GRCOV_EXCL_LINE }, - _ => panic!(), + _ => panic!(), // GRCOV_EXCL_LINE } let file = r#"( @@ -69,8 +69,8 @@ tasks: { Value::String("debug message".to_string()) ); } - _ => panic!(), + _ => panic!(), // GRCOV_EXCL_LINE }, - _ => panic!(), + _ => panic!(), // GRCOV_EXCL_LINE } } diff --git a/tests/359_deserialize_seed.rs b/tests/359_deserialize_seed.rs index c193a7c1..74afd05a 100644 --- a/tests/359_deserialize_seed.rs +++ b/tests/359_deserialize_seed.rs @@ -43,4 +43,14 @@ fn test_deserialize_seed() { assert_eq!(expected, deserialized); } + + assert_eq!( + ron::Options::default().from_str_seed("'a'", Seed(42)), + Err(ron::error::SpannedError { + code: ron::Error::Message(String::from( + "invalid type: string \"a\", expected an integer" + )), + position: ron::error::Position { line: 1, col: 4 }, + }) + ); } diff --git a/tests/preserve_sequence.rs b/tests/preserve_sequence.rs index 9bb1d489..8ffb20d8 100644 --- a/tests/preserve_sequence.rs +++ b/tests/preserve_sequence.rs @@ -25,13 +25,7 @@ fn read_original(source: &str) -> String { } fn make_roundtrip(source: &str) -> String { - let config: Config = match from_str(source) { - Ok(x) => x, - Err(e) => { - println!("Failed to load config: {}", e); - std::process::exit(1); - } - }; + let config: Config = from_str(source).unwrap(); let pretty = PrettyConfig::new() .depth_limit(3) .separate_tuple_members(true) From eb682fb7b954fa1f48e1af52e85bc6d8f5e9d7df Mon Sep 17 00:00:00 2001 From: Momo Langenstein Date: Thu, 24 Feb 2022 12:47:58 +0000 Subject: [PATCH 2/2] Removed unused enum from empty set test --- tests/147_empty_sets_serialisation.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/147_empty_sets_serialisation.rs b/tests/147_empty_sets_serialisation.rs index a3fab462..81cabf64 100644 --- a/tests/147_empty_sets_serialisation.rs +++ b/tests/147_empty_sets_serialisation.rs @@ -13,20 +13,13 @@ struct TupleStruct(UnitStruct, i8); #[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] struct Key(u32); -#[derive(Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] -enum Enum { - Unit, - Bool(bool), - Chars(char, String), -} - #[derive(Debug, PartialEq, Deserialize, Serialize)] struct Struct { tuple: ((), NewType, TupleStruct), vec: Vec>, - map: HashMap, + map: HashMap, deep_vec: HashMap>, - deep_map: HashMap>, + deep_map: HashMap>, } #[test]